ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/scram
Revision: 1.23.2.89
Committed: Tue Jun 20 16:40:56 2000 UTC (24 years, 10 months ago) by williamc
Branch: V0_9branch
CVS Tags: V0_12_12_4, V0_12_12_3, V0_12_12_2, V0_12_12_1, V0_12_12_0, PlayGround_0, V0_13_0, V0_12_12
Branch point for: HPWbranch
Changes since 1.23.2.88: +1 -1 lines
Log Message:
fix toolbox problem and return to releasedoc mechanism

File Contents

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