ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Scram/ScramFunctions.pm
Revision: 1.8
Committed: Thu Sep 21 13:44:26 2000 UTC (24 years, 7 months ago) by williamc
Content type: text/plain
Branch: MAIN
Changes since 1.7: +52 -1 lines
Log Message:
Merge in versions from V0_15_0

File Contents

# User Rev Content
1 williamc 1.2 #
2     # ScramFunctions.pm
3     #
4     # Written by Christopher Williams
5     #
6     # Description
7     #
8     # Interface
9     # ---------
10     # new() : A new ScramCommands object
11     # project(urlstring,dir[,areaname]): Create a project from the given url file
12     # return the area
13     # satellite(name,version,installdirectory[,areaname]): create a satellite
14     # project from the specified name version
15     # addareatoDB(ConfigArea[,name[,version]]) : add area to the db
16     # globalcache([cachedirectory])) : return the global cache object/set at dir.
17     # scramprojectdb() : return the scram project DB object
18     # areatoolbox(ConfigArea) : return the toolbox of the specified area
19     # setuptoolsinarea($area[,$toolname[,$toolversion[,toolfile]) : setup
20     # arch() : get/set the architecture string
21 williamc 1.6 # scramobjectinterface(Class) : print out the interface of a scram class
22 williamc 1.7 # webget(area,url) : get the url into the cache of the specified area
23 williamc 1.8 # getversion() : return the current scram version
24     # spawnversion(version,@args) : spawn the scram version with the given args
25 williamc 1.2
26     package Scram::ScramFunctions;
27     use URL::URLcache;
28     use Utilities::Verbose;
29     require 5.004;
30    
31     @ISA=qw(Utilities::Verbose);
32    
33     sub new {
34     my $class=shift;
35     $self={};
36     bless $self, $class;
37     # -- default settings
38 williamc 1.5 $self->{cachedir}=$ENV{HOME}."/.scramrc/globalcache";
39 williamc 1.2 $self->{scramprojectsdbdir}=$ENV{SCRAM_LOOKUPDB};
40 williamc 1.8 ($self->{scram_top})=( $ENV{SCRAM_HOME}=~/(.*)\//) ;
41    
42 williamc 1.2 return $self;
43     }
44    
45     sub project {
46     my $self=shift;
47     my $url=shift;
48     my $installarea=shift;
49    
50     my $areaname="";
51     if ( @_ ) {
52     $areaname=shift;
53     }
54     require Configuration::BootStrapProject;
55     my $bs=Configuration::BootStrapProject->
56     new($self->globalcache(),$installarea);
57     $self->verbose("BootStrapping $url");
58     my $area=$bs->boot($url,$areaname);
59     if ( ! defined $area ) {
60     $self->error("Unable to create project area");
61     }
62     $area->archname($self->arch());
63    
64     # -- download all tool description files
65     my $req=$self->arearequirements($area);
66     if ( defined $req ) {
67     $req->download($self->areatoolbox($area));
68     }
69    
70     return $area;
71     }
72    
73     sub setuptoolsinarea {
74     my $self=shift;
75     my $area=shift;
76    
77     # -- initialise
78     $self->_allprojectinitsearcher();
79    
80     # -- create a new toolbox object
81     my $toolbox=$self->areatoolbox($area);
82     $toolbox->searcher($self->_projsearcher());
83    
84     if ( @_ ) {
85     # -- specific tool specified
86     if ( my $rv=$toolbox->toolsetup(@_) ) {
87     if ( $rv eq 1 ) {
88     print "Unknown tool $toolname @ARGV\n";
89     exit 1;
90     }
91     }
92     }
93     else {
94     # -- setup all tools specified in the requirements doc
95     my $reqs=$self->arearequirements($area);
96     $self->verbose("Setup ToolBox from Requirements doc ($reqs)");
97     $reqs->setup($toolbox);
98     }
99     }
100    
101     sub satellite {
102     my $self=shift;
103     my $name=shift;
104     my $version=shift;
105     my $installarea=shift;
106    
107 williamc 1.4 my $areaname=undef;
108 williamc 1.2 if ( @_ ) {
109     $areaname=shift;
110     }
111    
112     # -- look up scram database for location
113     my $relarea=$self->_lookupareaindb($name,$version);
114     if ( ! defined $relarea ) {
115     $self->error("Unable to Find Project $name $version");
116 williamc 1.4 }
117    
118     # -- fix for old broken areas
119     if ( (! defined $relarea->version()) || ($relarea->version() eq "") ) {
120     $relarea->version($version);
121 williamc 1.2 }
122    
123     # -- create satellite
124     my $area=$relarea->satellite($installarea,$areaname);
125     $area->archname($self->arch());
126    
127     # -- copy setup info - deprecated by toolbox copy method
128     #$relarea->copysetup($area->location());
129    
130     # -- copy toolbox
131     my $rtb=$self->areatoolbox($relarea);
132     my $tb=$self->areatoolbox($area);
133     $rtb->copytools($tb);
134    
135     # -- copy configuration directory
136     if ( ! -d $area->location()."/".$area->configurationdir() ) {
137     use Utilities::AddDir;
138     AddDir::copydir($relarea->location()."/".$relarea->configurationdir(),
139     $area->location()."/".$area->configurationdir() );
140     }
141    
142     # -- copy RequirementsDoc
143     if ( ! -f $area->requirementsdoc() ) {
144 williamc 1.3 use File::Copy;
145 williamc 1.2 copy( $relarea->requirementsdoc() , $area->requirementsdoc());
146     }
147    
148     return $area;
149 williamc 1.7 }
150    
151     sub webget {
152     my $self=shift;
153     my $area=shift;
154     my $url=shift;
155    
156     my $handler=URL::URLhandler->new($area->cache());
157     return ($handler->get($url));
158 williamc 1.2 }
159    
160     sub addareatoDB {
161     my $self=shift;
162     my $area=shift;
163     my $tagname=shift;
164     my $version=shift;
165    
166     # -- create defaults if necessary
167     if ( (! defined $version) || ( $version eq "") ) {
168     $version=$area->version();
169     }
170     if ( (! defined $tagname) || ( $tagname eq "") ) {
171     $tagname=$area->name();
172     }
173    
174     # -- Add to the DB
175     $self->scramprojectdb()->addarea($tagname,$version,$area);
176     }
177    
178 williamc 1.8 sub spawnversion {
179     my $self=shift;
180     my $version=shift;
181    
182     my $rv=0;
183     my $thisversion=$self->getversion();
184     if ( defined $version ) {
185     if ( $version ne $thisversion ) {
186     # first try to use the correct version
187     if ( -d $self->{scram_top}."/".$version ) {
188     $ENV{SCRAM_HOME}=$self->{scram_top}."/".$version;
189     $ENV{TOOL_HOME}="$ENV{SCRAM_HOME}/src";
190     $self->verbose("Spawning SCRAM version $version");
191     my $rv=system("scram", @_)/256;
192     exit $rv;
193     }
194     else { # if not then simply warn
195     print "******* Warning : scram version inconsistent ********\n";
196     print "This version: $thisversion; Required version: $version\n";
197     print "*****************************************************\n";
198     print "\n";
199     }
200     }
201     }
202     else {
203     $self->error("Undefined value for version requested");
204     $rv=1;
205     }
206     return $rv;
207     }
208    
209 williamc 1.2 sub globalcache {
210     my $self=shift;
211     if ( @_ ) {
212     $self->{cachedir}=shift;
213     }
214     if ( ! defined $self->{globalcache} ) {
215     $self->{globalcache}=URL::URLcache->new($self->{cachedir});
216     }
217     return $self->{globalcache};
218     }
219    
220    
221     sub scramprojectdb {
222     my $self=shift;
223     if ( @_ ) {
224     $self->{scramprojectsdbdir}=shift;
225     }
226     if ( ! defined $self->{scramprojectsdb} ) {
227     require Scram::ScramProjectDB;
228     $self->{scramprojectsdb}=Scram::ScramProjectDB->new(
229     $self->{scramprojectsdbdir} );
230     $self->{scramprojectsdb}->verbosity($self->verbosity());
231     }
232     return $self->{scramprojectsdb};
233     }
234 williamc 1.8
235     sub getversion {
236     my $self=shift;
237    
238     my $thisversion;
239     ($thisversion=$ENV{SCRAM_HOME})=~s/(.*)\///;
240     my $scram_top=$1;
241     my $scram_version=$thisversion;
242     # deal with links
243     my $version=readlink $ENV{SCRAM_HOME};
244     if ( defined $version) {
245     $scram_version=$version;
246     }
247     return $scram_version;
248     }
249 williamc 1.2
250     sub areatoolbox {
251     my $self=shift;
252     my $area=shift;
253    
254     my $name=$area->location();
255     if ( ! defined $self->{toolboxes}{$name} ) {
256     # -- create a new toolbox object
257     require BuildSystem::ToolBox;
258 williamc 1.8 $self->{toolboxes}{$name}=BuildSystem::ToolBox->new($area,
259     $self->arch());
260 williamc 1.2 $self->{toolboxes}{$name}->verbosity($self->verbosity());
261     }
262     return $self->{toolboxes}{$name};
263     }
264    
265     sub arearequirements {
266     my $self=shift;
267     my $area=shift;
268    
269     my $name=$area->location();
270     if ( ! defined $self->{requirements}{$name} ) {
271     # -- create a new toolbox object
272     require BuildSystem::Requirements;
273     my $doc=$area->requirementsdoc();
274     my $cache=$area->cache();
275     my $db=$area->objectstore();
276     require ActiveDoc::ActiveStore;
277     my $astore=ActiveDoc::ActiveStore->new($db,$cache);
278     $self->{requirements}{$name}=
279     BuildSystem::Requirements->new($astore,"file:".$doc,
280     $ENV{SCRAM_ARCH});
281     $self->{requirements}{$name}->verbosity($self->verbosity());
282     $self->verbose("Requirements Doc (".$self->{requirements}{$name}.
283     ") for area :\n $name\n initiated from $doc");
284     }
285     else {
286     $self->verbose("Requirements Doc (".$self->{requirements}{$name}.")");
287     }
288     return $self->{requirements}{$name};
289     }
290    
291     sub arch {
292     my $self=shift;
293    
294     @_?$self->{arch}=shift
295     :$self->{arch};
296 williamc 1.6 }
297    
298     sub scramobjectinterface {
299     my $self=shift;
300     my $class=shift;
301    
302     my $file;
303     ($file=$class."\.pm")=~s/::/\//g;
304     $file=$ENV{TOOL_HOME}."/".$file;
305    
306     if ( ! -f $file ) {
307     $self->error("Unable to find $class in ".$ENV{TOOL_HOME});
308     }
309     print "--------------------- $class ------------------\n";
310     my $fh=FileHandle->new();
311     $fh->open("<$file");
312     while ( <$fh> ) {
313     if ( $_=~/#\s*Interface/g ) {
314     $intregion=1;
315     next;
316     }
317     if ( $intregion ) { # if we are in the interface documentation
318     if ( ( $_!~/^#/ ) || ( $_=~/^#\s?-{40}/ ) ) { #moving out of Int doc
319     $intregion=0;
320     next;
321     }
322     print $_;
323     if ( $_=~/^#\s*(.*)\((.*)\)?:(.*)/ ) {
324     $interface=$1;
325     $args=$2;
326     $rest=$3;
327     next if ($interface eq "");
328     push @interfaces,$interface;
329     $interfaceargs{$interface}=$args;
330     }
331     }
332     }
333     print "\n";
334     undef $fh;
335 williamc 1.2 }
336    
337     # -------------- Support Routines ------------------------------
338    
339    
340     sub _allprojectinitsearcher {
341     if ( ! defined $self->{projsearcher} ) {
342     my $search=_projsearcher();
343     foreach $proj ( $self->scramprojectdb()->list() ) {
344     $search->addproject($$proj[0],$$proj[1]);
345     }
346     }
347     }
348    
349     sub _projsearcher {
350     if ( ! defined $self->{projsearcher} ) {
351     require Scram::ProjectSearcher;
352     $self->{projsearcher}=Scram::ProjectSearcher->new(
353     $self->scramprojectdb());
354     }
355     return $self->{projsearcher};
356     }
357    
358    
359     sub _lookupareaindb {
360     my $self=shift;
361    
362     my $area=undef;
363     # -- Look up the area in the databse
364     my @areas=$self->scramprojectdb()->getarea(@_);
365     if ( $#areas > 0 ) { #ambigous
366     # could ask user - for now just error
367     $self->error("Ambigous request - please be more specific");
368     }
369     elsif ( $#areas != 0 ) { #not found
370     $self->error("The project requested has not been found");
371     }
372     else {
373     $area=$areas[0];
374     }
375     return $area;
376     }