ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Scram/ScramFunctions.pm
Revision: 1.12
Committed: Tue Jun 12 16:02:56 2001 UTC (23 years, 11 months ago) by sashby
Content type: text/plain
Branch: MAIN
Changes since 1.11: +36 -29 lines
Log Message:
Fixed problem with prerequisite checking during build

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