ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Scram/ScramFunctions.pm
Revision: 1.15
Committed: Wed Aug 22 12:40:13 2001 UTC (23 years, 8 months ago) by sashby
Content type: text/plain
Branch: MAIN
Changes since 1.14: +13 -0 lines
Log Message:
Committing some minor changes. Disable bold feature for piping.

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