ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Scram/ScramFunctions.pm
Revision: 1.17
Committed: Fri Nov 9 16:49:45 2001 UTC (23 years, 6 months ago) by sashby
Content type: text/plain
Branch: MAIN
Changes since 1.16: +1 -2 lines
Log Message:
Some changes to basics.mk

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 sashby 1.14 # -- initialise
90     print "Initialising setup procedure......","\n";
91 williamc 1.2 $self->_allprojectinitsearcher();
92    
93     # -- create a new toolbox object
94     my $toolbox=$self->areatoolbox($area);
95 williamc 1.10 $toolbox->searcher($self->_allprojectinitsearcher());
96 williamc 1.2
97     if ( @_ ) {
98     # -- specific tool specified
99     if ( my $rv=$toolbox->toolsetup(@_) ) {
100     if ( $rv eq 1 ) {
101     print "Unknown tool $toolname @ARGV\n";
102     exit 1;
103     }
104     }
105     }
106     else {
107     # -- setup all tools specified in the requirements doc
108     my $reqs=$self->arearequirements($area);
109     $self->verbose("Setup ToolBox from Requirements doc ($reqs)");
110     $reqs->setup($toolbox);
111     }
112     }
113    
114     sub satellite {
115     my $self=shift;
116     my $name=shift;
117     my $version=shift;
118     my $installarea=shift;
119    
120 williamc 1.4 my $areaname=undef;
121 williamc 1.2 if ( @_ ) {
122     $areaname=shift;
123     }
124    
125     # -- look up scram database for location
126     my $relarea=$self->_lookupareaindb($name,$version);
127     if ( ! defined $relarea ) {
128     $self->error("Unable to Find Project $name $version");
129 williamc 1.4 }
130    
131     # -- fix for old broken areas
132     if ( (! defined $relarea->version()) || ($relarea->version() eq "") ) {
133     $relarea->version($version);
134 williamc 1.2 }
135    
136     # -- create satellite
137     my $area=$relarea->satellite($installarea,$areaname);
138     $area->archname($self->arch());
139    
140     # -- copy toolbox
141     my $rtb=$self->areatoolbox($relarea);
142     my $tb=$self->areatoolbox($area);
143     $rtb->copytools($tb);
144    
145     # -- copy configuration directory
146     if ( ! -d $area->location()."/".$area->configurationdir() ) {
147     use Utilities::AddDir;
148     AddDir::copydir($relarea->location()."/".$relarea->configurationdir(),
149     $area->location()."/".$area->configurationdir() );
150     }
151    
152     # -- copy RequirementsDoc
153     if ( ! -f $area->requirementsdoc() ) {
154 williamc 1.3 use File::Copy;
155 williamc 1.2 copy( $relarea->requirementsdoc() , $area->requirementsdoc());
156     }
157    
158     return $area;
159 williamc 1.7 }
160    
161 williamc 1.10 sub toolruntime {
162 williamc 1.7 my $self=shift;
163     my $area=shift;
164    
165 williamc 1.10 my $name=$area->location();
166     if ( ! defined $self->{toolruntime}{$name} ) {
167     require Runtime;
168     my $toolbox=$self->areatoolbox($area);
169     $self->{toolruntime}{$name}=Runtime->new();
170    
171     # -- add scram area specific runtimes
172     $self->{toolruntime}{$name}->addvar("LD_LIBRARY_PATH",
173     $area->location()."/lib/".$self->arch(),"path");
174     $self->{toolruntime}{$name}->addvar("PATH",
175     $area->location()."/bin/".$self->arch(),"path");
176     if ( defined $area->linkarea() ) {
177     my $reltop=$area->linkarea()->location();
178     $self->{toolruntime}{$name}->addvar("LD_LIBRARY_PATH",
179     $reltop."/lib/".$self->arch(),"path");
180     $self->{toolruntime}{$name}->addvar("PATH",
181     $reltop."/bin/".$self->arch(),"path");
182     }
183    
184     # -- get the runtime environment from all the tools
185     my $tool;
186     foreach $toolname ( $toolbox->tools() ) {
187     $tool=$toolbox->gettool($toolname);
188     if ( defined $tool ) {
189     # -- get runtime paths
190     foreach $f ( $tool->listtype("runtime_path")) {
191     foreach $val ( $tool->getfeature($f) ) {
192     $self->{toolruntime}{$name}->addvar($f,$val,"path");
193     }
194     }
195     # -- get runtime vars
196     foreach $f ( $tool->listtype("runtime")) {
197     foreach $val ( $tool->getfeature($f) ) {
198     $self->{toolruntime}{$name}->addvar($f,$val);
199     }
200     }
201     }
202     }
203    
204     # -- Get the project level environment
205     my $runtimefile=$area->location()."/".$area->configurationdir()
206     ."/Runtime";
207     if ( -f $runtimefile ) {
208     $self->{toolruntime}{$name}->file($runtimefile);
209     }
210     }
211     return $self->{toolruntime}{$name};
212     }
213    
214     sub webget {
215     my $self=shift;
216     my $area=shift;
217     my $url=shift;
218    
219     require URL::URLhandler;
220     my $handler=URL::URLhandler->new($area->cache());
221     return ($handler->download($url));
222 williamc 1.2 }
223    
224     sub addareatoDB {
225     my $self=shift;
226     my $area=shift;
227     my $tagname=shift;
228     my $version=shift;
229    
230     # -- create defaults if necessary
231     if ( (! defined $version) || ( $version eq "") ) {
232     $version=$area->version();
233     }
234     if ( (! defined $tagname) || ( $tagname eq "") ) {
235     $tagname=$area->name();
236     }
237    
238     # -- Add to the DB
239     $self->scramprojectdb()->addarea($tagname,$version,$area);
240     }
241    
242 sashby 1.13
243     sub removeareafromDB
244     {
245     ###############################################################
246     # removearefromDB() #
247     ###############################################################
248     # modified : Thu Jun 14 10:46:22 2001 / SFA #
249     # params : projectname, projectversion #
250     # : #
251     # : #
252     # : #
253     # function : Remove project <projectname> from DB file. #
254     # : #
255     # : #
256     ###############################################################
257     my $self=shift;
258     my $projname=shift;
259     my $version=shift;
260    
261     # -- Remove from the DB:
262     $self->scramprojectdb()->removearea($projname,$version);
263     }
264    
265    
266 sashby 1.12 sub spawnversion
267     {
268 sashby 1.15 ###############################################################
269     # spawnversion #
270     ###############################################################
271     # modified : Fri Aug 10 15:42:08 2001 / SFA #
272     # params : #
273     # : #
274     # : #
275     # : #
276     # function : Check for version of scram to run, and run it. #
277     # : #
278     # : #
279     ###############################################################
280    
281 sashby 1.12 my $self=shift;
282     my $version=shift;
283     my $rv=0;
284    
285     my $thisversion=$self->getversion();
286 williamc 1.8
287 sashby 1.12 if ( defined $version )
288     {
289     if ( $version ne $thisversion )
290     {
291     # first try to use the correct version
292     if ( -d $self->{scram_top}."/".$version )
293     {
294     $ENV{SCRAM_HOME}=$self->{scram_top}."/".$version;
295     $ENV{TOOL_HOME}="$ENV{SCRAM_HOME}/src";
296     $self->verbose("Spawning SCRAM version $version");
297 sashby 1.17
298 sashby 1.12 my $rv=system("scram", @_)/256;
299     exit $rv;
300     }
301     else
302     { # if not then simply warn
303     print "******* Warning : scram version inconsistent ********\n";
304     print "This version: $thisversion; Required version: $version\n";
305     print "*****************************************************\n";
306     print "\n";
307     }
308     }
309     }
310     else
311     {
312     $self->error("Undefined value for version requested");
313     $rv=1;
314     }
315     return $rv;
316     }
317 williamc 1.8
318 williamc 1.2 sub globalcache {
319     my $self=shift;
320     if ( @_ ) {
321     $self->{cachedir}=shift;
322     }
323     if ( ! defined $self->{globalcache} ) {
324     $self->{globalcache}=URL::URLcache->new($self->{cachedir});
325     }
326     return $self->{globalcache};
327     }
328    
329    
330     sub scramprojectdb {
331     my $self=shift;
332     if ( @_ ) {
333     $self->{scramprojectsdbdir}=shift;
334     }
335     if ( ! defined $self->{scramprojectsdb} ) {
336     require Scram::ScramProjectDB;
337     $self->{scramprojectsdb}=Scram::ScramProjectDB->new(
338     $self->{scramprojectsdbdir} );
339     $self->{scramprojectsdb}->verbosity($self->verbosity());
340     }
341     return $self->{scramprojectsdb};
342     }
343 williamc 1.8
344     sub getversion {
345     my $self=shift;
346    
347     my $thisversion;
348     ($thisversion=$ENV{SCRAM_HOME})=~s/(.*)\///;
349     my $scram_top=$1;
350     my $scram_version=$thisversion;
351     # deal with links
352     my $version=readlink $ENV{SCRAM_HOME};
353     if ( defined $version) {
354     $scram_version=$version;
355     }
356     return $scram_version;
357     }
358 williamc 1.2
359     sub areatoolbox {
360     my $self=shift;
361     my $area=shift;
362    
363     my $name=$area->location();
364     if ( ! defined $self->{toolboxes}{$name} ) {
365     # -- create a new toolbox object
366     require BuildSystem::ToolBox;
367 williamc 1.8 $self->{toolboxes}{$name}=BuildSystem::ToolBox->new($area,
368     $self->arch());
369 williamc 1.2 $self->{toolboxes}{$name}->verbosity($self->verbosity());
370     }
371     return $self->{toolboxes}{$name};
372     }
373    
374     sub arearequirements {
375     my $self=shift;
376     my $area=shift;
377    
378     my $name=$area->location();
379     if ( ! defined $self->{requirements}{$name} ) {
380     # -- create a new toolbox object
381     require BuildSystem::Requirements;
382     my $doc=$area->requirementsdoc();
383     my $cache=$area->cache();
384     my $db=$area->objectstore();
385     require ActiveDoc::ActiveStore;
386     my $astore=ActiveDoc::ActiveStore->new($db,$cache);
387     $self->{requirements}{$name}=
388     BuildSystem::Requirements->new($astore,"file:".$doc,
389     $ENV{SCRAM_ARCH});
390     $self->{requirements}{$name}->verbosity($self->verbosity());
391     $self->verbose("Requirements Doc (".$self->{requirements}{$name}.
392     ") for area :\n $name\n initiated from $doc");
393     }
394     else {
395     $self->verbose("Requirements Doc (".$self->{requirements}{$name}.")");
396     }
397     return $self->{requirements}{$name};
398     }
399    
400     sub arch {
401     my $self=shift;
402    
403     @_?$self->{arch}=shift
404     :$self->{arch};
405 williamc 1.6 }
406    
407     sub scramobjectinterface {
408 williamc 1.10 my $self=shift;
409     my $class=shift;
410 williamc 1.6
411 williamc 1.10 my $file;
412     ($file=$class."\.pm")=~s/::/\//g;
413     $file=$ENV{TOOL_HOME}."/".$file;
414 williamc 1.6
415 williamc 1.10 if ( ! -f $file ) {
416     $self->error("Unable to find $class in ".$ENV{TOOL_HOME});
417     }
418     print "--------------------- $class ------------------\n";
419     my $fh=FileHandle->new();
420 williamc 1.6 $fh->open("<$file");
421     while ( <$fh> ) {
422     if ( $_=~/#\s*Interface/g ) {
423     $intregion=1;
424     next;
425     }
426     if ( $intregion ) { # if we are in the interface documentation
427     if ( ( $_!~/^#/ ) || ( $_=~/^#\s?-{40}/ ) ) { #moving out of Int doc
428     $intregion=0;
429     next;
430     }
431     print $_;
432     if ( $_=~/^#\s*(.*)\((.*)\)?:(.*)/ ) {
433     $interface=$1;
434     $args=$2;
435     $rest=$3;
436     next if ($interface eq "");
437     push @interfaces,$interface;
438     $interfaceargs{$interface}=$args;
439     }
440     }
441     }
442     print "\n";
443 williamc 1.10 undef $fh;
444 williamc 1.2 }
445    
446     # -------------- Support Routines ------------------------------
447    
448    
449     sub _allprojectinitsearcher {
450     if ( ! defined $self->{projsearcher} ) {
451     my $search=_projsearcher();
452     foreach $proj ( $self->scramprojectdb()->list() ) {
453     $search->addproject($$proj[0],$$proj[1]);
454     }
455     }
456 williamc 1.10 return $self->{projsearcher};
457 williamc 1.2 }
458    
459     sub _projsearcher {
460     if ( ! defined $self->{projsearcher} ) {
461     require Scram::ProjectSearcher;
462     $self->{projsearcher}=Scram::ProjectSearcher->new(
463     $self->scramprojectdb());
464     }
465     return $self->{projsearcher};
466     }
467    
468    
469     sub _lookupareaindb {
470     my $self=shift;
471    
472     my $area=undef;
473     # -- Look up the area in the databse
474     my @areas=$self->scramprojectdb()->getarea(@_);
475     if ( $#areas > 0 ) { #ambigous
476     # could ask user - for now just error
477     $self->error("Ambigous request - please be more specific");
478     }
479     elsif ( $#areas != 0 ) { #not found
480     $self->error("The project requested has not been found");
481     }
482     else {
483     $area=$areas[0];
484     }
485     return $area;
486     }