ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/scram
Revision: 1.23.2.73
Committed: Wed Apr 26 10:29:17 2000 UTC (25 years ago) by williamc
Branch: V0_9branch
CVS Tags: V0_12_2, V0_12_1
Changes since 1.23.2.72: +3 -3 lines
Log Message:
project fixed

File Contents

# User Rev Content
1 williamc 1.8 #!/usr/local/bin/perl5
2 williamc 1.1 #
3     # User Interface
4     #
5 williamc 1.23.2.36 # Make sure were running the right version
6     versioncheck();
7    
8 williamc 1.1 $inputcmd=shift;
9     $found='false';
10 williamc 1.13 $bold = "\033[1m";
11 williamc 1.23.2.53 $rv=0;
12 williamc 1.13 $normal = "\033[0m";
13 williamc 1.23.2.44 @allowed_commands=qw(project build install version list arch setup runtime db);
14 williamc 1.23.2.59 @dev_cmds=qw(devtest);
15 williamc 1.1
16 williamc 1.21 if ( $inputcmd ne "" ) {
17 williamc 1.23.2.59 foreach $command ( (@allowed_commands,@dev_cmds) ) {
18 williamc 1.21 if ( $command=~/^$inputcmd/i) {
19 williamc 1.13 # Deal with a help request
20     do{ helpheader($command);
21     &{"help_".$command}; exit; } if $ARGV[0]=~/help/i;
22 williamc 1.23.2.52 $rv=&$command; $found='true';
23 williamc 1.13 last;
24     }
25 williamc 1.21 }
26 williamc 1.1 }
27    
28     if ( ! ( $found=~/true/ ) ) {
29 williamc 1.15 helpheader('Recognised Commands');
30 williamc 1.1 foreach $command ( @allowed_commands ) {
31 williamc 1.15 print " $bold scram ".$command.$normal."\n";
32 williamc 1.1 }
33 williamc 1.15 print "\n";
34     print "Help on individual commands available through\n\n";
35     print "$bold scram".$normal." command$bold help $normal\n\n";
36 williamc 1.1 }
37 williamc 1.23.2.52 exit $rv;
38 williamc 1.1
39 williamc 1.23.2.36 sub versioncheck {
40     my $version;
41     my $thisversion;
42    
43     $thisversion=getversion();
44    
45 williamc 1.23.2.67 if ( @_ ) {
46     $version=shift;
47     }
48     else {
49     if ( ! localtop_find() ) {
50     LoadEnvFile();
51     my $versionfile=$ENV{LOCALTOP}."/$ENV{projconfigdir}/scram_version";
52     if ( -f $versionfile ) {
53     open (VERSION, "<".$versionfile);
54 williamc 1.23.2.36 $version=<VERSION>;
55     chomp $version;
56 williamc 1.23.2.67 }
57     }
58     }
59     if ( defined $version ) {
60 williamc 1.23.2.36 if ( $version ne $thisversion ) {
61     # first try to use the correct version
62     if ( -d $scram_top."/".$version ) {
63     $ENV{SCRAM_HOME}=$scram_top."/".$version;
64 williamc 1.23.2.53 my $rv=system("scram", @ARGV)/256;
65     exit $rv;
66 williamc 1.23.2.36 }
67     else { # if not then simply warn
68     print "******* Warning : scram version inconsistent ********\n";
69     print "This version: $thisversion; Required version: $version";
70     print "*****************************************************\n";
71     print "\n";
72     }
73     }
74     }
75     }
76    
77 williamc 1.14 sub help_build {
78     &build;
79     }
80 williamc 1.1 sub build {
81     # is this a based or free release?
82     FullEnvInit();
83 williamc 1.23.2.58 use BuildSystem::BuildSetup;
84 williamc 1.10 $ENV{MAKETARGETS}=join ' ',@ARGV;
85 williamc 1.23.2.58 my $bs=BuildSystem::BuildSetup->new();
86     $rv=$bs->BuildSetup($ENV{THISDIR},@ARGV);
87 williamc 1.23.2.52 $rv;
88 williamc 1.1 }
89    
90     sub project {
91 williamc 1.23.2.67 my @args=@ARGV;
92 williamc 1.7 # process options
93 williamc 1.23.2.67 while ( $args[0]=~"^-" ) {
94     if ( $args[0]=~/-n/ ) {
95     shift @args;
96     $ENV{devareaname}=shift @args;
97 williamc 1.23 }
98 williamc 1.23.2.67 elsif ( $args[0]=~/-d/ ) { #installation area directory
99     shift @args;
100     chdir $args[0];
101     shift @args;
102 williamc 1.23.2.47 }
103     else {
104 williamc 1.23.2.67 print "scram: unknown option $args[0] to project command\n";
105 williamc 1.23.2.50 exit 1;
106 williamc 1.7 }
107     }
108 williamc 1.23.2.67 my $project=shift @args;
109     my $version=shift @args;
110    
111     # quick scram version check (hack) -
112 williamc 1.1 environmentinit();
113 williamc 1.23.2.67 my $pjurl="$project\?\?$version";
114     require Utilities::urlhandler;
115     my $bsfile=urlhandler::urlhandler($pjurl);
116 williamc 1.23.2.70 my $local=0;
117 williamc 1.23.2.72 my $config;
118 williamc 1.23.2.67 if ( ($dir)=($bsfile=~/(.*)\/InstallFile$/) ) { # -- we have a dev area
119     require Configuration::ConfigArea;
120 williamc 1.23.2.72 $config=Configuration::ConfigArea->new();
121 williamc 1.23.2.70 $local=1;
122 williamc 1.23.2.67 $config->bootstrapfromlocation($dir);
123     unshift @ARGV, "project";
124     versioncheck($config->scramversion());
125     }
126    
127 williamc 1.1 use File::Copy;
128 williamc 1.2 use Utilities::AddDir;
129 williamc 1.1
130     use BootStrapProject;
131     # get the bootstrap files downloaded
132 williamc 1.23.2.67 BootStrapProject($pjurl);
133    
134 williamc 1.1 # Go setup the rest of the environement, now we can
135 williamc 1.23 chdir $ENV{LOCALTOP};
136     &localtop;
137 williamc 1.1 LoadEnvFile();
138 williamc 1.23.2.67
139 williamc 1.1 #
140     # Now create the directories specified in the interface
141     #
142     foreach $key ( keys %ENV ) {
143     if ( $key=~/^INT/ ) {
144 williamc 1.5 AddDir::adddir($ENV{$key});
145 williamc 1.1 }
146     }
147 williamc 1.6 if ( ! -e "$ENV{LOCALTOP}/$ENV{projconfigdir}" ) {
148 williamc 1.23.2.71 AddDir::copydir("$ENV{RELEASETOP}/$ENV{projconfigdir}",
149 williamc 1.6 "$ENV{LOCALTOP}/$ENV{projconfigdir}");
150     }
151 williamc 1.23.2.67
152 williamc 1.23.2.63 require BuildSystem::Requirements;
153     my $req=_requirements();
154 williamc 1.23.2.69
155 williamc 1.23.2.63 $req->download(toolbox());
156 williamc 1.23.2.70 if ( ! $local ) {
157     $req->setup(toolbox());
158     }
159 williamc 1.23.2.71 else {
160     AddDir::copydir($config->location()."/".$ENV{SCRAM_ARCH},
161     $ENV{LOCALTOP}."/.SCRAM/".$ENV{SCRAM_ARCH});
162     }
163 williamc 1.7 use Cwd;
164 williamc 1.20 print "\nInstallation Procedure Complete. \n".
165     "Installation Located at:\n".cwd()."\n";
166 williamc 1.1 }
167 williamc 1.7
168 williamc 1.23.2.63 sub _requirements {
169     if ( ! defined $reqsobj ) {
170     require BuildSystem::Requirements;
171     $reqsobj=BuildSystem::Requirements->new($ENV{SCRAM_ProjReqsDoc});
172     }
173     return $reqsobj;
174     }
175    
176 williamc 1.23.2.2 sub runtime {
177     my $shell;
178 williamc 1.23.2.58 require Runtime;
179 williamc 1.23.2.2
180     # process options
181     while ( $ARGV[0]=~"^-" ) {
182     if ( $ARGV[0]=~/-sh/ ) {
183     shift @ARGV;
184     $shell="sh";
185     next;
186     }
187     if ( $ARGV[0]=~/-csh/ ) { #installation area directory
188     shift @ARGV;
189     $shell="csh";
190     next;
191     }
192     print "Unknown Option $ARGV[0]\n";
193     exit 1;
194     }
195 williamc 1.23.2.30
196 williamc 1.23.2.62 FullEnvInit();
197 williamc 1.23.2.55 if ( @ARGV ) {
198     my $runtime=Runtime->new();
199 williamc 1.23.2.56 my $arg=shift @ARGV;
200    
201     my $info=0;
202     if ( $arg eq "info" ) {
203     $arg=shift @ARGV;
204     $info=1;
205     }
206    
207     # --- determine filename
208     my $filename;
209     if ( -f $arg ) { # Is it a file?
210     $filename=$arg;
211     }
212     else {
213     # -- lets see if its a BuildFile location
214 williamc 1.23.2.57 $filename=_testfile($ENV{LOCALTOP}."/src/".$arg,
215     $ENV{RELEASETOP}."/src/".$arg,
216     $ENV{LOCALTOP}."/src/".$arg."/BuildFile",
217     $ENV{RELEASETOP}."/src/".$arg."/BuildFile");
218 williamc 1.23.2.56 if ( $filename eq "" ) {
219 williamc 1.23.2.57 print "Unable to find a file (or BuildFile) relating to ".
220 williamc 1.23.2.56 $arg."\n";
221     exit 1;
222     }
223     }
224     $runtime->file($filename);
225     if ( ! $info ) {
226     $runtime->printenv($shell);
227     }
228     else {
229     if ( @ARGV ) { #do we have a specific variable request?
230     _printvardoc($runtime,shift @ARGV);
231     }
232     else {
233     foreach $var ( $runtime->list() ) {
234     _printvardoc($runtime,$var);
235     }
236     }
237     }
238 williamc 1.23.2.55 undef $runtime;
239     }
240     else {
241 williamc 1.23.2.56 FullEnvInit();
242 williamc 1.23.2.30 # We have to clean up from the last runtime cmd - use env history
243     foreach $variable ( %ENV ) {
244     if ( $variable=~/^SCRAMRT_(.*)/ ) { #SCRAMRT are history retaining
245     my $var=$1;
246     $ENV{$var}=~s/\Q$ENV{$variable}\E//g;
247     $ENV{$var}=~s/^:*//; # Deal with any Path variables
248     #print "$variable : $ENV{$variable} \n$var : $ENV{$var}\n";
249     delete $ENV{$variable};
250     }
251     }
252    
253 williamc 1.23.2.60 # -- Set SCRAM release area paths
254 williamc 1.23.2.32 addpath("LD_LIBRARY_PATH","$ENV{LOCALTOP}/lib/$ENV{SCRAM_ARCH}");
255     addpath("LD_LIBRARY_PATH","$ENV{RELEASETOP}/lib/$ENV{SCRAM_ARCH}");
256 williamc 1.23.2.30
257 williamc 1.23.2.60 # -- get the tool runtime environments
258 williamc 1.23.2.63 my $toolbox=toolbox();
259 williamc 1.23.2.60 foreach $toolpair ( $toolbox->tools() ) {
260     # TODO - check for doubles
261     $tool=$toolbox->gettool($$toolpair[0]);
262    
263 williamc 1.23.2.62 if ( defined $tool ) {
264     # -- get runtime paths
265     foreach $f ( $tool->listtype("runtime_path")) {
266 williamc 1.23.2.60 foreach $val ( $tool->getfeature($f) ) {
267     addpath($f,$val);
268     }
269 williamc 1.23.2.62 }
270     # -- get runtime vars
271     foreach $f ( $tool->listtype("runtime")) {
272 williamc 1.23.2.60 foreach $val ( $tool->getfeature($f) ) {
273     $EnvRuntime{$f}=$val;
274     }
275 williamc 1.23.2.62 }
276 williamc 1.23.2.60 }
277 williamc 1.23.2.2 }
278 williamc 1.23.2.60
279 williamc 1.23.2.34 addpath("PATH","$ENV{LOCALTOP}/bin/$ENV{SCRAM_ARCH}");
280     addpath("PATH","$ENV{RELEASETOP}/bin/$ENV{SCRAM_ARCH}");
281 williamc 1.23.2.24
282     # Now get the general project environment
283     open ( SCRAMENV, "<$ENV{LOCALTOP}/$ENV{projconfigdir}/Runtime" );
284     while ( <SCRAMENV> ) {
285     chomp;
286     next if /^#/;
287     next if /^\s*$/;
288     ($name, $value)=split /=/;
289     addvar($name, (eval $value)," ");
290     }
291     close SCRAMENV;
292    
293 williamc 1.23.2.13 # create new SCRAMRT history vars.
294     foreach $variable ( keys %EnvRuntime ) {
295 williamc 1.23.2.30 printoutenv($shell,"SCRAMRT_$variable",$EnvRuntime{$variable});
296     #addvar("SCRAMRT_$variable", $EnvRuntime{$variable}, "");
297 williamc 1.23.2.13 }
298     # Now adapt as necessary - include base environment as well
299 williamc 1.23.2.26 if ( exists $ENV{LD_LIBRARY_PATH} ) {
300 williamc 1.23.2.31 addpath("LD_LIBRARY_PATH","$ENV{LD_LIBRARY_PATH}");
301 williamc 1.23.2.26 }
302 williamc 1.23.2.27 if ( exists $ENV{MANPATH} ) {
303 williamc 1.23.2.34 addpath("MANPATH","$ENV{MANPATH}");
304 williamc 1.23.2.27 }
305 williamc 1.23.2.34 addpath("PATH","$ENV{PATH}");
306 williamc 1.23.2.13 # Print out as reqd
307 williamc 1.23.2.2 foreach $variable ( keys %EnvRuntime ) {
308 williamc 1.23.2.29 printoutenv($shell,$variable,$EnvRuntime{$variable});
309 williamc 1.23.2.55 }
310 williamc 1.23.2.2 }
311     }
312    
313     # Support rt for runtime
314 williamc 1.23.2.29
315 williamc 1.23.2.56 sub _testfile {
316     my @files=@_;
317    
318     my $filename="";
319     foreach $file ( @files ) {
320     if ( -f $file ) {
321     $filename=$file;
322     last;
323     }
324     }
325     return $filename;
326     }
327    
328     sub _printvardoc {
329     my $runtime=shift;
330     my $var=shift;
331    
332     print $var." :\n";
333     print $runtime->doc($var);
334     print "\n";
335     }
336    
337 williamc 1.23.2.29 sub printoutenv {
338     my $shell=shift;
339     my $variable=shift;
340     my $value=shift;
341    
342     if ( $shell eq "csh" ) {
343 williamc 1.23.2.30 print "setenv $variable \"$value\";\n";
344 williamc 1.23.2.29 }
345     elsif ( $shell eq "sh" ) {
346 williamc 1.23.2.30 print "$variable=\"$value\";\n";
347 williamc 1.23.2.29 print "export $variable;\n";
348     }
349 williamc 1.23.2.31 }
350    
351     sub addpath {
352     my $name=shift;
353     my $val=shift;
354    
355     my $n;
356 williamc 1.23.2.35 my @env;
357     @env=split /:/, $EnvRuntime{$name};
358 williamc 1.23.2.31 foreach $n ( (split /:/, $val ) ){
359 williamc 1.23.2.46 if ( ! grep /^\Q$n\E$/, @env ) {
360 williamc 1.23.2.32 addvar($name,$n,":");
361 williamc 1.23.2.31 }
362     }
363 williamc 1.23.2.29 }
364    
365 williamc 1.23.2.2 sub addvar {
366     my $name=shift;
367     my $val=shift;
368     my $sep=shift;
369    
370 williamc 1.23.2.3 if ( $val ne "" ) {
371 williamc 1.23.2.2 if ( defined $EnvRuntime{$name} ) {
372     $EnvRuntime{$name}=$EnvRuntime{$name}.$sep.$val;
373     }
374     else {
375     $EnvRuntime{$name}=$val;
376     }
377 williamc 1.23.2.3 }
378 williamc 1.23.2.2 }
379    
380 williamc 1.1 sub FullEnvInit {
381     environmentinit();
382     localtop();
383     LoadEnvFile();
384     }
385    
386     sub environmentinit {
387 williamc 1.2 use Utilities::setarchitecture;
388 williamc 1.1 my $name;
389     my $value;
390    
391     $ENV{LatestBuildFile}=""; # stop recursive behaviour in make
392 williamc 1.4 setarchitecture::setarch();
393 williamc 1.1 $ENV{INTwork}="tmp/$ENV{SCRAM_ARCH}";
394     $ENV{INTlib}="lib/$ENV{SCRAM_ARCH}";
395     $ENV{INTsrc}="src";
396     $ENV{INTbin}="bin/$ENV{SCRAM_ARCH}";
397     $ENV{INTlog}="logs";
398    
399 williamc 1.23.2.42 ($ENV{SCRAM_BASEDIR}=$ENV{SCRAM_HOME})=~s/(.*)\/.*/$1/;
400     if ( ! ( exists $ENV{SCRAM_CONFIG} ) ){
401 williamc 1.3 $ENV{SCRAM_CONFIG}="$ENV{SCRAM_HOME}/configuration";
402 williamc 1.1 }
403     if ( ! ( exists $ENV{TOOL_HOME} ) ){
404 williamc 1.4 $ENV{TOOL_HOME}="$ENV{SCRAM_HOME}/src";
405 williamc 1.1 }
406     if ( ! ( exists $ENV{SCRAM_LOOKUPDB} ) ){
407 williamc 1.23.2.42 if ( -d "$ENV{SCRAM_BASEDIR}/scramdb/" ) {
408     $ENV{SCRAM_LOOKUPDB}="$ENV{SCRAM_BASEDIR}/scramdb/project.lookup";
409     }
410     else {
411     $ENV{SCRAM_LOOKUPDB}="$ENV{SCRAM_CONFIG}/project.lookup";
412     }
413 williamc 1.1 }
414 williamc 1.23.2.25 $ENV{SCRAM_AVAILDIRS}="";
415     $ENV{SCRAM_AVAILFILES}="";
416 williamc 1.1 }
417    
418 williamc 1.23.2.38 sub localtop_find {
419 williamc 1.1 # find localtop
420     use Cwd;
421     my $thispath=cwd;
422 williamc 1.23.2.38 my $rv=1;
423    
424 williamc 1.1 block: {
425     do {
426     if ( -e "$thispath/.SCRAM" ) {
427     $ENV{LOCALTOP}=$thispath;
428 williamc 1.23.2.39 $ENV{SCRAM_WORKDIR}="$ENV{LOCALTOP}/.SCRAM";
429 williamc 1.23.2.38 $rv=0;
430 williamc 1.23.2.39 last block;
431 williamc 1.1 }
432     } while ( ( $thispath=~s/(.*)\/.*/$1/ )=~/./ );
433 williamc 1.23.2.38 } #end block
434     return $rv;
435     }
436    
437     sub localtop {
438     localtop_find();
439 williamc 1.1 if ( ! (defined $ENV{LOCALTOP}) ) {
440     print "Unable to locate the top of local release. Exiting\n";
441 williamc 1.18 exit 1;
442 williamc 1.1 }
443 williamc 1.19 ($ENV{THISDIR}=cwd)=~s/^\Q$ENV{LOCALTOP}\L//;
444 williamc 1.1 $ENV{THISDIR}=~s/^\///;
445     }
446    
447     sub LoadEnvFile {
448     open ( SCRAMENV, "<$ENV{SCRAM_WORKDIR}/Environment" ) ||
449     die "Cant find Environment file $!\n";
450     while ( <SCRAMENV> ) {
451     chomp;
452     next if /^#/;
453     next if /^\s*$/ ;
454     ($name, $value)=split /=/;
455     eval "\$ENV{${name}}=\"$value\"";
456     }
457     close SCRAMENV;
458     }
459    
460     sub env {
461     print "Sorry - Not yet\n";
462 williamc 1.23.2.59 }
463    
464     sub devtest {
465     require Utilities::TestClass;
466     my $class=shift @ARGV;
467    
468     my $tester;
469     my $path;
470    
471     #_initproject();
472     if ( $class=~/::/ ) {
473     ($path=$class)=~s/(.*)::.*/$1/;
474     }
475     $tester=Utilities::TestClass->new($class,
476     "$ENV{SCRAM_HOME}/src/$path/test/testdata");
477     $tester->dotest(@_);
478 williamc 1.1 }
479    
480     #
481     # Create a lookup tag in the site database
482     #
483     sub install ( $tagname, $version ) {
484     my $tagname=shift @ARGV;
485     my $version=shift @ARGV;
486    
487     # create database entry
488     &FullEnvInit;
489     if ( $version eq "" ) {
490     $version=$ENV{SCRAM_PROJVERSION};
491     }
492     if ( $tagname eq "" ) {
493     $tagname=$ENV{SCRAM_PROJECTNAME};
494     }
495 williamc 1.23.2.40 my $filename=$ENV{SCRAM_LOOKUPDB};
496 williamc 1.23.2.41 my $outfile=$ENV{SCRAM_LOOKUPDB}.".tmp";
497 williamc 1.1 open ( LOCALLOOKUPDB, "<$filename" );
498 williamc 1.16 open ( OUTFILE , ">$outfile" ) or die "Unable to open $outfile $!\n";
499 williamc 1.1 while ( <LOCALLOOKUPDB> ) {
500     if ( /^$tagname/ ) {
501     print "Related tag :".$_."\n";
502     if ( /$version/) {
503     print "$tagname $version already exists. Overwrite (y/n)\n";
504     if ( ! (<STDIN>=~/y/i ) ) {
505     print "Aborting install ...\n";
506     close OUTFILE;
507     close LOCALLOOKUPDB;
508     exit 1;
509     }
510     }
511     else {
512     print OUTFILE $_;
513     }
514     }
515     else {
516     print OUTFILE $_;
517     }
518     }
519     print OUTFILE "$tagname:$version:file:$ENV{LOCALTOP}".
520     "/.SCRAM/InstallFile\n";
521     close OUTFILE;
522     close LOCALLOOKUPDB;
523     copy ( "$outfile", "$filename" )
524     || die "Unable to copy $! \n";
525 williamc 1.23.2.19 &align;
526     }
527 williamc 1.1
528 williamc 1.23.2.19 #
529     # align variables with actual location of release
530     #
531    
532     sub align {
533     &localtop;
534     LoadEnvFile();
535    
536     use File::Copy;
537     rename( "$ENV{SCRAM_WORKDIR}/Environment",
538     "$ENV{SCRAM_WORKDIR}/Environment.bak");
539     open ( SCRAMENV, "<$ENV{SCRAM_WORKDIR}/Environment.bak" ) ||
540     die "Cant find Environment file $!\n";
541     open ( SCRAMENVOUT, ">$ENV{SCRAM_WORKDIR}/Environment" ) ||
542     die "Cant Open Environment file $!\n";
543     while ( <SCRAMENV> ) {
544     $_=~s/\Q$ENV{RELEASETOP}\L/$ENV{LOCALTOP}/g;
545     print SCRAMENVOUT $_;
546     }
547     close SCRAMENV;
548     close SCRAMENVOUT;
549 williamc 1.1 }
550    
551     sub help_install() {
552    
553     print <<ENDTEXT;
554     Associates a label with the current release in the SCRAM database.
555     This allows other users to refer to a centrally installed project by
556     this label rather than a remote url reference.
557    
558     Usage:
559    
560 williamc 1.23.2.20 $bold scram install $normal [project_tag [version_tag]]
561 williamc 1.1
562 williamc 1.23.2.20 porject_tag : override default label (the project name of the current release)
563     version_tag : the version tag of the current release. If version is not
564 williamc 1.1 specified the base release version will be taken by default.
565    
566     ENDTEXT
567     }
568    
569     sub helpheader ($label) {
570     my $label=shift;
571     print <<ENDTEXT;
572     *************************************************************************
573     SCRAM HELP --------- $label
574     *************************************************************************
575     ENDTEXT
576     }
577    
578 williamc 1.23.2.36 sub getversion {
579     ($thisversion=$ENV{SCRAM_HOME})=~s/(.*)\///;
580     $scram_top=$1;
581     $scram_version=$thisversion;
582     # deal with links
583     my $version=readlink $ENV{SCRAM_HOME};
584     if ( defined $version) {
585     $scram_version=$version;
586     }
587     return $scram_version;
588     }
589    
590 williamc 1.1 sub version {
591 williamc 1.23.2.7 my $version=shift @ARGV;
592 williamc 1.23.2.6 my $thisversion;
593 williamc 1.23.2.7 my $scram_top;
594     my $cvsobject;
595    
596     ($thisversion=$ENV{SCRAM_HOME})=~s/(.*)\///;
597     $scram_top=$1;
598     if ( $version eq "" ) {
599 williamc 1.23.2.36 print "$thisversion";
600     # deal with links
601     $version=readlink $ENV{SCRAM_HOME};
602     if ( defined $version) {
603     print " ---> $version";
604     }
605     print "\n";
606 williamc 1.23.2.7 }
607     else {
608     if ( -d $scram_top."/".$version ) {
609     print "Version $version exists\n";
610     }
611     else {
612     print "Version $version not available locally\n";
613 williamc 1.23.2.22 print "Attempting download from the SCRAM repository\n";
614 williamc 1.23.2.7 # set up and configure the cvs module for SCRAM
615     use Utilities::cvsmodule;
616     $cvsobject=cvsmodule->new();
617     $cvsobject->set_base(
618     "cmscvs.cern.ch:/cvs_server/repositories/SCRAM");
619     $cvsobject->set_auth("pserver");
620     $cvsobject->set_user("anonymous");
621     $cvsobject->set_passkey("AA_:yZZ3e");
622     # Now check it out in the right place
623     chdir $scram_top or die "Unable to change to $scram_top $!\n";
624     $cvsobject->invokecvs( ( split / /,
625     "co -d $version -r $version SCRAM" ));
626    
627     # Get rid of cvs object now weve finished
628     $cvsobject=undef;
629     print "\n";
630     }
631     }
632 williamc 1.23.2.53 0;
633 williamc 1.1 }
634    
635     sub list {
636     &environmentinit;
637 williamc 1.23.2.42 my $filename="$ENV{SCRAM_LOOKUPDB}";
638 williamc 1.23.2.48 if ( ! -f $ENV{SCRAM_LOOKUPDB} ) {
639     print "No installation database available - perhaps no projects".
640 williamc 1.23.2.56 " have been installed locally\n";
641 williamc 1.23.2.50 exit 1;
642 williamc 1.23.2.48 }
643 williamc 1.1 print "Installed Projects\n";
644     print "------------------\n";
645     print "|Project Name | Project Version |\n";
646     print "----------------------------------\n";
647 williamc 1.23.2.43 listdb($filename);
648     }
649    
650 williamc 1.23.2.44 sub db {
651     my $subcmd=shift @ARGV;
652     &environmentinit;
653    
654     switch : {
655     if ( $subcmd eq 'link' ) {
656     dblink($ENV{SCRAM_LOOKUPDB},@ARGV);
657     last switch;
658     }
659 williamc 1.23.2.49 if ( ! -f $ENV{SCRAM_LOOKUPDB} ) {
660     print "No installation database available - perhaps no projects".
661     "have been installed locally\n";
662 williamc 1.23.2.50 exit 1;
663 williamc 1.23.2.49 }
664 williamc 1.23.2.44 if ( $subcmd eq 'unlink' ) {
665     dbunlink($ENV{SCRAM_LOOKUPDB},@ARGV);
666     last switch;
667     }
668     if ( $subcmd eq 'showlinks' ) {
669     dblinklist($ENV{SCRAM_LOOKUPDB});
670     last switch;
671     }
672     } # end switch
673    
674     }
675    
676     sub dblinklist {
677     my $filename=shift;
678     open (LOCALLOOKUPDB, "<$filename") or
679     die "Unable to open local database $!";
680     while (<LOCALLOOKUPDB>) {
681     if ( $_=~/\!DB (.*)/) {
682     print $1,"\n";
683     }
684     }
685     close LOCALLOOKUPDB;
686     }
687    
688     sub dblink {
689     my $filename=shift;
690     my $newdbfilename=shift;
691     my $exists=0;
692    
693     if ( -e $filename ) {
694     if ( -e $newdbfilename ) {
695     # Check if its already there
696     open (LOCALLOOKUPDB, "<$filename") or
697     die "Unable to open local database $!";
698     while (<LOCALLOOKUPDB>) {
699     if ( $_=~/\!DB $newdbfilename/ ) {
700     $exists=1;
701     last;
702     }
703     }
704     close LOCALLOOKUPDB;
705     # Add it
706     if ( ! $exists ) {
707     open (LOCALLOOKUPDB, ">>$filename") or
708     die "Unable to open local database $!";
709     print LOCALLOOKUPDB "\!DB $newdbfilename\n";
710     close LOCALLOOKUPDB;
711     }
712     }
713     else {
714     print "Unknown file $newdbfilename\n";
715 williamc 1.23.2.50 exit 1;
716 williamc 1.23.2.44 }
717     }
718     else {
719     print "Unknown file $filename $!\n";
720 williamc 1.23.2.50 exit 1;
721 williamc 1.23.2.44 }
722    
723     }
724    
725     sub dbunlink {
726     my $filename=shift;
727     my $dbfilename=shift;
728     if ( -e $filename ) {
729     # Check if its already there
730     open (LOCALLOOKUPDB, "<$filename") or
731     die "Unable to open local database $!";
732     open (DBOUTFILE, ">$filename.tmp") or
733     die "Unable to open working file $!";
734     while (<LOCALLOOKUPDB>) {
735     if ( $_!~/\!DB $dbfilename/ ) {
736     print DBOUTFILE $_;
737     }
738     }
739     close LOCALLOOKUPDB;
740     close DBOUTFILE;
741     use File::Copy;
742     rename "$filename.tmp", $filename;
743     }
744     }
745    
746 williamc 1.23.2.43 sub listdb {
747     my $filename=shift;
748     my $map;
749    
750 williamc 1.23.2.44 use FileHandle;
751     my $fh=FileHandle->new();
752     open ( $fh, "<$filename" );
753     while ( $map=<$fh> ) {
754 williamc 1.23.2.43 if ( $map=~/^\!DB (.*)/ ) { # Check for other DB files
755     my $db=$1;
756     if ( -f $db ) {
757     listdb($db);
758     }
759     next;
760     }
761     ( $name, $version, $type, $url ) = split ":", $map;
762 williamc 1.1 printf "%1s",$name;
763     printf "%25s\n",$version;
764     printf "--> %25s\n",$type.":".$url;
765     }
766 williamc 1.23.2.44 close $fh;
767 williamc 1.23.2.53 0;
768 williamc 1.1 }
769    
770     sub arch {
771     &environmentinit();
772     print "$ENV{SCRAM_ARCH}\n";
773 williamc 1.11 }
774    
775 williamc 1.12
776     #
777     # Setup a new tool
778     #
779    
780     sub setup {
781 williamc 1.23.2.66 my $interactive=0;
782    
783     # process options
784     while ( $ARGV[0]=~"^-" ) {
785     if ( $ARGV[0]=~/-i/ ) {
786     shift @ARGV;
787     $interactive=1;
788     }
789     else {
790     print "scram: unknown option $ARGV[0] to project command\n";
791     exit 1;
792     }
793     }
794    
795     &FullEnvInit;
796 williamc 1.12 my $toolname=shift @ARGV;
797 williamc 1.23.2.4 my $insert=0;
798 williamc 1.23.2.66 toolbox()->interactive($interactive);
799 williamc 1.12
800 williamc 1.23.2.14 if ( $ENV{SCRAM_BootStrapFiles}!~/\Q$ENV{LOCALTOP}\N\/\.SCRAM/ ) {
801 williamc 1.12 $ENV{SCRAM_BootStrapFiles}="$ENV{LOCALTOP}/.SCRAM:".
802     $ENV{SCRAM_BootStrapFiles};
803     }
804 williamc 1.20 # If no toolname specified then its a full setup
805     if ( $toolname eq "" ) {
806 williamc 1.23.2.63 # -- add architecture specific directories
807 williamc 1.23.2.11 use Utilities::AddDir;
808 williamc 1.23.2.13 AddDir::adddir("$ENV{LOCALTOP}/lib/$ENV{SCRAM_ARCH}");
809     AddDir::adddir("$ENV{LOCALTOP}/bin/$ENV{SCRAM_ARCH}");
810 williamc 1.23.2.63
811     # -- check the releasetop area
812     # if the releasetop has the files copy them
813 williamc 1.23.2.73 if ( ( -d $ENV{RELEASETOP}."/.SCRAM/".$ENV{SCRAM_ARCH} ) &&
814 williamc 1.23.2.69 ( $ENV{RELEASETOP} ne $ENV{LOCALTOP} ) ) {
815 williamc 1.23.2.73 AddDir::copydir($ENV{RELEASETOP}."/.SCRAM/".$ENV{SCRAM_ARCH},
816     $ENV{LOCALTOP}."/.SCRAM/".$ENV{SCRAM_ARCH});
817 williamc 1.23.2.63 }
818     else { #activate a full setup
819     my $reqs=_requirements();
820     $reqs->setup(toolbox());
821     }
822 williamc 1.20 }
823     else {
824 williamc 1.23.2.64 if ( my $rv=toolbox()->toolsetup($toolname,@ARGV) ) {
825     if ( $rv eq 1 ) {
826     print "Unknown tool $toolname @ARGV\n";
827     exit 1;
828     }
829     }
830 williamc 1.12 }
831 williamc 1.23.2.63 }
832    
833     # get a toolbox object for the project
834     sub toolbox {
835     if ( ! defined $toolbox ) {
836     require BuildSystem::ToolBox;
837     $toolbox=BuildSystem::ToolBox->new();
838     }
839     return $toolbox;
840 williamc 1.23.2.44 }
841    
842     sub help_db {
843     print <<ENDTEXT;
844     scram database administration command.
845    
846     Usage:
847    
848     $bold scram db $normal subcommand
849    
850     subcommands:
851     link :
852     Make available an additional database for
853     project and list operations
854    
855 williamc 1.23.2.45 $bold scram db link $normal /a/directory/path/project.lookup
856 williamc 1.23.2.44
857     unlink :
858     Remove a database from the link list. Note this does
859     not remove the database, just the link to it in scram.
860    
861 williamc 1.23.2.45 $bold scram db unlink $normal /a/directory/path/project.lookup
862 williamc 1.23.2.44
863     showlinks :
864     List the databases that are linked in
865    
866     ENDTEXT
867 williamc 1.12 }
868    
869 williamc 1.13 sub help_setup {
870 williamc 1.12
871     print <<ENDTEXT;
872 williamc 1.23.2.5 Allows installation/re-installation of a new tool/external package into an
873     already existing development area. If not toolname is specified,
874     the complete installation process is initiated.
875 williamc 1.12
876     Usage:
877    
878 williamc 1.23.2.66 $bold scram setup [-i]$normal [toolname] [[version] [url]]
879 williamc 1.12
880     toolname : The name of the tool setup file required.
881 williamc 1.23.2.63 version : where more than one version exists specify the version
882     url : when setting up a completely new tool specify the url too
883 williamc 1.23.2.66
884     The -i option turns off the automatic search mechanism allowing for more
885     user interaction with the setup mechanism
886 williamc 1.12 ENDTEXT
887 williamc 1.13 }
888    
889     sub help_list {
890     print <<ENDTEXT;
891 williamc 1.23.2.20 List the available projects and versions installed in the local SCRAM database
892     (see scram install help)
893 williamc 1.13
894 williamc 1.23.2.20 Usage:
895    
896     $bold scram list $normal
897 williamc 1.13
898     ENDTEXT
899     }
900 williamc 1.23.2.20
901 williamc 1.13 sub help_project {
902     print <<ENDTEXT;
903     Setup a new project development area. The new area will appear in the current
904     working directory.
905     Usage:
906    
907 williamc 1.23.2.1 $bold scram project [-d install_area] [-n directory_name]$normal project_url [project_version]
908 williamc 1.13
909     Options:
910    
911     project_url: The url of a scram bootstrap file.
912     Currently supported types are:
913     $bold Database label $normal
914     Labels can be assigned to bootstrap files for easy
915     access (See "scram install" command). If you
916     specify a label you must also specify a project_version.
917     e.g.
918    
919     scram project SCRAM V1_0
920    
921     scram project ORCA ORCA_1_1_1
922    
923     To see the list of installed projects use the
924     "scram list" command.
925    
926     $bold file: $normal A regular file on an accessable file system
927     e.g.
928    
929     file:~/myprojects/projecta/config/BootStrapFile
930    
931     project_version:
932     Only for use with a database label
933    
934     -d install_area:
935     Indicate a project installation area into which the new
936     project area should appear. Default is the current working
937     directory.
938 williamc 1.23.2.1
939     -n directory_name:
940     Specify the name of the SCRAM development area you wish to
941     create.
942 williamc 1.13
943 williamc 1.14 ENDTEXT
944     }
945    
946     sub help_version {
947     print <<ENDTEXT;
948 williamc 1.23.2.54 With now $bold [version] $normal argument given, this command will simply
949 williamc 1.23.2.9 print to standard output the current version number.
950    
951     Providing a version argument will cause that version to be downloaded and
952     installed, if not already locally available.
953    
954    
955 williamc 1.14 Usage:
956 williamc 1.23.2.9 $bold scram version [version]$normal
957 williamc 1.14
958     ENDTEXT
959     }
960    
961     sub help_arch {
962     print <<ENDTEXT;
963     Print out the architecture flag for the current machine.
964    
965     Usage:
966     $bold scram arch $normal
967 williamc 1.23.2.2 ENDTEXT
968     }
969    
970     sub help_runtime {
971     print <<ENDTEXT;
972     Echo to Standard Output the Runtime Environment for the current development area
973     Output available in csh or sh flavours
974    
975     Usage:
976 williamc 1.23.2.56 1) $bold scram runtime [-csh|-sh] $normal
977     or
978     2) $bold scram runtime [-csh|-sh] filename $normal
979     or
980     3) $bold scram runtime info filename [variable]$normal
981    
982     1) For the general configuration environment
983     2) For environment described in filename or
984     areatop/src/directory/BuildFile
985     3) Display information concerning the environment in the given file
986     (limited to variable if specified)
987    
988     The file for cases 2) and 3) are searched as follows :
989     a) straightforward filename
990     b) filename relative to local_area/src
991     c) filename relative to release_area/src
992     d) BuildFile relative to local_area/src
993     e) BuildFile relative to release_area/src
994 williamc 1.23.2.3
995     Examples:
996    
997     Setup the current environment to include the project Runtime Environment
998     in a csh environment
999    
1000     $bold eval `scram runtime -csh` $normal
1001    
1002     Setup the current environment to include the project Runtime Environment in a
1003     sh environment
1004    
1005 williamc 1.23.2.23 $bold eval `scram runtime -sh` $normal
1006 williamc 1.23.2.21
1007 williamc 1.23.2.2
1008 williamc 1.13 ENDTEXT
1009 williamc 1.1 }