ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Scram/ScramFunctions.pm
Revision: 1.13
Committed: Mon Jun 18 15:19:51 2001 UTC (23 years, 10 months ago) by sashby
Content type: text/plain
Branch: MAIN
Changes since 1.12: +24 -0 lines
Log Message:
Added remove function so installed projects can be removed from DB

File Contents

# Content
1 #
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 # scramobjectinterface(Class) : print out the interface of a scram class
22 # webget(area,url) : get the url into the cache of the specified area
23 # getversion() : return the current scram version
24 # spawnversion(version,@args) : spawn the scram version with the given args
25 # classverbose(classstring,setting) : Set the class verbosity level
26 # toolruntime(ConfigArea): Get a runtime object withthe settings from
27 # the specified toolbox
28
29 package Scram::ScramFunctions;
30 use URL::URLcache;
31 use Utilities::Verbose;
32 require 5.004;
33
34 @ISA=qw(Utilities::Verbose);
35
36 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
49 sub classverbose {
50 my $self=shift;
51 my $class=shift;
52 my $val=shift;
53
54 $ENV{"VERBOSE_".$class}=$val;
55 }
56
57 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 $toolbox->searcher($self->_allprojectinitsearcher());
95
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 my $areaname=undef;
120 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 }
129
130 # -- fix for old broken areas
131 if ( (! defined $relarea->version()) || ($relarea->version() eq "") ) {
132 $relarea->version($version);
133 }
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 use File::Copy;
157 copy( $relarea->requirementsdoc() , $area->requirementsdoc());
158 }
159
160 return $area;
161 }
162
163 sub toolruntime {
164 my $self=shift;
165 my $area=shift;
166
167 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 }
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
245 sub removeareafromDB
246 {
247 ###############################################################
248 # removearefromDB() #
249 ###############################################################
250 # modified : Thu Jun 14 10:46:22 2001 / SFA #
251 # params : projectname, projectversion #
252 # : #
253 # : #
254 # : #
255 # function : Remove project <projectname> from DB file. #
256 # : #
257 # : #
258 ###############################################################
259 my $self=shift;
260 my $projname=shift;
261 my $version=shift;
262
263 # -- Remove from the DB:
264 $self->scramprojectdb()->removearea($projname,$version);
265 }
266
267
268 sub spawnversion
269 {
270 my $self=shift;
271 my $version=shift;
272 my $rv=0;
273
274 my $thisversion=$self->getversion();
275
276 if ( defined $version )
277 {
278 if ( $version ne $thisversion )
279 {
280 # first try to use the correct version
281 if ( -d $self->{scram_top}."/".$version )
282 {
283 $ENV{SCRAM_HOME}=$self->{scram_top}."/".$version;
284 $ENV{TOOL_HOME}="$ENV{SCRAM_HOME}/src";
285 $self->verbose("Spawning SCRAM version $version");
286 my $rv=system("scram", @_)/256;
287 exit $rv;
288 }
289 else
290 { # if not then simply warn
291 print "******* Warning : scram version inconsistent ********\n";
292 print "This version: $thisversion; Required version: $version\n";
293 print "*****************************************************\n";
294 print "\n";
295 }
296 }
297 }
298 else
299 {
300 $self->error("Undefined value for version requested");
301 $rv=1;
302 }
303 return $rv;
304 }
305
306 sub globalcache {
307 my $self=shift;
308 if ( @_ ) {
309 $self->{cachedir}=shift;
310 }
311 if ( ! defined $self->{globalcache} ) {
312 $self->{globalcache}=URL::URLcache->new($self->{cachedir});
313 }
314 return $self->{globalcache};
315 }
316
317
318 sub scramprojectdb {
319 my $self=shift;
320 if ( @_ ) {
321 $self->{scramprojectsdbdir}=shift;
322 }
323 if ( ! defined $self->{scramprojectsdb} ) {
324 require Scram::ScramProjectDB;
325 $self->{scramprojectsdb}=Scram::ScramProjectDB->new(
326 $self->{scramprojectsdbdir} );
327 $self->{scramprojectsdb}->verbosity($self->verbosity());
328 }
329 return $self->{scramprojectsdb};
330 }
331
332 sub getversion {
333 my $self=shift;
334
335 my $thisversion;
336 ($thisversion=$ENV{SCRAM_HOME})=~s/(.*)\///;
337 my $scram_top=$1;
338 my $scram_version=$thisversion;
339 # deal with links
340 my $version=readlink $ENV{SCRAM_HOME};
341 if ( defined $version) {
342 $scram_version=$version;
343 }
344 return $scram_version;
345 }
346
347 sub areatoolbox {
348 my $self=shift;
349 my $area=shift;
350
351 my $name=$area->location();
352 if ( ! defined $self->{toolboxes}{$name} ) {
353 # -- create a new toolbox object
354 require BuildSystem::ToolBox;
355 $self->{toolboxes}{$name}=BuildSystem::ToolBox->new($area,
356 $self->arch());
357 $self->{toolboxes}{$name}->verbosity($self->verbosity());
358 }
359 return $self->{toolboxes}{$name};
360 }
361
362 sub arearequirements {
363 my $self=shift;
364 my $area=shift;
365
366 my $name=$area->location();
367 if ( ! defined $self->{requirements}{$name} ) {
368 # -- create a new toolbox object
369 require BuildSystem::Requirements;
370 my $doc=$area->requirementsdoc();
371 my $cache=$area->cache();
372 my $db=$area->objectstore();
373 require ActiveDoc::ActiveStore;
374 my $astore=ActiveDoc::ActiveStore->new($db,$cache);
375 $self->{requirements}{$name}=
376 BuildSystem::Requirements->new($astore,"file:".$doc,
377 $ENV{SCRAM_ARCH});
378 $self->{requirements}{$name}->verbosity($self->verbosity());
379 $self->verbose("Requirements Doc (".$self->{requirements}{$name}.
380 ") for area :\n $name\n initiated from $doc");
381 }
382 else {
383 $self->verbose("Requirements Doc (".$self->{requirements}{$name}.")");
384 }
385 return $self->{requirements}{$name};
386 }
387
388 sub arch {
389 my $self=shift;
390
391 @_?$self->{arch}=shift
392 :$self->{arch};
393 }
394
395 sub scramobjectinterface {
396 my $self=shift;
397 my $class=shift;
398
399 my $file;
400 ($file=$class."\.pm")=~s/::/\//g;
401 $file=$ENV{TOOL_HOME}."/".$file;
402
403 if ( ! -f $file ) {
404 $self->error("Unable to find $class in ".$ENV{TOOL_HOME});
405 }
406 print "--------------------- $class ------------------\n";
407 my $fh=FileHandle->new();
408 $fh->open("<$file");
409 while ( <$fh> ) {
410 if ( $_=~/#\s*Interface/g ) {
411 $intregion=1;
412 next;
413 }
414 if ( $intregion ) { # if we are in the interface documentation
415 if ( ( $_!~/^#/ ) || ( $_=~/^#\s?-{40}/ ) ) { #moving out of Int doc
416 $intregion=0;
417 next;
418 }
419 print $_;
420 if ( $_=~/^#\s*(.*)\((.*)\)?:(.*)/ ) {
421 $interface=$1;
422 $args=$2;
423 $rest=$3;
424 next if ($interface eq "");
425 push @interfaces,$interface;
426 $interfaceargs{$interface}=$args;
427 }
428 }
429 }
430 print "\n";
431 undef $fh;
432 }
433
434 # -------------- Support Routines ------------------------------
435
436
437 sub _allprojectinitsearcher {
438 if ( ! defined $self->{projsearcher} ) {
439 my $search=_projsearcher();
440 foreach $proj ( $self->scramprojectdb()->list() ) {
441 $search->addproject($$proj[0],$$proj[1]);
442 }
443 }
444 return $self->{projsearcher};
445 }
446
447 sub _projsearcher {
448 if ( ! defined $self->{projsearcher} ) {
449 require Scram::ProjectSearcher;
450 $self->{projsearcher}=Scram::ProjectSearcher->new(
451 $self->scramprojectdb());
452 }
453 return $self->{projsearcher};
454 }
455
456
457 sub _lookupareaindb {
458 my $self=shift;
459
460 my $area=undef;
461 # -- Look up the area in the databse
462 my @areas=$self->scramprojectdb()->getarea(@_);
463 if ( $#areas > 0 ) { #ambigous
464 # could ask user - for now just error
465 $self->error("Ambigous request - please be more specific");
466 }
467 elsif ( $#areas != 0 ) { #not found
468 $self->error("The project requested has not been found");
469 }
470 else {
471 $area=$areas[0];
472 }
473 return $area;
474 }