ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/scramcli
Revision: 1.51
Committed: Fri Aug 16 11:54:15 2002 UTC (22 years, 9 months ago) by sashby
Branch: MAIN
Changes since 1.50: +3 -1 lines
Log Message:
Added FIRSTLIBS option.

File Contents

# User Rev Content
1 sashby 1.26 # -*-perl-*-
2 sashby 1.2 #===========================================================================#
3 sashby 1.15 # NAME: scramcli #
4 sashby 1.2 #===========================================================================#
5     # DATE: Mon May 28 11:36:18 2001 #
6     # AUTHOR: C. Williams #
7     # MAINTAINER: Shaun Ashby #
8     #===========================================================================#
9     # DESCRIPTION: The main scram program (NOTE: this is wrapped at runtime to #
10     # set up the path to the SCRAM Perl modules). #
11 sashby 1.15 # #
12 sashby 1.2 #===========================================================================#
13 sashby 1.36 # V1.36: V0_19_3 release ready Wed Feb 20 13:41:56 2002 #
14 sashby 1.40 # V1.39: NR fixes included (no references to "which" anywhere) #
15 sashby 1.44 # V1.44: Added -f options to set/project. Added simple parser to #
16     # remove duplicate lib entries. #
17 sashby 1.46 # V1.46: V0_19_4 release ready Tue May 21 12:35:14 2002 #
18 sashby 1.51 # V1.49: V0_19_6p1 prerelease Tue May 21 13:53:14 2002 #
19 sashby 1.36 #===========================================================================#
20 sashby 1.2
21 sashby 1.29 # Verbose mode:
22 sashby 1.31 &local_verbose("MAIN");
23 sashby 1.29
24 sashby 1.19 $main::bold = "";
25     $main::normal = "";
26     $main::line = "-"x80;
27     $main::lookupobject = "";
28 sashby 1.15
29 sashby 1.10 # Test whether the output from SCRAM is being redirected, or
30     # not (prevents escape signals from being printed to STDOUT if
31 sashby 1.25 # STDOUT is redirected to a file or piped):
32 sashby 1.11 if ( -t STDIN && -t STDOUT )
33     {
34     $bold = "\033[1m";
35     $normal = "\033[0m";
36     }
37    
38 sashby 1.2 # Allowed main and dev commands:
39 sashby 1.13 @allowed_commands=qw(project build install version list remove arch setup runtime setroot db tool url);
40 sashby 1.18 @dev_cmds=qw(devtest devint align);
41 hpw 1.1
42 sashby 1.2 # Check for prerequisites:
43     prerequisitecheck();
44     # Check for version consistency:
45 hpw 1.1 versioncheck();
46    
47 sashby 1.28
48 sashby 1.2 # Parse arguments (look for "-verbose" or "-arch" then shift):
49     while ( $ARGV[0] =~ /^-/)
50     {
51     if ( $ARGV[0] eq "-verbose" )
52     {
53 sashby 1.27 # Enable verbose for main as well, by default when -verbose mode selected:
54     $ENV{'SCRAMDEBUG'} = 1;
55 sashby 1.2 shift @ARGV;
56     # If no argument (i.e. class to activate "verbose" for) do nothing:
57     if (defined ($ARGV[0]))
58     {
59 sashby 1.21 print "Verbose mode for $ARGV[0] switched ".$bold."ON".$normal."\n" ;
60 sashby 1.2 scrambasics()->classverbose($ARGV[0],1);
61     }
62     }
63     elsif ( $ARGV[0] eq "-arch" )
64     {
65     shift @ARGV;
66     $ENV{SCRAM_ARCH}=$ARGV[0];
67     scrambasics()->arch($ARGV[0]);
68     }
69     else
70     {
71 sashby 1.31 ReportError("Unknown option $ARGV[0]");
72 sashby 1.2 }
73     shift @ARGV;
74     }
75    
76     # Shift args to get input command:
77 hpw 1.1 $inputcmd=shift;
78     $found='false';
79     $rv=0;
80     $self={};
81    
82 sashby 1.2 # Check that input command is defined, and then
83     # run a scram subroutine for the command or show
84     # some help:
85     if ( $inputcmd ne "" )
86     {
87     foreach $command ( (@allowed_commands,@dev_cmds) )
88     {
89     if ( $command =~ /^$inputcmd/i)
90     {
91     # Deal with a help request
92     do
93     {
94     helpheader($command);
95     &{"help_".$command};
96     exit;
97     } if $ARGV[0] =~ /help/i;
98     $rv=&$command;
99     $found='true';
100     last;
101     }
102     }
103     }
104    
105     if ( ! ( $found =~ /true/ ) )
106     {
107     helpheader('Recognised Commands');
108     foreach $command ( @allowed_commands )
109     {
110     print " $bold scram ".$command.$normal."\n";
111     }
112     print "\n";
113     print "Help on individual commands available through\n\n";
114     print "$bold scram".$normal." command$bold help $normal\n\n";
115    
116     print "\nOptions:\n";
117     print "--------\n";
118     print $bold."-verbose ".$normal."Class : Activate the verbose ".
119     "function on the specified class";
120     print "\n\n";
121     print $bold."-arch ".$normal."architecture : Set the architecture id ".
122     "to that specified";
123     print "\n\n";
124     }
125 hpw 1.1
126 sashby 1.2 # Exit with exit status of subroutine
127     # that was executed in line 80:
128 hpw 1.1 exit $rv;
129 sashby 1.2
130    
131    
132    
133 sashby 1.21
134    
135    
136    
137    
138 sashby 1.2 ######################################################################################
139     ## Subroutine definitions ##
140     ######################################################################################
141    
142 sashby 1.31 sub ReportError
143 sashby 1.2 {
144     ###############################################################
145 sashby 1.31 # ReportError(string) #
146 sashby 1.2 ###############################################################
147     # modified : Mon May 28 11:26:47 2001 / SFA #
148     # params : Error messsage string #
149     # : #
150     # : #
151     # : #
152 sashby 1.31 # function : Exit with an error string. Print string to #
153     # : STDERR if using pipes. #
154 sashby 1.2 # : #
155     ###############################################################
156     my $string=shift;
157 sashby 1.31 &local_verbose("ReportError");
158 sashby 1.28
159 sashby 1.31 if ( -t STDERR ) # Make sure that errors go to STDERR
160     { # when using pipes
161     print STDERR "\n","SCRAM error: ".$string."\n";
162     }
163     else
164     {
165     print "\n","SCRAM error: ".$string."\n";
166     }
167 sashby 1.5 exit (1);
168 sashby 1.2 }
169    
170     sub prerequisitecheck
171     {
172     ###############################################################
173     # prerequisitecheck() #
174     ###############################################################
175     # modified : Mon May 28 11:26:52 2001 / SFA #
176     # params : None. #
177     # : #
178     # : #
179     # : #
180     # function : Check for prerequisite programs. #
181 sashby 1.9 # : Don't bother checking for shell: too much hassle.#
182     # : (and doesn't work outside of HEPiX scheme) #
183 sashby 1.2 ###############################################################
184     my $reqdmake="gmake";
185 sashby 1.31 &local_verbose("prerequisitecheck");
186 sashby 1.38
187     # We must have gmake. Check this or exit if no gmake:
188     my $gmake_version_info=`$reqdmake -v`;
189     if ( $? == 0 )
190 sashby 1.2 {
191     return (0);
192     }
193     else
194     {
195     print "It appears that you do not have all prerequisite","\n";
196     print "programs. To run SCRAM, you must have:","\n";
197     print "\n";
198     print " - GNU make (gmake)","\n";
199     print "\n";
200 sashby 1.9 print "Please make sure that this program is present.","\n\n";
201 sashby 1.2 exit (1);
202     }
203     }
204    
205     sub versioncheck
206     {
207     ###############################################################
208     # versioncheck(version) #
209     ###############################################################
210     # modified : Mon May 28 11:27:06 2001 / SFA #
211     # params : version (optional) #
212     # : #
213     # : #
214     # : #
215     # function : Check for scram version info. #
216     # : #
217     # : #
218     ###############################################################
219     my $version;
220 sashby 1.31 &local_verbose("versioncheck");
221 sashby 1.2
222     if ( @_ )
223     {
224     $version=shift;
225     }
226     else
227     {
228     # -- get version from local area
229     if ( ! localtop_find() )
230     {
231 hpw 1.1 LoadEnvFile();
232     my $versionfile=$ENV{LOCALTOP}."/$ENV{projconfigdir}/scram_version";
233 sashby 1.2 if ( -f $versionfile )
234     {
235     open (VERSION, "<".$versionfile);
236 hpw 1.1 $version=<VERSION>;
237     chomp $version;
238 sashby 1.2 }
239 hpw 1.1 }
240 sashby 1.2 }
241     if ( defined $version )
242     {
243     scrambasics()->spawnversion($version,@ARGV);
244     }
245     }
246    
247    
248     sub _processcmds
249     {
250     ###############################################################
251     # _processcmds(handlercoderef,refarrayofallowedcommands, #
252     # refarrayofactualcommands, #
253     # arrayofsubroutinestringstocall) #
254     # #
255     ###############################################################
256     # modified : Mon May 28 11:27:12 2001 / SFA #
257     # params : #
258     # : #
259     # : #
260     # : #
261     # function : #
262     # : #
263     # : #
264     ###############################################################
265 sashby 1.31 &local_verbose("_processcmds");
266 sashby 1.28
267 sashby 1.2 my $optionhandler=shift;
268     my $allowed_commands=shift;
269     my $cmds=shift;
270     my @subs=@_;
271     my $found=0;
272 sashby 1.35 my $rv = 0;
273 sashby 1.2
274     # make a string from the subcommand levels
275     my $substring="";
276     if ( @subs )
277     {
278     $substring= join '_', @subs;
279     $substring=$substring."_";
280     }
281    
282     # Process options
283     if (defined ${$cmds}[0])
284     {
285     while ( ${$cmds}[0] =~ /^-/)
286     {
287     &{$optionhandler}( ${$cmds}[0],$cmds);
288     }
289 hpw 1.1
290 sashby 1.2 my $inputcmd=shift @{$cmds};
291     if ( $inputcmd ne "" )
292     {
293     foreach $command ( @{$allowed_commands} )
294     {
295     if ( $command =~ /^$inputcmd/i)
296     {
297     # Deal with a help request
298     if ( ( defined $$cmds[0]) && $$cmds[0] =~ /help/i )
299     {
300     &helpheader($command,@subs);
301     &{"help_".$substring.$command}; exit;
302     }
303     else
304     {
305 sashby 1.35 $rv=&{$substring.$command}(@{$cmds});
306 sashby 1.2 $found=1;
307     last;
308     }
309     }
310     }
311     }
312     }
313    
314     if ( ! $found )
315     {
316     &{$substring."error"}(@subs);
317 sashby 1.34 return (1);
318 hpw 1.1 }
319 sashby 1.35 # Return the status of the command subrtn executed:
320     return $rv;
321 sashby 1.2 }
322    
323    
324     sub help_build
325     {
326     ###############################################################
327     # help_build() #
328     ###############################################################
329     # modified : Mon May 28 11:27:23 2001 / SFA #
330     # params : #
331     # : #
332     # : #
333     # : #
334     # function : Show help for the scram build command #
335     # : #
336     # : #
337     ###############################################################
338 sashby 1.31 &local_verbose("help_build");
339 sashby 1.28
340 sashby 1.2 print <<ENDTEXT;
341     Information for building binaries and libraries.
342    
343     Subcommands:
344    
345     scram (b)uild lib/bin
346    
347     Command is run from the src directory.
348    
349     ENDTEXT
350 sashby 1.6 # Also run "build" dir because this will run "gmake help":
351     &build();
352 sashby 1.34 return (0);
353 sashby 1.2 }
354    
355    
356     sub align
357     {
358     ###############################################################
359     # align() #
360     ###############################################################
361     # modified : Mon May 28 11:27:27 2001 / SFA #
362     # params : #
363     # : #
364     # : #
365     # : #
366     # function : #
367     # : #
368     # : #
369     ###############################################################
370 sashby 1.31 &local_verbose("align");
371 sashby 1.2 _localarea()->align();
372     }
373    
374 sashby 1.49 sub build
375 sashby 1.2 {
376     ###############################################################
377     # build() #
378     ###############################################################
379     # modified : Mon May 28 11:27:34 2001 / SFA #
380     # params : #
381     # : #
382     # : #
383     # : #
384     # function : Compile project. #
385     # : #
386     # : #
387     ###############################################################
388 sashby 1.31 &local_verbose("build");
389 sashby 1.50
390 sashby 1.2 # is this a based or free release?
391     FullEnvInit();
392     use BuildSystem::BuildSetup;
393     $ENV{MAKETARGETS}=join ' ',@ARGV;
394 sashby 1.50
395 sashby 1.2 # -- set the runtime environment
396     my $toolrt=scrambasics()->toolruntime(_localarea());
397     $toolrt->sethash(\%Env);
398 sashby 1.50
399 sashby 1.2 # -- set up the builder
400     my $bs=BuildSystem::BuildSetup->new(toolbox());
401     $rv=$bs->BuildSetup($ENV{THISDIR},@ARGV);
402 sashby 1.34 return $rv;
403 sashby 1.2 }
404    
405 sashby 1.49 sub buildn
406 sashby 1.48 {
407     ###############################################################
408     # build() #
409     ###############################################################
410     # modified : Mon May 28 11:27:34 2001 / SFA #
411     # params : #
412     # : #
413     # : #
414     # : #
415     # function : Compile project. #
416     # : #
417 sashby 1.49 # : Currently NOT working properly....! #
418 sashby 1.48 ###############################################################
419     &local_verbose("build");
420     use BuildSystem::Build;
421     use BuildSystem::BuildSetup;
422    
423     # Init the environment:
424     FullEnvInit();
425     $ENV{MAKETARGETS}=join ' ',@ARGV;
426 sashby 1.50
427 sashby 1.48 # Set the runtime environment:
428     my $toolrt=scrambasics()->toolruntime(_localarea());
429     $toolrt->sethash(\%Env);
430    
431     # Set up the builder:
432     my $build = BuildSystem::Build->new(_localarea(),toolbox());
433    
434     # Invoke a build:
435     my $buildreport = $build->build($ENV{THISDIR}, @ARGV);
436 sashby 1.50
437 sashby 1.48 # Print the info from the build:
438     $buildreport->reportBuildStatus();
439     }
440    
441 sashby 1.2 sub project
442     {
443     ###############################################################
444     # project() #
445     ###############################################################
446     # modified : Mon May 28 11:27:38 2001 / SFA #
447     # params : #
448     # : #
449     # : #
450     # : #
451     # function : Set up a project area. #
452     # : #
453     # : #
454     ###############################################################
455 sashby 1.31 &local_verbose("project");
456 sashby 1.28
457 sashby 1.2 my @args=@ARGV;
458    
459     my $devareaname="";
460     use Cwd;
461     my $installarea=cwd();
462 sashby 1.19
463 sashby 1.2 # process options
464     while ( $args[0] =~ "^-" )
465     {
466     if ( $args[0] =~ /-n/ )
467     {
468     shift @args;
469     $devareaname=shift @args;
470     }
471     elsif ( $args[0] =~ /-d/ ) #installation area directory
472     {
473     shift @args;
474     $installarea=$args[0];
475     if ( ! -d $installarea )
476     {
477 sashby 1.31 ReportError("$installarea does not exist");
478 sashby 1.2 }
479     shift @args;
480     }
481     else
482     {
483 sashby 1.31 ReportError("Unknown option $args[0] to project command");
484 sashby 1.2 }
485     }
486 sashby 1.42
487 sashby 1.2 # -- check what arguments have been passed
488 sashby 1.42 if ( $#args <0 || $#args>3 )
489 sashby 1.2 {
490 sashby 1.31 ReportError("\"scram project help\" for usage info.");
491 sashby 1.2 }
492     my $area; #somewhere to store the area object when we have it
493    
494 sashby 1.42 if ( $args[0] =~ /:/ )
495     {
496     # Get the bootstrapfile:
497     my $bootstrapfile=shift @args;
498 sashby 1.2 # -- must be a url to bootstrap from
499 sashby 1.42 print "Bootstrapping using ",$bootstrapfile,"\n";
500     $area=scrambasics()->project($bootstrapfile, $installarea,
501 sashby 1.2 $devareaname);
502 sashby 1.42
503 sashby 1.21 # Need to set the sitename for the setup process:
504     if (defined ($area))
505     {
506 sashby 1.42 # Check for a config file argument:
507     my $flag=shift @args;
508     my $file=shift @args;
509    
510     # Make sure the extra flag is -f, followed by a valid filename:
511     if ( $flag =~ /-f/ )
512     {
513     # OK, flag is valid. Is there a filename arg given?:
514     if ( $file =~ /.*conf$/)
515     {
516     $ENV{LOCCMSTOOLS}=$file;
517     }
518     else
519     {
520     # The file doesn't look like a conf file:
521     ReportError("Invalid file given as arg to project command.");
522     }
523     }
524    
525 sashby 1.33 # We have an area so we can invoke method. First,
526     # establish our site name. See if there is an environment
527     # setting:
528     if ( ! $ENV{'SITENAME'})
529     {
530     $ENV{'SITENAME'} = $area->sitename();
531     }
532 sashby 1.22 $ENV{'PROJECTDIR'} = $area->location();
533 sashby 1.21 }
534 sashby 1.42 else
535     {
536     ReportError("No project area defined. Cannot continue.");
537     }
538 sashby 1.21
539 sashby 1.19 # Initialize the lookup table:
540     use Scram::AutoToolSetup;
541     $lookupobject = Scram::AutoToolSetup->new();
542 sashby 1.42
543     print "Setting up tools in project area","\n";
544 sashby 1.40
545 sashby 1.19 # Now run the full setup for the area:
546 sashby 1.2 scrambasics()->setuptoolsinarea($area);
547     }
548     elsif ( $#args >0 )
549     {
550     # -- get the release area
551     print "Getting release area....","\n";
552     my $relarea=scrambasics()->scramprojectdb()->getarea(@args);
553     if ( ! defined $relarea )
554     {
555 sashby 1.31 ReportError("Unknown project @args");
556 sashby 1.2 }
557    
558     # -- we need to spawn the correct scram version to handle it:
559     unshift @ARGV, "project";
560     print "Checking SCRAM version....","\n";
561     versioncheck($relarea->scramversion());
562 hpw 1.1
563 sashby 1.2 # -- need to create a satellite area:
564     print "Creating satellite area....","\n";
565     $area=scrambasics()->satellite(@args,$installarea, $devareaname);
566     }
567     else
568     {
569 sashby 1.31 ReportError("\"scram project help\" for usage info.");
570 sashby 1.2 }
571     #
572     # Now create the directories specified in the interface
573     # There should be some better mechanism - TODO
574     #
575     print "Creating directories....","\n";
576     chdir $area->location();
577     foreach $key ( keys %ENV )
578     {
579     if ( $key =~ /^INT/ )
580     {
581     AddDir::adddir($ENV{$key});
582     }
583     }
584 sashby 1.5 # Final message
585 sashby 1.2 print "\n\nInstallation procedure complete.\n";
586     print "Installation Located at:\n\n\t\t".$bold.$area->location().$normal."\n\n";
587 sashby 1.34 return(0);
588 sashby 1.2 }
589    
590    
591     sub scrambasics
592     {
593     ###############################################################
594     # scrambasics() #
595     ###############################################################
596     # modified : Mon May 28 11:27:44 2001 / SFA #
597     # params : #
598     # : #
599     # : #
600     # : #
601     # function : #
602     # : #
603     # : #
604     ###############################################################
605 sashby 1.31 &local_verbose("scrambasics");
606 sashby 1.28
607 sashby 1.2 require Scram::ScramFunctions;
608     if ( ! defined $scramobj )
609     {
610     environmentinit();
611     $scramobj=Scram::ScramFunctions->new();
612     $scramobj->arch($ENV{SCRAM_ARCH});
613     }
614     return $scramobj;
615     }
616    
617     sub url
618     {
619     ###############################################################
620     # url() #
621     ###############################################################
622     # modified : Mon May 28 11:27:48 2001 / SFA #
623     # params : #
624     # : #
625     # : #
626     # : #
627     # function : #
628     # : #
629     # : #
630     ###############################################################
631 sashby 1.31 &local_verbose("url");
632 sashby 1.28
633 sashby 1.2 @_=@ARGV;
634     localtop();
635     environmentinit();
636     my @allowed_cmds=qw(get);
637 sashby 1.34 my $rv=_processcmds("_tooloptions", \@allowed_cmds, \@_, ("url"));
638     return $rv;
639 sashby 1.2 }
640    
641     sub url_get
642     {
643     ###############################################################
644     # url_get() #
645     ###############################################################
646     # modified : Mon May 28 11:27:52 2001 / SFA #
647     # params : #
648     # : #
649     # : #
650     # : #
651     # function : #
652     # : #
653     # : #
654     ###############################################################
655 sashby 1.31 &local_verbose("url_get");
656 sashby 1.28
657 sashby 1.2 my $url=shift;
658     my $area=_localarea();
659    
660     ($uurl,$file)=scrambasics()->webget($area,$url);
661 sashby 1.34 print "$file\n";
662     return (0);
663 sashby 1.2 }
664 hpw 1.1
665 sashby 1.2 sub help_url
666     {
667     ###############################################################
668     # help_url() #
669     ###############################################################
670     # modified : Mon May 28 11:28:06 2001 / SFA #
671     # params : #
672     # : #
673     # : #
674     # : #
675     # function : Show help for the scram url command. #
676     # : #
677     # : #
678     ###############################################################
679 sashby 1.31 &local_verbose("help_url");
680 sashby 1.28
681 sashby 1.2 print <<ENDTEXT;
682 hpw 1.1 URL information.
683 sashby 1.2
684     Subcommands:
685    
686 hpw 1.1 scram url get
687    
688     ENDTEXT
689 sashby 1.34 return (0);
690 sashby 1.2 }
691 hpw 1.1
692 sashby 1.2 sub help_url_get
693     {
694     ###############################################################
695     # help_url_get() #
696     ###############################################################
697     # modified : Mon May 28 11:28:11 2001 / SFA #
698     # params : #
699     # : #
700     # : #
701     # : #
702     # function : Show help for the scram url get command. #
703     # : #
704     # : #
705     ###############################################################
706 sashby 1.31 &local_verbose("help_url_get");
707 sashby 1.28
708 sashby 1.2 print <<ENDTEXT;
709 hpw 1.1 Description:
710     Return the location of the local copy of the specified url
711     Usage :
712     scram url get url
713    
714     ENDTEXT
715 sashby 1.34 return (0);
716 sashby 1.2 }
717 hpw 1.1
718     # ------------ tool command --------------------------------------------
719 sashby 1.2 sub tool
720     {
721     ###############################################################
722     # tool() #
723     ###############################################################
724     # modified : Mon May 28 11:28:16 2001 / SFA #
725     # params : #
726     # : #
727     # : #
728     # : #
729     # function : #
730     # : #
731     # : #
732     ###############################################################
733 sashby 1.31 &local_verbose("tool");
734 sashby 1.28
735 sashby 1.2 @_=@ARGV;
736     localtop();
737     environmentinit();
738 sashby 1.40 my @allowed_cmds=qw(info list default setup tag remove);
739 sashby 1.34 my $rv=_processcmds("_tooloptions", \@allowed_cmds, \@_, ("tool"));
740     return $rv;
741 sashby 1.2 }
742    
743     sub tool_error
744     {
745     ###############################################################
746     # tool_error(error_string) #
747     ###############################################################
748     # modified : Mon May 28 11:28:20 2001 / SFA #
749     # params : Error message string. #
750     # : #
751     # : #
752     # : #
753     # function : Show an error message for tool command. #
754     # : #
755     # : #
756     ###############################################################
757 sashby 1.31 &local_verbose("tool_error");
758 sashby 1.28
759 sashby 1.31 ReportError("Unknown tool subcommand : @_");
760 sashby 1.2 }
761    
762     sub tool_default
763     {
764     ###############################################################
765     # tool_default() #
766     ###############################################################
767     # modified : Mon May 28 11:28:24 2001 / SFA #
768     # params : #
769     # : #
770     # : #
771     # : #
772     # function : #
773     # : #
774     # : #
775     ###############################################################
776 sashby 1.31 &local_verbose("tool_default");
777 sashby 1.28
778 sashby 1.2 if ( $#_ != 1 )
779     {
780 sashby 1.31 ReportError("\"scram tool default help\" for usage information");
781 sashby 1.2 }
782     my $tool=shift;
783     my $version=shift;
784     print "Setting default version of $tool to $version\n";
785     # -- adjust the toolbox
786     toolbox()->setdefault($tool,$version);
787 sashby 1.34 return (0);
788 sashby 1.2 }
789    
790     sub tool_list
791     {
792     ###############################################################
793     # tool_list() #
794     ###############################################################
795     # modified : Mon May 28 11:28:27 2001 / SFA #
796     # params : #
797     # : #
798     # : #
799     # : #
800     # function : List the tools defined in toolbox. #
801     # : #
802     # : #
803     ###############################################################
804 sashby 1.31 &local_verbose("tool_list");
805 sashby 1.28
806 sashby 1.2 my $area=_localarea();
807     my $locationstring="Tool list for location ".$area->location();
808     my $length=length($locationstring);
809    
810 sashby 1.14 print "\n",$locationstring,"\n";
811 sashby 1.2 print "+"x $length;
812     print "\n";
813     print "\n";
814    
815     foreach $t ( toolbox()->tools() )
816     {
817     my $vers=join / /, toolbox()->versions($t);
818 sashby 1.14 print " ".$t." ".$vers." (default=".toolbox()->defaultversion($t).")\n";
819 sashby 1.2 }
820 sashby 1.14 print "\n";
821 sashby 1.34 return (0);
822 sashby 1.2 }
823    
824     sub tool_info
825     {
826     ###############################################################
827     # tool_info() #
828     ###############################################################
829     # modified : Mon May 28 11:28:30 2001 / SFA #
830     # params : #
831     # : #
832     # : #
833     # : #
834     # function : Show info for available tools. #
835     # : #
836     # : #
837     ###############################################################
838 sashby 1.31 &local_verbose("tool_info");
839 sashby 1.28
840 sashby 1.2 my $project=shift;
841     my $area=_localarea();
842     my $locationstring="Tool info as configured in location ".$area->location();
843     my $length=length($locationstring);
844 sashby 1.35 my $rv=0;
845 sashby 1.2
846     print $locationstring,"\n";
847     print "+"x $length;
848     print "\n";
849     print "\n";
850    
851     my @tools=toolbox()->gettool($project,@_);
852 sashby 1.32
853 sashby 1.2 foreach $t ( @tools )
854     {
855     if ( defined $t )
856     {
857     print "Name : ".$t->name();
858     print "\n";
859     print "Version : ".$t->version();
860     print "\n";
861     print "Docfile : ".$t->url();
862     print "\n";
863     print "+"x20;
864     print "\n";
865     @features=$t->features();
866     foreach $ft ( @features )
867     {
868     @vals=$t->getfeature($ft);
869     foreach $v ( @vals )
870     {
871 hpw 1.1 print $ft. "=$v\n";
872 sashby 1.2 }
873     }
874     }
875 sashby 1.8 else
876     {
877     print "Tool $t is not defined for this project area.","\n";
878 sashby 1.35 $rv=1;
879 sashby 1.8 }
880 sashby 1.2 }
881 sashby 1.35 return $rv;
882 sashby 1.2 }
883 hpw 1.1
884 sashby 1.32 sub tool_tag
885     {
886     ###############################################################
887     # tool_tag() #
888     ###############################################################
889     # modified : Mon May 28 11:28:30 2001 / SFA #
890     # params : #
891     # : #
892     # : #
893     # : #
894     # function : Show value of tool tag <tagname>. #
895     # : #
896     # : #
897     ###############################################################
898     &local_verbose("tool_tag");
899    
900     my $toolname=shift;
901     chomp (my $tagname=shift);
902     my $area=_localarea();
903     my @tools=toolbox()->gettool($toolname,@_);
904    
905     foreach $t ( @tools )
906     {
907     # If we have a hash for this tool, proceed:
908     if ( defined $t )
909     {
910     # Get the features:
911     @features=$t->features();
912     # If a tag name was supplied then try to get the value,
913     # otherwise just display all tag+value pairs defined:
914     if ( defined $tagname )
915     {
916     foreach $feature (@features)
917     {
918     print $t->getfeature($feature),"\n" if ($feature eq $tagname);
919     }
920     }
921     else
922     {
923     # Loop over features:
924     foreach $ft ( @features )
925     {
926     @vals=$t->getfeature($ft);
927     foreach $v ( @vals )
928     {
929     print $ft,"\n";
930     }
931     }
932     }
933     }
934     else
935     {
936 sashby 1.34 return (1);
937 sashby 1.32 }
938     }
939     }
940    
941 sashby 1.2 sub tool_setup
942     {
943     ###############################################################
944     # tool_setup() #
945     ###############################################################
946     # modified : Mon May 28 11:28:35 2001 / SFA #
947     # params : #
948     # : #
949     # : #
950     # : #
951     # function : #
952     # : #
953     # : #
954     ###############################################################
955 sashby 1.31 &local_verbose("tool_setup");
956 sashby 1.2 print "Please use scram setup command\n";
957 sashby 1.34 return (1);
958 sashby 1.2 }
959    
960 sashby 1.40 sub tool_remove
961     {
962     ###############################################################
963     # tool_remove() #
964     ###############################################################
965     # modified : Fri Apr 26 11:18:35 2002 / SFA #
966     # params : #
967     # : #
968     # : #
969     # : #
970     # function : Remove the tool from the project area. #
971     # : #
972     # : #
973     ###############################################################
974     &local_verbose("tool_remove");
975     my $tool_name = shift;
976     # Translate to lower case:
977     $tool_name =~ tr[A-Z][a-z];
978    
979     my $here=_localarea()->location();
980     my @tools_hash=toolbox()->gettool($tool_name,@_);
981     my $adminfile=$here."/.SCRAM/".$ENV{SCRAM_ARCH}."/admin";
982     my $newadminfile=$here."/.SCRAM/".$ENV{SCRAM_ARCH}."/admin.new";
983     my $foundtool=0;
984    
985     $lncount=0;
986    
987     if (defined $tools_hash[0]) # Check that the tool is defined in this area
988     {
989     my $tool_version=$tools_hash[0]->version();
990     print "\n";
991     my $toolstring=$tool_name."_".$tool_version;
992     print "Tool exists in project area ",$here,
993     "\n...removing ",$toolstring," from admin file:\n\n";
994     open (ADMIN, "<".$adminfile);
995     open (NEWADMIN, ">".$newadminfile);
996    
997     while (<ADMIN>)
998     {
999     # First we look for a line matching the tool name:
1000     if ($_ =~ /$tool_name/)
1001     {
1002     $foundtool=1;
1003     }
1004     # Once we have found the tool, check the next two lines for
1005     # matching version. End after the two version lines have been read:
1006     elsif (($foundtool == 1) && ($_ =~ /$tool_version/) && ($lncount < 2))
1007     {
1008     $lncount++;
1009     next;
1010     }
1011     else
1012     {
1013     # We write this to our new admin file:
1014     print NEWADMIN $_;
1015     }
1016     }
1017     close(ADMIN);
1018     close(NEWADMIN);
1019    
1020     # Rename the new admin file:
1021     rename($newadminfile, $adminfile) || ReportError("Unable to rename admin file.");
1022     # Create variables pointing to the files we're going to remove:
1023     my $tooldesc=$here."/.SCRAM/ToolFiles/".$toolstring;
1024     my $tooldat=$here."/.SCRAM/".$ENV{SCRAM_ARCH}."/".$toolstring.".dat";
1025    
1026     print "Removing ".$tooldesc."\n";
1027     # Remove the tool description:
1028     unlink($tooldesc) || ReportError("Unable to remove tool description file.");
1029     print "Removing ".$tooldat."\n";
1030     # Remove the dat file:
1031     unlink($tooldat) || ReportError("Unable to remove ".$toolstring.".dat file");
1032     print "..done.","\n";
1033     }
1034     else
1035     {
1036     ReportError("Tool \"".$tool_name."\" is not defined in this project area!\n");
1037     }
1038     return (0);
1039     }
1040    
1041 sashby 1.2 sub _tooloptions
1042     {
1043     ###############################################################
1044     # _tooloptions(error_string) #
1045     ###############################################################
1046     # modified : Mon May 28 11:28:38 2001 / SFA #
1047     # params : Error message string. #
1048     # : #
1049     # : #
1050     # : #
1051     # function : #
1052     # : #
1053     # : #
1054     ###############################################################
1055 sashby 1.31 &local_verbose("_tooloptions");
1056     ReportError("No Options defined for tool subcommand");
1057 sashby 1.2 }
1058    
1059     sub help_tool
1060     {
1061     ###############################################################
1062     # help_tool() #
1063     ###############################################################
1064     # modified : Mon May 28 11:28:41 2001 / SFA #
1065     # params : #
1066     # : #
1067     # : #
1068     # : #
1069     # function : Show help for tool command. #
1070     # : #
1071     # : #
1072     ###############################################################
1073 sashby 1.31 &local_verbose("help_tool");
1074 sashby 1.28
1075 sashby 1.2 print <<ENDTEXT;
1076 hpw 1.1 Manage the tools in the scram area that define the areas environment.
1077 sashby 1.40 Tool subcommands:
1078 sashby 1.2
1079 hpw 1.1 list
1080 sashby 1.40 info <tool_name>
1081     default <tool_name> <tool_version>
1082     tag <tool_name> <tag_name>
1083     remove <tool_name>
1084    
1085 hpw 1.1 ENDTEXT
1086 sashby 1.34 return (0);
1087 sashby 1.2 }
1088 hpw 1.1
1089 sashby 1.2 sub help_tool_info
1090     {
1091     ###############################################################
1092     # help_tool_info() #
1093     ###############################################################
1094     # modified : Mon May 28 11:28:45 2001 / SFA #
1095     # params : #
1096     # : #
1097     # : #
1098     # : #
1099     # function : Show help for tool info command. #
1100     # : #
1101     # : #
1102     ###############################################################
1103 sashby 1.31 &local_verbose("help_tool_info");
1104 sashby 1.28
1105 sashby 1.2 print <<ENDTEXT;
1106 hpw 1.1 Description:
1107     Print out information on the specified tool in the current area
1108     configuration.
1109     Usage :
1110     scram tool info tool_name [tool_version]
1111    
1112     ENDTEXT
1113 sashby 1.34 return (0);
1114 sashby 1.2 }
1115 hpw 1.1
1116 sashby 1.2 sub help_tool_list
1117     {
1118     ###############################################################
1119     # help_tool_list() #
1120     ###############################################################
1121     # modified : Mon May 28 11:28:50 2001 / SFA #
1122     # params : #
1123     # : #
1124     # : #
1125     # : #
1126     # function : Show help for tool info command. #
1127     # : #
1128     # : #
1129     ###############################################################
1130 sashby 1.31 &local_verbose("help_tool_list");
1131 sashby 1.28
1132 sashby 1.2 print <<ENDTEXT;
1133 hpw 1.1 Description:
1134     List of currently configured tools available in ther current scram
1135     area
1136     Usage :
1137     scram tool list
1138    
1139     ENDTEXT
1140 sashby 1.34 return (0);
1141 sashby 1.2 }
1142 hpw 1.1
1143 sashby 1.2 sub help_tool_default
1144     {
1145     ###############################################################
1146     # help_tool_default() #
1147     ###############################################################
1148     # modified : Mon May 28 11:28:54 2001 / SFA #
1149     # params : #
1150     # : #
1151     # : #
1152     # : #
1153     # function : #
1154     # : #
1155     # : #
1156     ###############################################################
1157 sashby 1.31 &local_verbose("help_tool_default");
1158 sashby 1.28
1159 sashby 1.2 print <<ENDTEXT;
1160 hpw 1.1 Description:
1161     Change the default version of a tool to be used in the area
1162     Usage :
1163     scram tool default tool_name tool_version
1164    
1165     ENDTEXT
1166 sashby 1.34 return (0);
1167 sashby 1.2 }
1168 sashby 1.32
1169    
1170     sub help_tool_tag
1171     {
1172     ###############################################################
1173     # help_tool_tag() #
1174     ###############################################################
1175     # modified : Mon May 28 11:28:45 2001 / SFA #
1176     # params : #
1177     # : #
1178     # : #
1179     # : #
1180     # function : Show help for tool tag command. #
1181     # : #
1182     # : #
1183     ###############################################################
1184     &local_verbose("help_tool_tag");
1185    
1186     print <<ENDTEXT;
1187     Description:
1188     Print out the value of a variable (tag) for the specified tool in the
1189 sashby 1.46 current area configuration. If no tag name is given, then all known tag
1190     names are printed to STDOUT.
1191 sashby 1.32 Usage :
1192 sashby 1.46 scram tool tag tool_name [tag_name]
1193 sashby 1.32
1194     ENDTEXT
1195 sashby 1.34 return (0);
1196 sashby 1.32 }
1197    
1198 sashby 1.40 sub help_tool_remove
1199     {
1200     ###############################################################
1201     # help_tool_remove() #
1202     ###############################################################
1203     # modified : #
1204     # params : #
1205     # : #
1206     # : #
1207     # : #
1208     # function : Show help for tool remove command. #
1209     # : #
1210     # : #
1211     ###############################################################
1212     &local_verbose("help_tool_remove");
1213    
1214     print <<ENDTEXT;
1215     Description:
1216     Remove the specified tool from the current project area
1217     Usage :
1218     scram tool remove tool_name
1219    
1220     ENDTEXT
1221     return (0);
1222     }
1223    
1224    
1225 hpw 1.1
1226     # ----------------------------------------------------------------------
1227 sashby 1.2 sub _requirements
1228     {
1229     ###############################################################
1230     # _requirements() #
1231     ###############################################################
1232     # modified : Mon May 28 11:28:59 2001 / SFA #
1233     # params : #
1234     # : #
1235     # : #
1236     # : #
1237     # function : #
1238     # : #
1239     # : #
1240     ###############################################################
1241 sashby 1.31 &local_verbose("_requirements");
1242 sashby 1.28
1243 sashby 1.2 if ( ! defined $reqsobj )
1244     {
1245     localtop();
1246     my $area=_localarea();
1247     scrambasics()->arearequirements($area);
1248     }
1249     return $reqsobj;
1250     }
1251    
1252     sub _allprojectinitsearcher
1253     {
1254     ###############################################################
1255     # _allprojectinitsearcher() #
1256     ###############################################################
1257     # modified : Mon May 28 11:29:03 2001 / SFA #
1258     # params : #
1259     # : #
1260     # : #
1261     # : #
1262     # function : #
1263     # : #
1264     # : #
1265     ###############################################################
1266 sashby 1.31 &local_verbose("_allprojectinitsearcher");
1267 sashby 1.28
1268 sashby 1.2 my $search=_projsearcher();
1269     foreach $proj ( _scramprojdb()->list() )
1270     {
1271     $search->addproject($$proj[0],$$proj[1]);
1272     }
1273     }
1274    
1275     sub _projsearcher
1276     {
1277     ###############################################################
1278     # _projsearcher() #
1279     ###############################################################
1280     # modified : Mon May 28 11:29:05 2001 / SFA #
1281     # params : #
1282     # : #
1283     # : #
1284     # : #
1285     # function : #
1286     # : #
1287     # : #
1288     ###############################################################
1289 sashby 1.31 &local_verbose("_projsearcher");
1290 sashby 1.28
1291 sashby 1.2 if ( ! defined $self->{projsearcher} )
1292     {
1293     require Scram::ProjectSearcher;
1294     $self->{projsearcher}=Scram::ProjectSearcher->new(_scramprojdb());
1295     }
1296     return $self->{projsearcher};
1297     }
1298    
1299     sub _scramprojdb
1300     {
1301     ###############################################################
1302     # _scramprodb() #
1303     ###############################################################
1304     # modified : Mon May 28 11:29:10 2001 / SFA #
1305     # params : #
1306     # : #
1307     # : #
1308     # : #
1309     # function : #
1310     # : #
1311     # : #
1312     ###############################################################
1313 sashby 1.31 &local_verbose("_scramprojdb");
1314 sashby 1.28
1315 sashby 1.2 return scrambasics()->scramprojectdb();
1316     }
1317    
1318     sub runtime
1319     {
1320     ###############################################################
1321     # runtime() #
1322     ###############################################################
1323     # modified : Mon May 28 11:29:13 2001 / SFA #
1324     # params : shell type (-sh for Bourne, -csh for C/tcsh) #
1325     # : #
1326     # : #
1327     # : #
1328     # function : Get/set runtime environment. #
1329     # : #
1330     # : #
1331     ###############################################################
1332 sashby 1.31 &local_verbose("runtime");
1333 sashby 1.28
1334 sashby 1.2 my $shell;
1335     require Runtime;
1336    
1337 sashby 1.35 # Exit unless we have some args:
1338     if ($ARGV[0] !~ "^-" ) {ReportError("Insufficient arguments. A shell must be given.\n")};
1339    
1340 sashby 1.2 # process options
1341     while ( $ARGV[0] =~ "^-" )
1342     {
1343     if ( $ARGV[0] =~ /-sh/ )
1344     {
1345     shift @ARGV;
1346     $shell="sh";
1347     next;
1348     }
1349     if ( $ARGV[0] =~ /-csh/ ) #installation area directory
1350     {
1351     shift @ARGV;
1352     $shell="csh";
1353     next;
1354     }
1355 sashby 1.31 ReportError("Unknown Option $ARGV[0]\n");
1356 sashby 1.2 }
1357 sashby 1.12
1358 sashby 1.2 FullEnvInit();
1359 sashby 1.12
1360 sashby 1.2 if ( @ARGV )
1361     {
1362     my $runtime=Runtime->new();
1363     my $arg=shift @ARGV;
1364    
1365     my $info=0;
1366     if ( $arg eq "info" )
1367     {
1368     $arg=shift @ARGV;
1369     $info=1;
1370     }
1371    
1372     # --- determine filename
1373     my $filename;
1374     if ( -f $arg ) # Is it a file?
1375     {
1376     $filename=$arg;
1377     }
1378     else
1379     {
1380     # -- lets see if its a BuildFile location
1381     $filename=_testfile($ENV{LOCALTOP}."/src/".$arg,
1382     $ENV{RELEASETOP}."/src/".$arg,
1383     $ENV{LOCALTOP}."/src/".$arg."/BuildFile",
1384     $ENV{RELEASETOP}."/src/".$arg."/BuildFile");
1385     if ( $filename eq "" )
1386     {
1387 sashby 1.31 ReportError("Unable to find a file (or BuildFile) relating to ".
1388     $arg."\n");
1389 sashby 1.2 }
1390     }
1391     $runtime->file($filename);
1392     if ( ! $info )
1393     {
1394     $runtime->printenv($shell);
1395     }
1396     else
1397     {
1398     if ( @ARGV ) #do we have a specific variable request?
1399     {
1400     _printvardoc($runtime,shift @ARGV);
1401     }
1402     else
1403     {
1404     foreach $var ( $runtime->list() )
1405     {
1406     _printvardoc($runtime,$var);
1407     }
1408     }
1409     }
1410     undef $runtime;
1411     }
1412     else
1413     {
1414     FullEnvInit();
1415     # -- We have to clean up from the last runtime cmd - use env history
1416     foreach $variable ( %ENV )
1417     {
1418     if ( $variable =~ /^SCRAMRT_(.*)/ ) #SCRAMRT are history retaining
1419     {
1420 hpw 1.1 my $var=$1;
1421 sashby 1.2 $ENV{$var} =~ s/\Q$ENV{$variable}\E//g;
1422     $ENV{$var} =~ s/^:*//; # Deal with any Path variables
1423 sashby 1.47 undef $ENV{$variable};
1424 sashby 1.2 }
1425     }
1426 hpw 1.1
1427 sashby 1.2 # -- get the tool runtime environments
1428     my $toolrt=scrambasics()->toolruntime(_localarea());
1429     $toolrt->sethash(\%EnvRuntime);
1430    
1431     # -- create new SCRAMRT history vars.
1432     foreach $variable ( keys %EnvRuntime )
1433     {
1434     printoutenv($shell,"SCRAMRT_$variable",$EnvRuntime{$variable});
1435     }
1436 hpw 1.1
1437 sashby 1.2 # TODO -- this stuff should dissappear with compiler description docs
1438     # Now adapt as necessary - include base environment as well
1439     if ( exists $ENV{LD_LIBRARY_PATH} )
1440     {
1441     addpath("LD_LIBRARY_PATH","$ENV{LD_LIBRARY_PATH}");
1442     }
1443     if ( exists $ENV{MANPATH} )
1444     {
1445     addpath("MANPATH","$ENV{MANPATH}");
1446     }
1447     addpath("PATH","$ENV{PATH}");
1448    
1449     # -- Print out as reqd
1450     # TODO -- we can use the runtime class method once we have removed
1451     # this stuff above
1452     foreach $variable ( keys %EnvRuntime )
1453     {
1454     printoutenv($shell,$variable,$EnvRuntime{$variable});
1455     }
1456 sashby 1.12
1457 sashby 1.30 # Export a copy of LOCALTOP, renamed as a new variable:
1458     printoutenv($shell,"LOCALRT",$ENV{LOCALTOP});
1459 sashby 1.2 }
1460 sashby 1.34 return (0);
1461 sashby 1.2 }
1462 hpw 1.1
1463     # Support rt for runtime
1464    
1465 sashby 1.2 sub _testfile
1466     {
1467     ###############################################################
1468     # _testfile() #
1469     ###############################################################
1470     # modified : Mon May 28 11:29:21 2001 / SFA #
1471     # params : #
1472     # : #
1473     # : #
1474     # : #
1475     # function : #
1476     # : #
1477     # : #
1478     ###############################################################
1479 sashby 1.31 &local_verbose("_testfile");
1480 sashby 1.28
1481 sashby 1.2 my @files=@_;
1482     my $filename="";
1483    
1484     foreach $file ( @files )
1485     {
1486     if ( -f $file )
1487     {
1488     $filename=$file;
1489     last;
1490     }
1491     }
1492     return $filename;
1493     }
1494    
1495     sub _printvardoc
1496     {
1497     ###############################################################
1498     # _printvardoc() #
1499     ###############################################################
1500     # modified : Mon May 28 11:29:25 2001 / SFA #
1501     # params : #
1502     # : #
1503     # : #
1504     # : #
1505     # function : #
1506     # : #
1507     # : #
1508     ###############################################################
1509 sashby 1.31 &local_verbose("_printvardoc");
1510 sashby 1.28
1511 sashby 1.2 my $runtime=shift;
1512     my $var=shift;
1513    
1514     print $var." :\n";
1515     print $runtime->doc($var);
1516     print "\n";
1517     }
1518    
1519     sub printoutenv
1520     {
1521     ###############################################################
1522     # printoutenv() #
1523     ###############################################################
1524     # modified : Mon May 28 11:29:28 2001 / SFA #
1525     # params : #
1526     # : #
1527     # : #
1528     # : #
1529     # function : #
1530     # : #
1531     # : #
1532     ###############################################################
1533 sashby 1.31 &local_verbose("printoutenv");
1534 sashby 1.28
1535 sashby 1.2 my $shell=shift;
1536     my $variable=shift;
1537     my $value=shift;
1538    
1539     if ( $shell eq "csh" )
1540     {
1541     print "setenv $variable \"$value\";\n";
1542     }
1543     elsif ( $shell eq "sh" )
1544     {
1545     print "$variable=\"$value\";\n";
1546     print "export $variable;\n";
1547     }
1548     }
1549    
1550     sub addpath
1551     {
1552     ###############################################################
1553     # addpath() #
1554     ###############################################################
1555     # modified : Mon May 28 11:29:32 2001 / SFA #
1556     # params : #
1557     # : #
1558     # : #
1559     # : #
1560     # function : #
1561     # : #
1562     # : #
1563     ###############################################################
1564 sashby 1.31 &local_verbose("addpath");
1565 sashby 1.28
1566 sashby 1.2 my $name=shift;
1567     my $val=shift;
1568    
1569     my $n;
1570     my @env;
1571     @env=split /:/, $EnvRuntime{$name};
1572     foreach $n ( (split /:/, $val ) )
1573     {
1574     if ( ! grep /^\Q$n\E$/, @env )
1575     {
1576     addvar($name,$n,":");
1577     }
1578     }
1579     }
1580 hpw 1.1
1581 sashby 1.2 sub addvar
1582     {
1583     ###############################################################
1584     # addvar() #
1585     ###############################################################
1586     # modified : Mon May 28 11:29:35 2001 / SFA #
1587     # params : #
1588     # : #
1589     # : #
1590     # : #
1591     # function : #
1592     # : #
1593     # : #
1594     ###############################################################
1595 sashby 1.31 &local_verbose("addvar");
1596 sashby 1.28
1597 sashby 1.2 my $name=shift;
1598     my $val=shift;
1599     my $sep=shift;
1600    
1601     if ( $val ne "" )
1602     {
1603     if ( defined $EnvRuntime{$name} )
1604     {
1605 hpw 1.1 $EnvRuntime{$name}=$EnvRuntime{$name}.$sep.$val;
1606 sashby 1.2 }
1607     else
1608     {
1609 hpw 1.1 $EnvRuntime{$name}=$val;
1610 sashby 1.2 }
1611     }
1612     }
1613    
1614     sub FullEnvInit
1615     {
1616     ###############################################################
1617     # FullEnvInit() #
1618     ###############################################################
1619     # modified : Mon May 28 11:29:38 2001 / SFA #
1620     # params : #
1621     # : #
1622     # : #
1623     # : #
1624     # function : #
1625     # : #
1626     # : #
1627     ###############################################################
1628 sashby 1.31 &local_verbose("FullEnvInit");
1629 sashby 1.28
1630 sashby 1.2 environmentinit();
1631     localtop();
1632     LoadEnvFile();
1633     }
1634    
1635     sub environmentinit
1636     {
1637     ###############################################################
1638     # environmentinit() #
1639     ###############################################################
1640     # modified : Mon May 28 11:29:41 2001 / SFA #
1641     # params : #
1642     # : #
1643     # : #
1644     # : #
1645     # function : Set the environment variables needed #
1646     # : by scram (arch, home etc.) #
1647     # : #
1648     ###############################################################
1649 sashby 1.31 &local_verbose("environmentinit");
1650 sashby 1.28
1651 sashby 1.2 use Utilities::setarchitecture;
1652 sashby 1.23
1653 sashby 1.2 my $name;
1654     my $value;
1655    
1656     $ENV{LatestBuildFile}=""; # stop recursive behaviour in make
1657 sashby 1.23
1658 sashby 1.2 if ( ! defined $ENV{SCRAM_ARCH} )
1659     {
1660     setarchitecture::setarch();
1661     }
1662     $ENV{INTwork}="tmp/$ENV{SCRAM_ARCH}";
1663     $ENV{INTsrc}="src";
1664     $ENV{INTlog}="logs";
1665     $ENV{INTlib}="lib/".$ENV{SCRAM_ARCH};
1666    
1667     ($ENV{SCRAM_BASEDIR}=$ENV{SCRAM_HOME}) =~ s/(.*)\/.*/$1/;
1668     if ( ! ( exists $ENV{SCRAM_CONFIG} ) )
1669     {
1670     $ENV{SCRAM_CONFIG}="$ENV{SCRAM_HOME}/configuration";
1671     }
1672     $ENV{TOOL_HOME}="$ENV{SCRAM_HOME}/src";
1673     if ( ! ( exists $ENV{SCRAM_LOOKUPDB} ) )
1674     {
1675     if ( -d "$ENV{SCRAM_BASEDIR}/scramdb/" )
1676     {
1677     $ENV{SCRAM_LOOKUPDB}="$ENV{SCRAM_BASEDIR}/scramdb/project.lookup";
1678     }
1679     else
1680     {
1681     $ENV{SCRAM_LOOKUPDB}="$ENV{SCRAM_CONFIG}/project.lookup";
1682     }
1683     }
1684     $ENV{SCRAM_AVAILDIRS}="";
1685     $ENV{SCRAM_AVAILFILES}="";
1686     }
1687    
1688     sub _localarea
1689     {
1690     ###############################################################
1691     # _localarea() #
1692     ###############################################################
1693     # modified : Mon May 28 11:29:47 2001 / SFA #
1694     # params : #
1695     # : #
1696     # : #
1697     # : #
1698     # function : #
1699     # : #
1700     # : #
1701     ###############################################################
1702 sashby 1.31 &local_verbose("_localarea");
1703 sashby 1.28
1704 sashby 1.2 if ( ! defined $self->{localarea} )
1705     {
1706     require Configuration::ConfigArea;
1707     $self->{localarea}=Configuration::ConfigArea->new();
1708     if ( ! defined $ENV{LOCALTOP} )
1709     {
1710     if ( $self->{localarea}->bootstrapfromlocation() )
1711     {
1712 hpw 1.1 # Were not in a local area
1713     undef $self->{localarea};
1714 sashby 1.2 }
1715     else
1716     {
1717     $self->{localarea}->archname(scrambasics()->arch());
1718     }
1719     }
1720     else
1721     {
1722     $self->{localarea}->bootstrapfromlocation($ENV{LOCALTOP});
1723     }
1724     }
1725     return $self->{localarea};
1726     }
1727    
1728     sub localtop_find
1729     {
1730     ###############################################################
1731     # localtop_find() #
1732     ###############################################################
1733     # modified : Mon May 28 11:29:50 2001 / SFA #
1734     # params : #
1735     # : #
1736     # : #
1737     # : #
1738     # function : #
1739     # : #
1740     # : #
1741     ###############################################################
1742 sashby 1.31 &local_verbose("localtop_find");
1743 sashby 1.28
1744 sashby 1.2 my $rv=1;
1745     if ( defined _localarea())
1746     {
1747     $rv=0;
1748     $ENV{LOCALTOP}=_localarea()->location();
1749     }
1750     return $rv;
1751     }
1752    
1753     sub localtop
1754     {
1755     ###############################################################
1756     # localtop() #
1757     ###############################################################
1758     # modified : Mon May 28 11:29:54 2001 / SFA #
1759     # params : #
1760     # : #
1761     # : #
1762     # : #
1763 sashby 1.5 # function : Find the top directory of local release area. #
1764 sashby 1.2 # : #
1765     # : #
1766     ###############################################################
1767 sashby 1.31 &local_verbose("localtop");
1768 sashby 1.28
1769 sashby 1.2 localtop_find();
1770 sashby 1.30
1771     # localtop_find() should set the variable LOCALTOP if we're
1772     # in a project area. This behaviour should take precedence.
1773     if ( defined ($ENV{LOCALTOP}))
1774     {
1775     # We're in a project area. Do whatever is necessary:
1776     ($ENV{THISDIR}=cwd) =~ s/^\Q$ENV{LOCALTOP}\L//;
1777     }
1778     else
1779 sashby 1.2 {
1780 sashby 1.30 # Not in a project area. See if we've used "setroot" to set
1781     # LOCALRT. If so, use that as LOCALTOP, otherwise say goodbye:
1782     if ( defined ($ENV{'LOCALRT'}))
1783     {
1784     $ENV{LOCALTOP} = $ENV{'LOCALRT'};
1785     ($ENV{THISDIR}=cwd) =~ s/^\Q$ENV{LOCALTOP}\L//;
1786     }
1787     else
1788     {
1789 sashby 1.31 ReportError("Unable to locate the top of local release. Exitting.\n");
1790 sashby 1.30 }
1791 sashby 1.2 }
1792     $ENV{THISDIR} =~ s/^\///;
1793     }
1794    
1795     sub LoadEnvFile
1796     {
1797     ###############################################################
1798     # LoadEnvFile() #
1799     ###############################################################
1800     # modified : Mon May 28 11:29:58 2001 / SFA #
1801     # params : #
1802     # : #
1803     # : #
1804     # : #
1805     # function : #
1806     # : #
1807     # : #
1808     ###############################################################
1809 sashby 1.31 &local_verbose("LoadEnvFile");
1810 sashby 1.28
1811 sashby 1.2 _localarea()->copyenv(\%ENV);
1812     }
1813    
1814     sub env
1815     {
1816     ###############################################################
1817     # env() #
1818     ###############################################################
1819     # modified : Mon May 28 11:30:00 2001 / SFA #
1820     # params : #
1821     # : #
1822     # : #
1823     # : #
1824     # function : #
1825     # : #
1826     # : #
1827     ###############################################################
1828 sashby 1.31 &local_verbose("env");
1829 sashby 1.28
1830 hpw 1.1 print "Sorry - Not yet\n";
1831 sashby 1.2 }
1832 hpw 1.1
1833 sashby 1.2 sub devint
1834     {
1835     ###############################################################
1836     # devint() #
1837     ###############################################################
1838     # modified : Mon May 28 11:30:03 2001 / SFA #
1839     # params : #
1840     # : #
1841     # : #
1842     # : #
1843     # function : #
1844     # : #
1845     # : #
1846     ###############################################################
1847 sashby 1.31 &local_verbose("devint");
1848 sashby 1.28
1849 sashby 1.2 my $class=shift @ARGV;
1850     scrambasics()->scramobjectinterface($class);
1851     }
1852    
1853     sub devtest
1854     {
1855     ###############################################################
1856     # devtest() #
1857     ###############################################################
1858     # modified : Mon May 28 11:30:06 2001 / SFA #
1859     # params : #
1860     # : #
1861     # : #
1862     # : #
1863     # function : #
1864     # : #
1865     # : #
1866     ###############################################################
1867 sashby 1.31 &local_verbose("devtest");
1868 sashby 1.28
1869 sashby 1.2 require Utilities::TestClass;
1870     my $class=shift @ARGV;
1871    
1872     my $tester;
1873     my $path;
1874    
1875     if ( $class =~ /::/ )
1876     {
1877     ($path=$class) =~ s/(.*)::.*/$1/;
1878     }
1879     $tester=Utilities::TestClass->new($class,
1880     "$ENV{SCRAM_HOME}/src/$path/test/testdata");
1881     $tester->dotest(@_);
1882     }
1883 hpw 1.1
1884     #
1885     # Create a lookup tag in the site database
1886     #
1887 sashby 1.2 sub install
1888     {
1889     ###############################################################
1890     # install() #
1891     ###############################################################
1892     # modified : Mon May 28 11:30:09 2001 / SFA #
1893     # params : #
1894     # : #
1895     # : #
1896     # : #
1897     # function : Install a project. Updates project.lookup #
1898     # : files found in /scramdb. #
1899     # : #
1900     ###############################################################
1901 sashby 1.31 &local_verbose("install");
1902 sashby 1.28
1903 sashby 1.2 localtop();
1904    
1905     scrambasics()->addareatoDB(_localarea(),@ARGV);
1906     _localarea()->align();
1907 sashby 1.34 return (0);
1908 sashby 1.2 }
1909    
1910     sub help_install()
1911     {
1912     ###############################################################
1913     # help_install() #
1914     ###############################################################
1915     # modified : Mon May 28 11:30:12 2001 / SFA #
1916     # params : #
1917     # : #
1918     # : #
1919     # : #
1920 sashby 1.28 # function : Show help for the install command. #
1921 sashby 1.2 # : #
1922     # : #
1923     ###############################################################
1924 sashby 1.31 &local_verbose("help_install");
1925 sashby 1.28
1926 sashby 1.2 print <<ENDTEXT;
1927 hpw 1.1 Associates a label with the current release in the SCRAM database.
1928     This allows other users to refer to a centrally installed project by
1929     this label rather than a remote url reference.
1930    
1931     Usage:
1932    
1933     $bold scram install $normal [project_tag [version_tag]]
1934    
1935 sashby 1.46 project_tag : override default label (the project name of the current release)
1936 hpw 1.1 version_tag : the version tag of the current release. If version is not
1937     specified the base release version will be taken by default.
1938    
1939     ENDTEXT
1940 sashby 1.34 return (0);
1941 sashby 1.2 }
1942 hpw 1.1
1943 sashby 1.2 sub helpheader ($label)
1944     {
1945     ###############################################################
1946     # helpheader(label) #
1947     ###############################################################
1948     # modified : Mon May 28 11:30:17 2001 / SFA #
1949     # params : label for the header. #
1950     # : #
1951     # : #
1952     # : #
1953     # function : Prints a header for the help command of #
1954     # : scram command "label". #
1955     # : #
1956     ###############################################################
1957 sashby 1.31 &local_verbose("helpheader");
1958 sashby 1.28
1959 sashby 1.2 my $label=shift;
1960    
1961     print <<ENDTEXT;
1962    
1963 hpw 1.1 *************************************************************************
1964 sashby 1.2 SCRAM HELP --------- $label
1965 hpw 1.1 *************************************************************************
1966 sashby 1.2
1967 hpw 1.1 ENDTEXT
1968 sashby 1.34 return (0);
1969 sashby 1.2 }
1970 hpw 1.1
1971 sashby 1.2 sub version
1972     {
1973     ###############################################################
1974     # version() #
1975     ###############################################################
1976     # modified : Mon May 28 11:30:24 2001 / SFA #
1977     # params : #
1978     # : #
1979     # : #
1980     # : #
1981     # function : Get the version of scram being used. #
1982     # : #
1983     # : #
1984     ###############################################################
1985 sashby 1.31 &local_verbose("version");
1986 sashby 1.28
1987 sashby 1.2 my $version=shift @ARGV;
1988     my $thisversion;
1989     my $scram_top;
1990     my $cvsobject;
1991    
1992     ($thisversion=$ENV{SCRAM_HOME}) =~ s/(.*)\///;
1993     $scram_top=$1;
1994     if ( $version eq "" )
1995     {
1996     print "$thisversion";
1997     # deal with links
1998     $version=readlink $ENV{SCRAM_HOME};
1999     if ( defined $version)
2000     {
2001     print " ---> $version";
2002     }
2003     print "\n";
2004     }
2005     else
2006     {
2007     if ( -d $scram_top."/".$version )
2008     {
2009     print "Version $version exists\n";
2010     }
2011     else
2012     {
2013     print "Version $version not available locally\n";
2014     print "Attempting download from the SCRAM repository\n";
2015     # set up and configure the cvs module for SCRAM
2016     require Utilities::CVSmodule;
2017     $cvsobject=Utilities::CVSmodule->new();
2018 sashby 1.51 # This will need to be changed to make it more generic:
2019 sashby 1.2 $cvsobject->set_base(
2020     "cmscvs.cern.ch:/cvs_server/repositories/SCRAM");
2021     $cvsobject->set_auth("pserver");
2022     $cvsobject->set_user("anonymous");
2023     $cvsobject->set_passkey("AA_:yZZ3e");
2024     # Now check it out in the right place
2025     chdir $scram_top or die "Unable to change to $scram_top $!\n";
2026     $cvsobject->invokecvs( ( split / /,
2027     "co -d $version -r $version SCRAM" ));
2028 hpw 1.1
2029 sashby 1.51 # Get rid of cvs object now we've finished
2030 sashby 1.2 $cvsobject=undef;
2031     print "\n";
2032     }
2033     }
2034 sashby 1.34 return (0);
2035 sashby 1.2 }
2036    
2037     sub list
2038     {
2039     ###############################################################
2040     # list() #
2041     ###############################################################
2042     # modified : Mon May 28 11:30:28 2001 / SFA #
2043     # params : #
2044     # : #
2045     # : #
2046     # : #
2047     # function : List available projects. #
2048     # : #
2049     # : #
2050     ###############################################################
2051 sashby 1.31 &local_verbose("list");
2052 sashby 1.2 &environmentinit;
2053    
2054     my $linebold = "$bold"."$line"."$normal";
2055     my $pjname = "Project Name";
2056     my $pjversion = "Project Version";
2057     my $pjlocation = "Project Location";
2058 sashby 1.5 my $headstring = sprintf("| %-12s | %-24s | %-33s |",$pjname,$pjversion,$pjlocation);
2059 sashby 1.2
2060     if ( ! -f $ENV{SCRAM_LOOKUPDB} )
2061     {
2062 sashby 1.31 ReportError
2063     ("\nNo installation database available - perhaps no projects\nhave been installed locally?\n");
2064 sashby 1.2 }
2065 sashby 1.4 print "\n","Listing installed projects....","\n\n";
2066 sashby 1.2 print $linebold,"\n";
2067     print $headstring."\n";
2068     print $linebold,"\n\n";
2069     listDB(@ARGV);
2070     print "\n";
2071 sashby 1.34 return (0);
2072 sashby 1.2 }
2073    
2074    
2075     sub remove
2076     {
2077     ###############################################################
2078     # remove(project) #
2079     ###############################################################
2080     # modified : Mon May 28 11:30:31 2001 / SFA #
2081 sashby 1.5 # params : project name, project version #
2082 sashby 1.2 # : #
2083     # : #
2084     # : #
2085     # function : Remove the named project from the project.lookup #
2086     # : file (scram database). #
2087     # : #
2088 sashby 1.28 ###############################################################
2089 sashby 1.31 &local_verbose("remove");
2090 sashby 1.28
2091 sashby 1.5 my $projectname=shift @ARGV;
2092     my $projectversion=shift @ARGV;
2093    
2094     # Check there were sufficient args:
2095     if ($projectname eq "" || $projectversion eq "")
2096     {
2097 sashby 1.31 ReportError("\"scram remove help\" for usage info.");
2098 sashby 1.5 }
2099     else
2100     {
2101     scrambasics()->removeareafromDB($projectname,$projectversion);
2102     }
2103 sashby 1.34 return (0);
2104 sashby 1.2 }
2105    
2106     sub db
2107     {
2108     ###############################################################
2109     # db() #
2110     ###############################################################
2111     # modified : Mon May 28 11:30:35 2001 / SFA #
2112 sashby 1.5 # params : "link", "unlink" or "show(links )" #
2113 sashby 1.2 # : #
2114     # : #
2115     # : #
2116     # function : Show project info stored in scramdb. Link/unlink #
2117     # : project database files, or show linked databases.#
2118     # : #
2119     ###############################################################
2120 sashby 1.31 &local_verbose("db");
2121 sashby 1.28
2122 sashby 1.2 my $subcmd=shift @ARGV;
2123 sashby 1.37 my $db=shift @ARGV;
2124    
2125 sashby 1.2 # Make sure we have an argument, or tell the user:
2126     if ( ! defined($subcmd))
2127     {
2128     &help_db;
2129     print "\n";
2130     exit (1);
2131     }
2132 sashby 1.37
2133     # If there is a file arg, test it to make sure it exists:
2134     if ( $subcmd eq 'link' ||
2135     $subcmd eq 'unlink' )
2136     {
2137     if ( -f $db )
2138     {
2139     print "Found DB file....",$db,"\n";
2140     }
2141     else
2142     {
2143     ReportError("Could not find a DB ".$db."\n");
2144     }
2145     }
2146 sashby 1.2 &environmentinit;
2147    
2148     # First, check for a database area:
2149     if ( ! -f $ENV{SCRAM_LOOKUPDB} )
2150     {
2151 sashby 1.31 ReportError
2152     ("\nNo installation database available - perhaps no projects\nhave been installed locally?\n");
2153 sashby 1.2 }
2154     print "\n","Current scram database: ";
2155     print $bold."$ENV{SCRAM_LOOKUPDB}".$normal."\n\n";
2156    
2157     switch :
2158     {
2159     if ( $subcmd eq 'link' )
2160     {
2161 sashby 1.37 scrambasics()->scramprojectdb()->link($db);
2162     print "\n","Linked ",$db," to current scram database.","\n\n";
2163 sashby 1.2 last switch;
2164     }
2165     if ( $subcmd eq 'unlink' )
2166     {
2167 sashby 1.37 scrambasics()->scramprojectdb()->unlink($db);
2168     print "\n","Unlinked ",$db," from current scram database.","\n\n";
2169 sashby 1.2 last switch;
2170     }
2171     if ( $subcmd eq 'showlinks'
2172     || $subcmd eq 'showlink'
2173     || $subcmd eq 'show')
2174     {
2175     my @links=scrambasics()->scramprojectdb()->listlinks();
2176     # Are there any links defined?:
2177     if ( defined($links[0]) )
2178     {
2179     print "\n","The following scram databases are linked to the current scram database: ","\n\n";
2180     foreach $link ( @links )
2181     {
2182     print " ".$link."\n";
2183     }
2184     print "\n";
2185     }
2186     else
2187     {
2188     print "There are no databases linked.","\n\n";
2189     }
2190     last switch;
2191     }
2192     } # end switch
2193 sashby 1.34 return (0);
2194 sashby 1.2 }
2195 hpw 1.1
2196 sashby 1.2 sub listDB
2197     {
2198     ###############################################################
2199     # listDB() #
2200     ###############################################################
2201     # modified : Mon May 28 11:30:39 2001 / SFA #
2202     # params : Project name #
2203     # : #
2204 sashby 1.4 # function : List projects. Only those projects that were #
2205     # : installed on the user's current OS will be #
2206     # : displayed (slight anomaly here: some projects #
2207     # : were installed on SunOS_5.6 so won't appear if #
2208     # : the user's current platform is SunOS_5.7...). #
2209 sashby 1.2 # : #
2210     ###############################################################
2211 sashby 1.31 &local_verbose("listDB");
2212 sashby 1.28
2213 sashby 1.2 my $project="";
2214 sashby 1.14 my $projectexists=0;
2215     my @missingareas;
2216    
2217 sashby 1.2 if ( @_ )
2218     {
2219     $project=shift;
2220     }
2221 sashby 1.5
2222 sashby 1.2 my @prs=scrambasics()->scramprojectdb()->listall();
2223 sashby 1.5
2224     # Check to see if there are any projects:
2225     if ( ! defined @prs )
2226     {
2227     print "\t\t>>>> No locally installed projects! <<<<","\n";
2228 sashby 1.34 return (1);
2229 sashby 1.5 }
2230 sashby 1.14
2231 sashby 1.5 # Iterate over the project list:
2232 sashby 1.2 foreach $pr ( @prs )
2233     {
2234 sashby 1.14 my $url='NULL';
2235    
2236 sashby 1.2 if ( $project eq "" || $project eq $$pr[0] )
2237     {
2238 sashby 1.14 # Check that the area exists (i.e. check that a configarea object
2239     # is returned before attempting to test its' location:
2240     my $possiblearea=scrambasics()->scramprojectdb()->getarea($$pr[0],$$pr[1]);
2241    
2242     if ( defined ($possiblearea))
2243 sashby 1.4 {
2244 sashby 1.14 $url=$possiblearea->location();
2245     if ($project eq $$pr[0]) {$projectexists=1};
2246     }
2247    
2248     # Check that the path to the project area is readable:
2249     if ( -d $url )
2250     {
2251     # Check that there exists an installation for
2252     # our current architecture. Check for a bin and
2253     # a lib directory:
2254     if ( -d "$url/bin/$ENV{SCRAM_ARCH}" || -d "$url/lib/$ENV{SCRAM_ARCH}" )
2255 sashby 1.12 {
2256     # Stagger the printed lines to allow easier
2257     # copying using the mouse:
2258     printf " %-15s %-25s \n",$$pr[0],$$pr[1];
2259     printf "%45s%-30s\n","--> ",$bold.$url.$normal;
2260     }
2261 sashby 1.14 }
2262     else
2263     {
2264     # We have an area that is unreadable. Push an entry onto the array:
2265     push @missingareas, sprintf ">> Project area MISSING: %-10s %-20s \n",$$pr[0],$$pr[1];
2266 sashby 1.4 }
2267 sashby 1.2 }
2268     }
2269 sashby 1.14
2270     if ( ! $projectexists && $project ne "" )
2271     {
2272     print "\t\t>>>> No locally installed $project projects! <<<<","\n";
2273 sashby 1.34 return(1);
2274 sashby 1.14 }
2275 sashby 1.31
2276     print "\n\n","Projects available for platform >> ".$bold."$ENV{SCRAM_ARCH}".$normal." <<\n";
2277     print "\n";
2278    
2279 sashby 1.14 # Print out a list of areas that are missing:
2280     if ( @missingareas )
2281     {
2282 sashby 1.31 ReportError(@missingareas);
2283 sashby 1.14 }
2284    
2285 sashby 1.31 # Otherwise exit nicely:
2286     return(0);
2287 sashby 1.2 }
2288    
2289     sub arch
2290     {
2291     ###############################################################
2292     # arch() #
2293     ###############################################################
2294     # modified : Mon May 28 11:30:41 2001 / SFA #
2295     # params : #
2296     # : #
2297     # : #
2298     # : #
2299     # function : Show the information about current architecture. #
2300     # : #
2301     # : #
2302     ###############################################################
2303 sashby 1.31 &local_verbose("arch");
2304 sashby 1.2 &environmentinit();
2305 sashby 1.10
2306     print "$ENV{SCRAM_ARCH}\n";
2307 sashby 1.34 return (0);
2308 sashby 1.2 }
2309 hpw 1.1
2310    
2311     #
2312     # Setup a new tool
2313     #
2314 sashby 1.2 sub setup
2315     {
2316 sashby 1.46 ###############################################################
2317     # setup #
2318     ###############################################################
2319     # modified : Tue May 21 12:40:24 2002 / SFA #
2320     # params : #
2321     # : #
2322     # : #
2323     # : #
2324     # function : setup tool box or a tool. #
2325     # : #
2326     # : #
2327     # : #
2328     ###############################################################
2329 sashby 1.2 my $interactive=0;
2330 sashby 1.43 my $toolsfile;
2331    
2332 sashby 1.2 # process options
2333     while ( $ARGV[0] =~ "^-" )
2334     {
2335     if ( $ARGV[0] =~ /-i/ )
2336     {
2337     shift @ARGV;
2338     $interactive=1;
2339 sashby 1.20 print "Running interactive setup....","\n";
2340 sashby 1.43 }
2341     elsif ( $ARGV[0] =~ /-f/ )
2342     {
2343     shift @ARGV;
2344     $toolsfile=$ARGV[0];
2345     if ($toolsfile =~ /\.conf$/ || -d $toolsfile) # File must end in ".conf" or be a dir...
2346     {
2347     # Set the location of the tools file:
2348     $ENV{LOCCMSTOOLS}=$toolsfile;
2349     }
2350     else
2351     {
2352     print "Expecting a tools file filename ( \"-f\" flag) but none given....","\n";
2353     print "Hint: the filename MUST end with \".conf\"","\n\n";
2354     }
2355     shift @ARGV;
2356     }
2357 sashby 1.2 else
2358     {
2359 sashby 1.31 ReportError("Unknown option $ARGV[0] to setup command");
2360 sashby 1.43 }
2361 sashby 1.2 }
2362 sashby 1.42
2363 sashby 1.2 localtop();
2364    
2365     my $area=_localarea();
2366 sashby 1.21 # We have a local area so we can invoke
2367 sashby 1.33 # method to get the sitename.
2368     # See if there is an environment setting:
2369     if ( ! $ENV{'SITENAME'})
2370     {
2371     $ENV{'SITENAME'} = $area->sitename();
2372     }
2373 sashby 1.22 $ENV{'PROJECTDIR'} = $area->location();
2374    
2375 sashby 1.2 my $toolname=shift @ARGV;
2376     my $insert=0;
2377 sashby 1.19
2378 sashby 1.2 toolbox()->interactive($interactive);
2379    
2380 sashby 1.20 # Initialize the lookup table:
2381     use Scram::AutoToolSetup;
2382     $lookupobject = Scram::AutoToolSetup->new();
2383 sashby 1.41
2384 sashby 1.2 # If no toolname specified then its a full setup
2385     if ( $toolname eq "" )
2386     {
2387     # -- add architecture specific directories
2388     use Utilities::AddDir;
2389 sashby 1.22 AddDir::adddir($ENV{'PROJECTDIR'}."/lib/$ENV{SCRAM_ARCH}");
2390     AddDir::adddir($ENV{'PROJECTDIR'}."/bin/$ENV{SCRAM_ARCH}");
2391 sashby 1.2 # -- check the releasetop area
2392     # if the releasetop has the files copy them
2393     my $releaseobj=_releasearea();
2394     if ( $releaseobj->copysetup($ENV{LOCALTOP}) )
2395     {
2396     print "Doing Full Setup\n";
2397 sashby 1.20 # Run the full setup for the area:
2398 sashby 1.2 scrambasics()->setuptoolsinarea($area);
2399     }
2400     }
2401     else
2402     {
2403 sashby 1.20 print "Running setup for tool ",$toolname,"...","\n";
2404 sashby 1.2 scrambasics()->setuptoolsinarea($area, $toolname,@ARGV);
2405     }
2406 sashby 1.34 return (0);
2407 sashby 1.2 }
2408 sashby 1.11
2409 sashby 1.12 sub setroot
2410     {
2411     ###############################################################
2412     # setroot #
2413     ###############################################################
2414     # modified : Wed Nov 7 16:22:25 2001 / SFA #
2415     # params : #
2416     # : #
2417     # : #
2418     # : #
2419     # function : #
2420     # : #
2421     # : #
2422     # : #
2423     ###############################################################
2424 sashby 1.31 &local_verbose("setroot");
2425 sashby 1.12 my $shell = shift @ARGV;
2426    
2427     # Check the shell argument...this must be supplied:
2428     if ($shell =~ "^-" )
2429     {
2430     # Remove the hyphen:
2431     $shell =~ s/-//;
2432 sashby 1.31 if ($shell ne "sh" && $shell ne "csh") {ReportError("No shell given! Exitting.");}
2433 sashby 1.12 }
2434     else
2435     {
2436 sashby 1.31 ReportError("No shell given! Exitting.");
2437 sashby 1.12 }
2438    
2439     my $projectname=shift @ARGV;
2440     my $projectversion=shift @ARGV;
2441    
2442     # Check there were sufficient args:
2443     if ($projectname eq "" || $projectversion eq "")
2444     {
2445 sashby 1.31 ReportError("\"scram setroot help\" for usage info.");
2446 sashby 1.12 }
2447     else
2448     {
2449 sashby 1.13 # And on we go. Let's find a release area for this project/version:
2450 sashby 1.12 my $releasearea = scrambasics()->scramprojectdb()->getarea($projectname,$projectversion);
2451 sashby 1.31 ReportError("No release area!!") if ( ! defined ($releasearea));
2452    
2453 sashby 1.12 # The info we need is stored in a hash and can be accessed using the key ENV.
2454 sashby 1.30 # If LOCALTOP is not defined, look for RELEASETOP:
2455     if ( ${${$releasearea}{'ENV'}}{'LOCALTOP'} eq '' )
2456 sashby 1.12 {
2457 sashby 1.30 if ( ${${$releasearea}{'ENV'}}{'RELEASETOP'} ne '' )
2458 sashby 1.12 {
2459 sashby 1.30 printoutenv($shell,"LOCALRT",${${$releasearea}{'ENV'}}{'RELEASETOP'});
2460 sashby 1.12 }
2461     }
2462 sashby 1.30 else
2463     # LOCALTOP is set so we can use it.
2464     # Set LOCALRT to LOCALTOP and return:
2465 sashby 1.12 {
2466 sashby 1.30 printoutenv($shell,"LOCALRT",${${$releasearea}{'ENV'}}{'LOCALTOP'});
2467 sashby 1.34 }
2468     }
2469     return (0);
2470 sashby 1.12 }
2471    
2472 sashby 1.2
2473     sub _releasearea
2474     {
2475     ###############################################################
2476     # _releasearea() #
2477     ###############################################################
2478     # modified : Mon May 28 11:30:50 2001 / SFA #
2479     # params : #
2480     # : #
2481     # : #
2482     # : #
2483     # function : #
2484     # : #
2485     # : #
2486     ###############################################################
2487 sashby 1.31 &local_verbose("_releasearea");
2488 sashby 1.28
2489 sashby 1.2 if ( !defined $self->{releasearea} )
2490     {
2491     require Configuration::ConfigArea;
2492     $self->{releasearea}=Configuration::ConfigArea->new();
2493     $self->{releasearea}->bootstrapfromlocation($ENV{RELEASETOP});
2494     }
2495     return $self->{releasearea};
2496     }
2497 hpw 1.1
2498     # get a toolbox object for the local area
2499 sashby 1.2 sub toolbox
2500     {
2501     ###############################################################
2502     # toolbox() #
2503     ###############################################################
2504     # modified : Mon May 28 11:30:53 2001 / SFA #
2505     # params : #
2506     # : #
2507     # : #
2508     # : #
2509     # function : #
2510     # : #
2511     # : #
2512     ###############################################################
2513 sashby 1.31 &local_verbose("toolbox");
2514 sashby 1.28
2515 sashby 1.2 if ( ! defined $toolbox )
2516     {
2517     localtop();
2518     my $area=_localarea();
2519     $toolbox=scrambasics()->areatoolbox($area);
2520     }
2521     return $toolbox;
2522     }
2523 sashby 1.27
2524    
2525     sub local_verbose
2526     {
2527     ###############################################################
2528     # local_verbose #
2529     ###############################################################
2530     # modified : Mon Jan 21 12:38:02 2002 / SFA #
2531     # params : Only debug env variable (switch) #
2532     # : #
2533     # : #
2534     # : #
2535     # function : Enable verbose mode for package "main" (i.e. #
2536     # : this wrapped script) #
2537     # : #
2538     # : #
2539     ###############################################################
2540     my $subroutine=shift;
2541 sashby 1.31
2542 sashby 1.28 if ($ENV{'SCRAMDEBUG'})
2543 sashby 1.30 {
2544     print "-------- [verbose mode]: subname >> ",$subroutine,"\n";
2545     }
2546     }
2547 sashby 1.2
2548     sub help_db
2549     {
2550     ###############################################################
2551     # help_db() #
2552     ###############################################################
2553     # modified : Mon May 28 11:30:56 2001 / SFA #
2554     # params : #
2555     # : #
2556     # : #
2557     # : #
2558     # function : Show help for scram db command. #
2559     # : #
2560     # : #
2561     ###############################################################
2562 sashby 1.31 &local_verbose("help_db");
2563 sashby 1.28
2564 sashby 1.2 print <<ENDTEXT;
2565 hpw 1.1 scram database administration command.
2566    
2567     Usage:
2568    
2569     $bold scram db $normal subcommand
2570    
2571 sashby 1.2 Subcommands:
2572    
2573 hpw 1.1 link :
2574     Make available an additional database for
2575     project and list operations
2576    
2577     $bold scram db link $normal /a/directory/path/project.lookup
2578    
2579     unlink :
2580     Remove a database from the link list. Note this does
2581     not remove the database, just the link to it in scram.
2582    
2583     $bold scram db unlink $normal /a/directory/path/project.lookup
2584    
2585     showlinks :
2586 sashby 1.46 List the databases that are linked in.
2587 hpw 1.1
2588     ENDTEXT
2589 sashby 1.34 return (0);
2590 sashby 1.2 }
2591 hpw 1.1
2592 sashby 1.2 sub help_setup
2593     {
2594     ###############################################################
2595     # help_setup() #
2596     ###############################################################
2597     # modified : Mon May 28 11:31:02 2001 / SFA #
2598     # params : #
2599     # : #
2600     # : #
2601     # : #
2602     # function : Show help for scram setup command. #
2603     # : #
2604     # : #
2605     ###############################################################
2606 sashby 1.31 &local_verbose("help_setup");
2607 sashby 1.28
2608 sashby 1.2 print <<ENDTEXT;
2609 hpw 1.1 Allows installation/re-installation of a new tool/external package into an
2610 sashby 1.46 already existing development area. If no toolname is specified,
2611 hpw 1.1 the complete installation process is initiated.
2612    
2613     Usage:
2614    
2615 sashby 1.43 $bold scram setup [-i] [-f cmstools.conf] $normal [toolname] [[version] [url]]
2616 hpw 1.1
2617     toolname : The name of the tool setup file required.
2618 sashby 1.46 version : where more than one version exists, specify the version.
2619     url : when setting up a completely new tool specify the url too.
2620 hpw 1.1
2621     The -i option turns off the automatic search mechanism allowing for more
2622 sashby 1.43 user interaction with the setup mechanism.
2623    
2624     The -f option allows the user to supply a valid path to a cmstools file (the filename
2625     MUST end in ".conf")
2626    
2627 hpw 1.1 ENDTEXT
2628 sashby 1.34 return (0);
2629 sashby 1.2 }
2630 hpw 1.1
2631 sashby 1.2 sub help_list
2632     {
2633     ###############################################################
2634     # help_list() #
2635     ###############################################################
2636     # modified : Mon May 28 11:31:09 2001 / SFA #
2637     # params : #
2638     # : #
2639     # : #
2640     # : #
2641     # function : Show help for scram list command. #
2642     # : #
2643     # : #
2644     ###############################################################
2645 sashby 1.31 &local_verbose("help_list");
2646 sashby 1.28
2647 sashby 1.2 print <<ENDTEXT;
2648 hpw 1.1 List the available projects and versions installed in the local SCRAM database
2649 sashby 1.46 (see scram install help).
2650 hpw 1.1
2651     Usage:
2652    
2653 sashby 1.24 $bold scram list $normal [ProjectName]
2654 hpw 1.1
2655     ENDTEXT
2656 sashby 1.34 return (0);
2657 sashby 1.2 }
2658    
2659     sub help_remove
2660     {
2661     ###############################################################
2662     # help_remove() #
2663     ###############################################################
2664     # modified : Mon May 28 11:31:12 2001 / SFA #
2665     # params : #
2666     # : #
2667     # : #
2668     # : #
2669     # function : Show help for scram remove command. #
2670     # : #
2671     # : #
2672     ###############################################################
2673 sashby 1.31 &local_verbose("help_remove");
2674 sashby 1.28
2675 sashby 1.2 print <<ENDTEXT;
2676 sashby 1.5 Remove a project entry from scram database file (\"project.lookup\").
2677 sashby 1.2
2678     Usage:
2679    
2680 sashby 1.24 $bold scram remove $normal [ProjectName] [Version]
2681 sashby 1.2
2682     ENDTEXT
2683 sashby 1.34 return (0);
2684 sashby 1.2 }
2685 hpw 1.1
2686 sashby 1.2 sub help_project
2687     {
2688     ###############################################################
2689     # help_project() #
2690     ###############################################################
2691     # modified : Mon May 28 11:31:16 2001 / SFA #
2692     # params : #
2693     # : #
2694     # : #
2695     # : #
2696     # function : Show help for scram project command. #
2697     # : #
2698     # : #
2699     ###############################################################
2700 sashby 1.31 &local_verbose("help_project");
2701 sashby 1.28
2702 sashby 1.2 print <<ENDTEXT;
2703 hpw 1.1 Setup a new project development area. The new area will appear in the current
2704     working directory.
2705     Usage:
2706    
2707 sashby 1.43 $bold scram project [-d install_area] [-n directory_name]$normal project_url [project_version] [-f cmstools.conf]
2708 hpw 1.1
2709     Options:
2710    
2711     project_url: The url of a scram bootstrap file.
2712 sashby 1.46
2713 hpw 1.1 Currently supported types are:
2714 sashby 1.46
2715 hpw 1.1 $bold Database label $normal
2716     Labels can be assigned to bootstrap files for easy
2717     access (See "scram install" command). If you
2718     specify a label you must also specify a project_version.
2719     e.g.
2720    
2721     scram project ORCA ORCA_1_1_1
2722    
2723     To see the list of installed projects use the
2724     "scram list" command.
2725    
2726 sashby 1.46 $bold file: $normal A regular file on an accessible file system
2727 hpw 1.1 e.g.
2728    
2729     file:~/myprojects/projecta/config/BootStrapFile
2730    
2731 sashby 1.43
2732     Use the "-f" flag followed by a valid filename (which MUST end in ".conf") to
2733     allow auto setup to proceed without reading files from a repository (standalone mode).
2734    
2735    
2736 hpw 1.1 project_version:
2737 sashby 1.46 Only for use with a database label.
2738 hpw 1.1
2739     -d install_area:
2740     Indicate a project installation area into which the new
2741     project area should appear. Default is the current working
2742     directory.
2743    
2744     -n directory_name:
2745     Specify the name of the SCRAM development area you wish to
2746     create.
2747 sashby 1.46
2748    
2749 hpw 1.1 ENDTEXT
2750 sashby 1.34 return (0);
2751 sashby 1.2 }
2752 hpw 1.1
2753 sashby 1.2 sub help_version
2754     {
2755     ###############################################################
2756     # help_version() #
2757     ###############################################################
2758     # modified : Mon May 28 11:31:23 2001 / SFA #
2759     # params : #
2760     # : #
2761     # : #
2762     # : #
2763     # function : Show help for scram version command. #
2764     # : #
2765     # : #
2766     ###############################################################
2767 sashby 1.31 &local_verbose("help_version");
2768 sashby 1.28
2769 sashby 1.2 print <<ENDTEXT;
2770     With no $bold [version] $normal argument given, this command will simply
2771 hpw 1.1 print to standard output the current version number.
2772    
2773     Providing a version argument will cause that version to be downloaded and
2774     installed, if not already locally available.
2775    
2776    
2777     Usage:
2778     $bold scram version [version]$normal
2779    
2780     ENDTEXT
2781 sashby 1.34 return (0);
2782 sashby 1.2 }
2783 hpw 1.1
2784 sashby 1.2 sub help_arch
2785     {
2786     ###############################################################
2787     # help_arch() #
2788     ###############################################################
2789     # modified : Mon May 28 11:31:33 2001 / SFA #
2790     # params : #
2791     # : #
2792     # : #
2793     # : #
2794     # function : Show help for scram arch command. #
2795     # : #
2796     # : #
2797     ###############################################################
2798 sashby 1.31 &local_verbose("help_arch");
2799 sashby 1.28
2800 sashby 1.2 print <<ENDTEXT;
2801 hpw 1.1 Print out the architecture flag for the current machine.
2802    
2803     Usage:
2804     $bold scram arch $normal
2805     ENDTEXT
2806 sashby 1.34 return (0);
2807 sashby 1.2 }
2808 hpw 1.1
2809 sashby 1.2 sub help_runtime
2810     {
2811     ###############################################################
2812     # help_runtime() #
2813     ###############################################################
2814     # modified : Mon May 28 11:31:37 2001 / SFA #
2815     # params : #
2816     # : #
2817     # : #
2818     # : #
2819     # function : Show help for scram runtime command. #
2820     # : #
2821     # : #
2822     ###############################################################
2823 sashby 1.31 &local_verbose("help_runtime");
2824 sashby 1.28
2825 sashby 1.2 print <<ENDTEXT;
2826 hpw 1.1 Echo to Standard Output the Runtime Environment for the current development area
2827     Output available in csh or sh flavours
2828    
2829     Usage:
2830     1) $bold scram runtime [-csh|-sh] $normal
2831     or
2832     2) $bold scram runtime [-csh|-sh] filename $normal
2833     or
2834     3) $bold scram runtime info filename [variable]$normal
2835    
2836     1) For the general configuration environment
2837     2) For environment described in filename or
2838     areatop/src/directory/BuildFile
2839     3) Display information concerning the environment in the given file
2840     (limited to variable if specified)
2841    
2842     The file for cases 2) and 3) are searched as follows :
2843     a) straightforward filename
2844     b) filename relative to local_area/src
2845     c) filename relative to release_area/src
2846     d) BuildFile relative to local_area/src
2847     e) BuildFile relative to release_area/src
2848    
2849     Examples:
2850    
2851     Setup the current environment to include the project Runtime Environment
2852     in a csh environment
2853    
2854     $bold eval `scram runtime -csh` $normal
2855    
2856     Setup the current environment to include the project Runtime Environment in a
2857     sh environment
2858    
2859     $bold eval `scram runtime -sh` $normal
2860    
2861 sashby 1.12 ENDTEXT
2862 sashby 1.34 return (0);
2863 sashby 1.12 }
2864    
2865    
2866     sub help_setroot
2867     {
2868     ###############################################################
2869     # help_setroot #
2870     ###############################################################
2871     # modified : Wed Nov 7 16:23:32 2001 / SFA #
2872     # params : #
2873     # : #
2874     # : #
2875     # : #
2876     # function : #
2877     # : #
2878     # : #
2879     # : #
2880     ###############################################################
2881 sashby 1.31 &local_verbose("help_setroot");
2882 sashby 1.28
2883 sashby 1.12 print <<ENDTEXT;
2884     Set a SCRAM-aware variable which points to a particular project area. This
2885     permits the setting of the runtime environment outside of the project area.
2886    
2887     Usage:
2888 sashby 1.24 $bold scram setroot [-sh|-csh] [ProjectName] [Version] $normal
2889 sashby 1.12
2890 sashby 1.24 To set the environment:
2891 sashby 1.12
2892 sashby 1.24 $bold eval `scram setroot [-sh|-csh] [ProjectName] [Version]` $normal
2893 hpw 1.1
2894     ENDTEXT
2895 sashby 1.34 return (0);
2896 sashby 1.2 }