ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/scram
(Generate patch)

Comparing COMP/SCRAM/src/scram (file contents):
Revision 1.24 by williamc, Fri Jun 4 16:56:10 1999 UTC vs.
Revision 1.33 by williamc, Mon Aug 28 08:19:03 2000 UTC

# Line 1 | Line 1
1 < #!/usr/local/bin/perl5
1 > #!/usr/local/bin/perl5
2 > # ^^^^^^^^^^^^^^^^^^^^
3 > # we dont need this anymore to invoke perl but options placed here will be
4 > # used.
5   #
6   # User Interface
7   #
8 + # Make sure were running the right version
9 +
10 + versioncheck();
11  
12   $inputcmd=shift;
13   $found='false';
14   $bold  = "\033[1m";
15 + $rv=0;
16   $normal = "\033[0m";
17 < @allowed_commands=qw(project build install version list arch setup runtime devtest);
17 > $self={};
18 >
19 > @allowed_commands=qw(project build install version list arch setup runtime db tool);
20 > @dev_cmds=qw(devtest align);
21  
22   if ( $inputcmd ne "" ) {
23 < foreach $command ( @allowed_commands ) {
23 > foreach $command ( (@allowed_commands,@dev_cmds) ) {
24           if ( $command=~/^$inputcmd/i) {
25                  # Deal with a help request
26 <                do{ &helpheader($command);
26 >                do{     helpheader($command);
27                          &{"help_".$command}; exit; } if $ARGV[0]=~/help/i;
28 <                &$command; $found='true';
28 >                $rv=&$command; $found='true';
29                  last;
30           }
31   }
# Line 30 | Line 40 | if ( ! ( $found=~/true/ ) ) {
40          print "Help on individual commands available through\n\n";
41          print "$bold       scram".$normal." command$bold help $normal\n\n";
42   }
43 + exit $rv;
44  
45 < sub devtest {
46 <        use Utilities::testclass;
47 <        my $class;
48 <        my $tester;
38 <
39 <        $class=shift @ARGV;
40 <        $tester=testclass->new($class);
41 <        $tester->dotest(@ARGV);
45 > sub error {
46 >        my $string=shift;
47 >        print "scram : ".$string."\n";
48 >        exit 1;
49   }
50  
51 < sub test_setup {
52 <        my $tool;
53 <        my $toolversion;
47 <        my $interactive=0;
48 <        my $listonly=0;
49 <
50 <        # process options
51 <        while ( $ARGV[0]=~"^-" ) { # turn on interactive setup mode
52 <         if ( $ARGV[0]=~/-i/ ) {
53 <           shift @ARGV;
54 <           $interactive=1;
55 <           print "Entering Interactive Setup Mode\n";
56 <           next;
57 <         }
58 <         if ( $ARGV[0]=~/-r/ ) {
59 <           shift @ARGV;
60 <           $listonly=1;
61 <           print "---------------- Project Requirements List -----------\n";
62 <           next;
63 <         }
64 <         print "Error : Unknown Option $ARGV[0]\n";
65 <         help_setup();
66 <         exit 1;
67 <        }
68 <        my $toolname=shift @ARGV;
69 <        my $version=shift @ARGV;
51 > sub versioncheck {
52 >        my $version;
53 >        my $thisversion;
54  
55 <        &FullEnvInit();
72 <        &RequirementsInit;
55 >        $thisversion=getversion();
56  
57 <        if ( $toolname ne "" ) {
58 <          _setuptool($interactive, $toolname, $version);
57 >        if ( @_ ) {
58 >           $version=shift;
59          }
60          else {
61 <          $reqobj->IteratorReset;
62 <          while ( ( $toolname=$reqobj->IteratorNext() ) ne "" ) {
63 <            if ( $listonly ) {
64 <                print $bold.$toolname.$normal.
65 <                        " version ".$reqobj->Version($toolname)."\n";
66 <            }
67 <            else {
85 <              _setuptool
86 <                 ($interactive, $toolname, $reqobj->Version("$toolname"));
87 <            }
61 >         if ( ! localtop_find() ) {
62 >         LoadEnvFile();
63 >         my $versionfile=$ENV{LOCALTOP}."/$ENV{projconfigdir}/scram_version";
64 >          if ( -f $versionfile ) {
65 >           open (VERSION, "<".$versionfile);
66 >            $version=<VERSION>;
67 >            chomp $version;
68            }
69 +         }
70 +        }
71 +        if ( defined $version ) {
72 +            if ( $version ne $thisversion ) {
73 +              # first try to use the correct version
74 +              if ( -d $scram_top."/".$version ) {
75 +                $ENV{SCRAM_HOME}=$scram_top."/".$version;
76 +                my $rv=system("scram", @ARGV)/256;
77 +                exit $rv;
78 +              }
79 +              else { # if not then simply warn
80 +                print "******* Warning : scram version inconsistent ********\n";
81 +                print "This version: $thisversion; Required version: $version";
82 +                print "*****************************************************\n";
83 +                print "\n";
84 +              }
85 +            }
86          }
87   }
88  
89 < sub _setuptool {
90 <        my $tool;
91 <        my $toolversion;
92 <        my $interactive=shift;
93 <        my $toolname=shift;
94 <        my $version=shift;
89 > sub _processcmds {
90 >        my $optionhandler=shift;
91 >        my $allowed_commands=shift;
92 >        my $cmds=shift;
93 >        my @subs=@_;
94 >
95 >        my $found='false';
96 >        # make a string from the subcommand levels
97 >        my $substring="";
98 >        if ( @subs ) {
99 >           $substring= join '_', @subs;
100 >           $substring=$substring."_";
101 >        }
102  
103 +        # Process options
104 +        if ( defined ${$cmds}[0] ) {
105 +        while ( ${$cmds}[0]=~/^-/) {
106 +           &{$optionhandler}( ${$cmds}[0],$cmds);
107 +        }
108  
109 <        if ( ( $version eq "" ) && ( $interactive == 0 )) {
110 <          #if not specified set to that of req. doc
111 <          $version=$reqobj->Version($toolname);
112 <        }
113 <
114 <        # ideally try and download it if not already in .SCRAM
115 <        # Only scram toolbox files supported so far
116 <          if ( ! -e "$ENV{LOCALTOP}/.SCRAM/$toolname" ) {
117 <                &urlhandler::urlhandler("file:$ENV{SCRAM_HOME}/toolbox/"
118 <                        .$toolname, "$ENV{LOCALTOP}/.SCRAM/$toolname") ;
119 <          }
120 <        use ToolSetup;
121 <        $tool=ToolSetup->new("$ENV{LOCALTOP}/.SCRAM/$toolname");
122 <
123 <        # check we have a version
124 <        if ( $interactive == 0 ) {
125 <         $tool->UnSetInteractive();
126 <        }
127 <        else {
119 <          $tool->SetInteractive();
120 <        }
121 <        $tool->Setup($toolname, $version);
122 <        
109 >        my $inputcmd=shift @{$cmds};
110 >        if ( $inputcmd ne "" ) {
111 >         foreach $command ( @{$allowed_commands} ) {
112 >           if ( $command=~/^$inputcmd/i) {
113 >                # Deal with a help request
114 >                if ( ( defined $$cmds[0]) && $$cmds[0]=~/help/i ) {
115 >                   &helpheader($command,@subs);
116 >                   &{"help_".$substring.$command}; exit;
117 >                }
118 >                else {
119 >        #print "calling $substring".$command."(@{$cmds})\n";
120 >                   &{$substring.$command}(@{$cmds}); $found='true';
121 >                   last;
122 >                }
123 >           }
124 >         }
125 >        }
126 >        }
127 >        return $found;
128   }
129  
130 +
131   sub help_build {
132          &build;
133   }
134 +
135 + sub align {
136 +        _localarea()->align();
137 + }
138 +
139   sub build {
140          # is this a based or free release?
141          FullEnvInit();
142 <        use BuildSetup;
142 >        use BuildSystem::BuildSetup;
143          $ENV{MAKETARGETS}=join ' ',@ARGV;
144 <        BuildSetup($ENV{THISDIR},@ARGV);
145 < #       system("$ENV{TOOL_HOME}/BuildSetup",$ENV{THISDIR},@ARGV);
144 >        my $bs=BuildSystem::BuildSetup->new(toolbox());
145 >        $rv=$bs->BuildSetup($ENV{THISDIR},@ARGV);
146 >        $rv;
147   }
148  
149   sub project {
150 +        my @args=@ARGV;
151 +
152 +        my $devareaname="";
153 +        use Cwd;
154 +        my $installarea=cwd();
155 +
156          # process options
157 <        while ( $ARGV[0]=~"^-" ) {
158 <         if ( $ARGV[0]=~/-n/ ) {
159 <           shift @ARGV;
160 <           $ENV{devareaname}=shift @ARGV;
157 >        while ( $args[0]=~"^-" ) {
158 >         if ( $args[0]=~/-n/ ) {
159 >           shift @args;
160 >           $devareaname=shift @args;
161           }
162 <         if ( $ARGV[0]=~/-d/ ) {  #installation area directory
163 <          shift @ARGV;
164 <          chdir $ARGV[0];
165 <          shift @ARGV;
162 >         elsif ( $args[0]=~/-d/ ) {  #installation area directory
163 >          shift @args;
164 >          $installarea=$args[0];
165 >          if ( ! -d $installarea ) {
166 >                error("$installarea does not exist");
167 >          }
168 >          shift @args;
169 >         }
170 >         else {
171 >          error("unknown option $args[0] to project command");
172           }
173          }
174 <        my $project=shift @ARGV;
175 <        my $version=shift @ARGV;
176 <        environmentinit();
177 <        use File::Copy;
178 <        use Utilities::AddDir;
174 >
175 >        # -- check what arguments have been passed
176 >        if ( $#args <0 || $#args>1 ) {
177 >          error("\"scram project help\" for usage info");
178 >        }
179 >        my $area; #somewhere to store the area object when we have it
180 >
181 >        if ( ( $#args==0 ) && ($args[0]=~/:/) ) {
182 >          # -- must be a url to bootstrap from
183 >          $area=scrambasics()->project($args[0], $installarea,
184 >                                                $devareaname);
185 >          scrambasics()->setuptoolsinarea($area);
186 >        }
187 >        elsif ( $#args >0 ) {
188 >          # -- need to create a satellite area
189 >          $area=scrambasics()->satellite(@args,$installarea, $devareaname);
190 >        }
191 >        else {
192 >          error("\"scram project help\" for usage info");
193 >        }
194          
195 <           use BootStrapProject2;
196 <           # get the bootstrap files downloaded
197 < #          BootStrapProject("$project\?\?$version");
198 <           $bootstrapper->BootStrap("$project\?\?$version");
199 <           # Go setup the rest of the environement, now we can
200 <           chdir $ENV{LOCALTOP};
201 <           &localtop;
202 <           LoadEnvFile();
203 <           #
204 <           # Now create the directories specified in the interface
205 <           #
206 <           foreach $key ( keys %ENV ) {
207 <                if ( $key=~/^INT/ ) {
208 <                        AddDir::adddir($ENV{$key});
209 <                }
210 <           }
211 <           if ( ! -e "$ENV{LOCALTOP}/$ENV{projconfigdir}" ) {
212 <                system("cp", "-r", "$ENV{RELEASETOP}/$ENV{projconfigdir}",
213 <                                "$ENV{LOCALTOP}/$ENV{projconfigdir}");
214 <           }
215 <           use clientfile;
216 <           BuildClientFile( $ENV{SCRAM_ProjReqsDoc} );
217 <           use Cwd;
218 <           print "\nInstallation Procedure Complete. \n".
219 <                        "Installation Located at:\n".cwd()."\n";
195 >        #
196 >        # Now create the directories specified in the interface
197 >        # There should be some better mechanism - TODO
198 >        #
199 >        chdir $area->location();
200 >        foreach $key ( keys %ENV ) {
201 >         if ( $key=~/^INT/ ) {
202 >                AddDir::adddir($ENV{$key});
203 >         }
204 >        }
205 >
206 >        print "\nInstallation Procedure Complete. \n".
207 >                "Installation Located at:\n".$area->location()."\n";
208 > }
209 >
210 > sub scrambasics {
211 >        require Scram::ScramFunctions;
212 >        if ( ! defined $scramobj ) {
213 >           environmentinit();
214 >           $scramobj=Scram::ScramFunctions->new();
215 >           $scramobj->arch($ENV{SCRAM_ARCH});
216 >           #$scramobj->verbosity(1);
217 >        }
218 >        return $scramobj;
219 > }
220 >
221 > # ------------ tool command --------------------------------------------
222 > sub tool {
223 >        @_=@ARGV;
224 >        localtop();
225 >        environmentinit();
226 >        my @allowed_cmds=qw(info list default);
227 >        _processcmds("_tooloptions", \@allowed_cmds, \@_, ("tool"));    
228 > }
229 >
230 > sub tool_default {
231 >        if ( $#_ != 1 ) {
232 >          error("\"scram tool default help\" for usage information");
233 >        }
234 >        my $tool=shift;
235 >        my $version=shift;
236 >        print "Setting default version of $tool to $version\n";
237 >        # -- adjust the toolbox
238 >        toolbox()->setdefault($tool,$version);
239 >
240 > }
241 >
242 > sub tool_list {
243 >        my $area=_localarea();
244 >        print "Tool List for "; #.$area->name()." ".$area->version()."\n";
245 >        print "Location : ".$area->location()."\n";
246 >        print "+"x60;
247 >        print "\n";
248 >        foreach $t ( toolbox()->tools() ) {
249 >          my $vers=join / /, toolbox()->versions($t);
250 >          print $t." ".$vers." (default=".toolbox()->defaultversion($t).")\n";
251 >        }
252 > }
253 >
254 > sub tool_info {
255 >        my $project=shift;
256 >        my $area=_localarea();
257 >        print "Tool Info as configured in ";
258 >                        #.$area->name()." ".$area->version()."\n";
259 >        print "Location : ".$area->location()."\n";
260 >        print "+"x60;
261 >        print "\n";
262 >
263 >        my @tools=toolbox()->gettool($project,@_);
264 >        foreach $t ( @tools ) {
265 >          if ( defined $t ) {
266 >           print "Name : ".$t->name();
267 >           print "\n";
268 >           print "Version : ".$t->version();
269 >           print "\n";
270 >           print "Docfile : ".$t->url();
271 >           print "\n";
272 >           print "+"x20;
273 >           print "\n";
274 >           @features=$t->features();
275 >           foreach $ft ( @features ) {
276 >             @vals=$t->getfeature($ft);
277 >             foreach $v ( @vals ) {
278 >               print $ft. "=$v\n";
279 >             }
280 >           }
281 >          }
282 >        }
283 > }
284 >
285 > sub _tooloptions {
286 >        error("No Options defined for tool subcommand");
287 > }
288 >
289 > sub help_tool {
290 > print <<ENDTEXT;
291 > Manage the tools in the scram area that define the areas environment.
292 > tool subcommands :
293 >        list
294 >        info tool_name
295 >        default tool_name tool_version
296 >
297 > ENDTEXT
298 > }
299 >
300 > sub help_tool_info {
301 > print <<ENDTEXT;
302 > Description:
303 >        Print out information on the specified tool in the current area
304 >        configuration.
305 > Usage :
306 >        scram tool info tool_name [tool_version]
307 >
308 > ENDTEXT
309 > }
310 >
311 > sub help_tool_list {
312 > print <<ENDTEXT;
313 > Description:
314 >        List of currently configured tools available in ther current scram
315 >        area
316 > Usage :
317 >        scram tool list
318 >
319 > ENDTEXT
320 > }
321 >
322 > sub help_tool_default {
323 > print <<ENDTEXT;
324 > Description:
325 >        Change the default version of a tool to be used in the area
326 > Usage :
327 >        scram tool default tool_name tool_version
328 >
329 > ENDTEXT
330 > }
331 >
332 > # ----------------------------------------------------------------------
333 > sub _requirements {
334 >        if ( ! defined $reqsobj ) {
335 >          localtop();
336 >          my $area=_localarea();
337 >          scrambasics()->arearequirements($area)
338 >        }
339 >        return $reqsobj;
340 > }
341 >
342 > sub _allprojectinitsearcher {
343 >        my $search=_projsearcher();
344 >        foreach $proj ( _scramprojdb()->list() ) {
345 >           $search->addproject($$proj[0],$$proj[1]);
346 >        }
347 > }
348 >
349 > sub _projsearcher {
350 >        if ( ! defined $self->{projsearcher} ) {
351 >          require Scram::ProjectSearcher;
352 >          $self->{projsearcher}=Scram::ProjectSearcher->new(_scramprojdb());
353 >        }
354 >        return $self->{projsearcher};
355 > }
356 >
357 > sub _scramprojdb {
358 >        return scrambasics()->scramprojectdb();
359   }
360  
361   sub runtime {
362          my $shell;
363 <        environmentinit();
186 <        localtop();
363 >        require Runtime;
364  
365          # process options
366          while ( $ARGV[0]=~"^-" ) {
# Line 200 | Line 377 | sub runtime {
377           print "Unknown Option $ARGV[0]\n";
378           exit 1;
379          }
380 <        open (file, "$ENV{LOCALTOP}/.SCRAM/$ENV{SCRAM_ARCH}/clientsettings" )
381 <                or die "Unable to open file ".
382 <                "$ENV{LOCALTOP}/.SCRAM/$ENV{SCRAM_ARCH}/clientsettings $!";
383 <        while( <file> ) {
384 <           chomp;
385 <           next if /^#/;
386 <           next if /^\s*$/;
387 <           ($product, $version, $type, $variable, $value, @junk)=split /:/;
388 <           next if ( $variable=~/\&/ );
389 <           if ( $type=~/^R/ ) {
390 <                if ( ( $type=~/path/ ) ) { #type Rtype
391 <                   addvar($variable,$value,":"); # Colon seperated
392 <                }
393 <                else {                   #type R
394 <                   addvar($variable,$value," "); # Add with spaces
395 <                }
396 <           }
380 >
381 >        FullEnvInit();
382 >        if ( @ARGV ) {
383 >           my $runtime=Runtime->new();
384 >           my $arg=shift @ARGV;
385 >
386 >           my $info=0;
387 >           if ( $arg eq "info" ) {
388 >              $arg=shift @ARGV;
389 >              $info=1;
390 >           }
391 >
392 >           # --- determine filename
393 >           my $filename;
394 >           if ( -f $arg ) { # Is it a file?
395 >              $filename=$arg;
396 >           }
397 >           else {
398 >               # -- lets see if its a BuildFile location
399 >               $filename=_testfile($ENV{LOCALTOP}."/src/".$arg,
400 >                                $ENV{RELEASETOP}."/src/".$arg,
401 >                                $ENV{LOCALTOP}."/src/".$arg."/BuildFile",
402 >                                $ENV{RELEASETOP}."/src/".$arg."/BuildFile");
403 >               if ( $filename eq "" ) {
404 >                   print "Unable to find a file (or BuildFile) relating to ".
405 >                        $arg."\n";
406 >                   exit 1;
407 >               }
408 >           }
409 >           $runtime->file($filename);
410 >           if ( ! $info ) {
411 >             $runtime->printenv($shell);
412 >           }
413 >           else {
414 >             if ( @ARGV ) { #do we have a specific variable request?
415 >                  _printvardoc($runtime,shift @ARGV);
416 >             }
417 >             else {
418 >                foreach $var ( $runtime->list() ) {
419 >                  _printvardoc($runtime,$var);
420 >                }
421 >             }
422 >           }
423 >           undef $runtime;
424          }
425 <        close file;
426 <        addvar("LD_LIBRARY_PATH","$ENV{LOCALTOP}/lib/$ENV{SCRAM_ARCH}",":");
223 <        addvar("PATH","$ENV{LOCALTOP}/bin/$ENV{SCRAM_ARCH}",":");
425 >        else {
426 >        FullEnvInit();
427          # We have to clean up from the last runtime cmd - use env history
428          foreach $variable ( %ENV ) {
429            if ( $variable=~/^SCRAMRT_(.*)/ ) { #SCRAMRT are history retaining
430 <            $ENV{$1}=~s/\Q$ENV{$variable}\N\:*//;
430 >            my $var=$1;
431 >            $ENV{$var}=~s/\Q$ENV{$variable}\E//g;
432 >            $ENV{$var}=~s/^:*//;  # Deal with any Path variables
433 >            #print "$variable : $ENV{$variable} \n$var : $ENV{$var}\n";
434              delete $ENV{$variable};
435            }
436          }
437 +
438 +        # -- Set SCRAM release area paths
439 +        addpath("LD_LIBRARY_PATH","$ENV{LOCALTOP}/lib/$ENV{SCRAM_ARCH}");
440 +        addpath("LD_LIBRARY_PATH","$ENV{RELEASETOP}/lib/$ENV{SCRAM_ARCH}");
441 +
442 +        # -- get the tool runtime environments
443 +        my $toolbox=toolbox();
444 +        foreach $tool ( $toolbox->tools() ) {
445 +          $tool=$toolbox->gettool($tool);
446 +          
447 +          if ( defined $tool ) {
448 +           # -- get runtime paths
449 +           foreach $f ( $tool->listtype("runtime_path")) {
450 +            foreach $val ( $tool->getfeature($f) ) {
451 +              addpath($f,$val);
452 +            }
453 +           }
454 +           # -- get runtime vars
455 +           foreach $f ( $tool->listtype("runtime")) {
456 +            foreach $val ( $tool->getfeature($f) ) {
457 +              $EnvRuntime{$f}=$val;
458 +            }
459 +           }
460 +          }
461 +        }
462 +
463 +        addpath("PATH","$ENV{LOCALTOP}/bin/$ENV{SCRAM_ARCH}");
464 +        addpath("PATH","$ENV{RELEASETOP}/bin/$ENV{SCRAM_ARCH}");
465 +
466 +        # Now get the general project environment
467 +        open ( SCRAMENV, "<$ENV{LOCALTOP}/$ENV{projconfigdir}/Runtime" );
468 +        while ( <SCRAMENV> ) {
469 +           chomp;
470 +           next if /^#/;
471 +           next if /^\s*$/;
472 +           ($name, $value)=split /=/;
473 +           addvar($name, (eval $value)," ");
474 +        }
475 +        close SCRAMENV;
476 +
477          # create new SCRAMRT history vars.
478          foreach $variable ( keys %EnvRuntime ) {
479 <          addvar("SCRAMRT_$variable", $EnvRuntime{$variable}, "");
479 >          printoutenv($shell,"SCRAMRT_$variable",$EnvRuntime{$variable});
480 >          #addvar("SCRAMRT_$variable", $EnvRuntime{$variable}, "");
481          }
482          # Now adapt as necessary - include base environment as well
483 <        addvar("LD_LIBRARY_PATH","$ENV{LD_LIBRARY_PATH}",":");
484 <        addvar("PATH","$ENV{PATH}",":");
483 >        if ( exists $ENV{LD_LIBRARY_PATH} ) {
484 >           addpath("LD_LIBRARY_PATH","$ENV{LD_LIBRARY_PATH}");
485 >        }
486 >        if ( exists $ENV{MANPATH} ) {
487 >           addpath("MANPATH","$ENV{MANPATH}");
488 >        }
489 >        addpath("PATH","$ENV{PATH}");
490          # Print out as reqd
491          foreach $variable ( keys %EnvRuntime ) {
492 <         if ( $shell eq "csh" ) {
493 <           print "setenv $variable \"$EnvRuntime{$variable}\";\n";
242 <         }
243 <         elsif ( $shell eq "sh" ) {
244 <           print "export $variable=$EnvRuntime{$variable};\n";
245 <         }
492 >          printoutenv($shell,$variable,$EnvRuntime{$variable});
493 >        }
494          }
495   }
496  
497   # Support rt for runtime
498 +
499 + sub _testfile {
500 +        my @files=@_;
501 +
502 +        my $filename="";
503 +        foreach $file ( @files ) {
504 +          if ( -f $file ) {
505 +                $filename=$file;
506 +                last;
507 +          }
508 +        }
509 +        return $filename;
510 + }
511 +
512 + sub _printvardoc {
513 +        my $runtime=shift;
514 +        my $var=shift;
515 +
516 +        print $var." :\n";
517 +        print $runtime->doc($var);
518 +        print "\n";
519 + }
520 +
521 + sub printoutenv {
522 +        my $shell=shift;
523 +        my $variable=shift;
524 +        my $value=shift;
525 +
526 +        if ( $shell eq "csh" ) {
527 +          print "setenv $variable \"$value\";\n";
528 +        }
529 +        elsif ( $shell eq "sh" ) {
530 +          print "$variable=\"$value\";\n";
531 +          print "export $variable;\n";
532 +        }
533 + }
534 +
535 + sub addpath {
536 +        my $name=shift;
537 +        my $val=shift;
538 +
539 +        my $n;
540 +        my @env;
541 +        @env=split /:/, $EnvRuntime{$name};
542 +        foreach $n ( (split /:/, $val ) ){
543 +         if (  ! grep /^\Q$n\E$/, @env ) {
544 +          addvar($name,$n,":");
545 +         }
546 +        }
547 + }
548 +
549   sub addvar {
550          my $name=shift;
551          my $val=shift;
# Line 281 | Line 580 | sub environmentinit {
580          $ENV{INTbin}="bin/$ENV{SCRAM_ARCH}";
581          $ENV{INTlog}="logs";
582  
583 <        if ( ! ( exists $ENV{SCRAM_HOME}) ){
584 <         $ENV{SCRAM_HOME}="/afs/cern.ch/cms/Releases";
286 <         print "Warning : Environment Variable SCRAM_HOME not set.\n";
287 <         print "Defaulting to $ENV{SCRAM_HOME}\n";
288 <        }
289 <         if ( ! ( exists $ENV{SCRAM_CONFIG} ) ){
583 >        ($ENV{SCRAM_BASEDIR}=$ENV{SCRAM_HOME})=~s/(.*)\/.*/$1/;
584 >        if ( ! ( exists $ENV{SCRAM_CONFIG} ) ){
585                  $ENV{SCRAM_CONFIG}="$ENV{SCRAM_HOME}/configuration";
586          }
587          if ( ! ( exists $ENV{TOOL_HOME} ) ){
588                  $ENV{TOOL_HOME}="$ENV{SCRAM_HOME}/src";
589          }
590          if ( ! ( exists $ENV{SCRAM_LOOKUPDB} ) ){
591 <                $ENV{SCRAM_LOOKUPDB}="$ENV{SCRAM_CONFIG}/project.lookup";
591 >                if ( -d "$ENV{SCRAM_BASEDIR}/scramdb/" ) {
592 >                  $ENV{SCRAM_LOOKUPDB}="$ENV{SCRAM_BASEDIR}/scramdb/project.lookup";
593 >                }
594 >                else {
595 >                  $ENV{SCRAM_LOOKUPDB}="$ENV{SCRAM_CONFIG}/project.lookup";
596 >                }
597          }
598 +        $ENV{SCRAM_AVAILDIRS}="";
599 +        $ENV{SCRAM_AVAILFILES}="";
600   }
601  
602 < sub localtop {
603 <        # find localtop
604 <        use Cwd;
605 <        my $thispath=cwd;
606 <        block: {
607 <        do {
608 <          if ( -e "$thispath/.SCRAM" ) {
609 <                $ENV{LOCALTOP}=$thispath;
610 <                last block;
602 > sub _localarea {
603 >        if ( ! defined $self->{localarea} ) {
604 >          require Configuration::ConfigArea;
605 >          $self->{localarea}=Configuration::ConfigArea->new();
606 >          if ( ! defined $ENV{LOCALTOP} ) {
607 >           if ( $self->{localarea}->bootstrapfromlocation() ) {
608 >            # Were not in a local area
609 >            undef $self->{localarea};
610 >           }
611 >           else {
612 >             $self->{localarea}->archname(scrambasics()->arch());
613 >           }
614 >          }
615 >          else {
616 >            $self->{localarea}->bootstrapfromlocation($ENV{LOCALTOP});
617            }
618 <        } while ( ( $thispath=~s/(.*)\/.*/$1/ )=~/./  );
618 >        }
619 >        return $self->{localarea};
620 > }
621 >
622 > sub localtop_find {
623 >        my $rv=1;
624 >        if ( defined _localarea()) {
625 >          $rv=0;
626 >          $ENV{LOCALTOP}=_localarea()->location();
627 >        }
628 >        return $rv;
629 > }
630 >
631 > sub localtop {
632 >        localtop_find();
633          if ( ! (defined $ENV{LOCALTOP}) ) {
634           print "Unable to locate the top of local release. Exiting\n";
635           exit 1;
636          }
315        } #end block
637          ($ENV{THISDIR}=cwd)=~s/^\Q$ENV{LOCALTOP}\L//;
638          $ENV{THISDIR}=~s/^\///;
318        $ENV{SCRAM_WORKDIR}="$ENV{LOCALTOP}/.SCRAM";
639   }
640  
641   sub LoadEnvFile {
642 <        open ( SCRAMENV, "<$ENV{SCRAM_WORKDIR}/Environment" ) ||
323 <                die "Cant find Environment file $!\n";
324 <        while ( <SCRAMENV> ) {
325 <           chomp;
326 <           next if /^#/;
327 <           next if /^\s*$/ ;
328 <           ($name, $value)=split /=/;
329 <           eval "\$ENV{${name}}=\"$value\"";
330 <        }
331 <        close SCRAMENV;
642 >        _localarea()->copyenv(\%ENV);
643   }
644  
645   sub env {
646     print "Sorry - Not yet\n";
647   }
648  
649 < sub RequirementsInit {
650 <        use Requirements;
651 <        $reqobj=Requirements->new($ENV{SCRAM_ProjReqsDoc});
649 > sub devtest {
650 >        require Utilities::TestClass;
651 >        my $class=shift @ARGV;
652 >
653 >        my $tester;
654 >        my $path;
655 >
656 >        #_initproject();
657 >        if ( $class=~/::/ ) {
658 >           ($path=$class)=~s/(.*)::.*/$1/;
659 >        }
660 >        $tester=Utilities::TestClass->new($class,
661 >                "$ENV{SCRAM_HOME}/src/$path/test/testdata");
662 >        $tester->dotest(@_);
663   }
664  
665   #
666   # Create a lookup tag in the site database
667   #
668 < sub install ( $tagname, $version ) {
669 <        my $tagname=shift @ARGV;
670 <        my $version=shift @ARGV;
671 <
350 <        # create database entry
351 <        &FullEnvInit;
352 <        if ( $version eq "" ) {
353 <           $version=$ENV{SCRAM_PROJVERSION};
354 <        }
355 <        if ( $tagname eq "" ) {
356 <           $tagname=$ENV{SCRAM_PROJECTNAME};
357 <        }
358 <        my $filename="$ENV{SCRAM_CONFIG}/project.lookup";
359 <        my $outfile="$ENV{SCRAM_CONFIG}/project.lookup.tmp";
360 <        open ( LOCALLOOKUPDB, "<$filename" );
361 <        open ( OUTFILE , ">$outfile" ) or die "Unable to open $outfile $!\n";
362 <        while ( <LOCALLOOKUPDB> ) {
363 <            if ( /^$tagname/ ) {
364 <                print "Related tag :".$_."\n";
365 <                if ( /$version/) {
366 <                  print "$tagname $version already exists. Overwrite (y/n)\n";
367 <                  if ( ! (<STDIN>=~/y/i ) ) {
368 <                        print "Aborting install ...\n";
369 <                        close OUTFILE;
370 <                        close LOCALLOOKUPDB;
371 <                        exit 1;
372 <                  }
373 <                }
374 <                else {
375 <                        print OUTFILE $_;
376 <                }
377 <            }
378 <            else {
379 <                print OUTFILE $_;
380 <            }
381 <        }
382 <        print OUTFILE "$tagname:$version:file:$ENV{LOCALTOP}".
383 <                "/.SCRAM/InstallFile\n";
384 <        close OUTFILE;
385 <        close LOCALLOOKUPDB;
386 <        copy ( "$outfile", "$filename" )
387 <                || die "Unable to copy $! \n";
388 <
668 > sub install {
669 >        localtop();
670 >        scrambasics()->addareatoDB(_localarea(),@ARGV);
671 >        _localarea()->align();
672   }
673  
674   sub help_install()  {
# Line 397 | Line 680 | this label rather than a remote url refe
680  
681   Usage:
682  
683 <                 scram install [[label] [version]]
683 >        $bold   scram install $normal [project_tag [version_tag]]
684  
685 < label   : override default label (the project name of the current release)
686 < version : the version tag of the current release. If version is not
685 > porject_tag : override default label (the project name of the current release)
686 > version_tag : the version tag of the current release. If version is not
687            specified the base release version will be taken by default.
688  
689   ENDTEXT
407 exit;
690   }
691  
692   sub helpheader ($label) {
# Line 416 | Line 698 | print <<ENDTEXT;
698   ENDTEXT
699   }
700  
701 + sub getversion {
702 +        ($thisversion=$ENV{SCRAM_HOME})=~s/(.*)\///;
703 +        $scram_top=$1;
704 +        $scram_version=$thisversion;
705 +        # deal with links
706 +        my $version=readlink $ENV{SCRAM_HOME};
707 +        if ( defined $version)  {
708 +          $scram_version=$version;
709 +        }
710 +        return $scram_version;
711 + }
712 +
713   sub version {
714          my $version=shift @ARGV;
715          my $thisversion;
# Line 425 | Line 719 | sub version {
719          ($thisversion=$ENV{SCRAM_HOME})=~s/(.*)\///;
720          $scram_top=$1;
721          if ( $version eq "" ) {
722 <          print "$thisversion\n";
722 >          print "$thisversion";
723 >          # deal with links
724 >          $version=readlink $ENV{SCRAM_HOME};
725 >          if ( defined $version)  {
726 >                print " ---> $version";
727 >          }
728 >          print "\n";
729          }
730          else {
731            if ( -d $scram_top."/".$version ) {
# Line 433 | Line 733 | sub version {
733            }
734            else {
735                print "Version $version not available locally\n";
736 <              print "Attempting download from the SCRAM repository";
736 >              print "Attempting download from the SCRAM repository\n";
737                # set up and configure the cvs module for SCRAM
738 <              use Utilities::cvsmodule;
739 <              $cvsobject=cvsmodule->new();
738 >              use Utilities::CVSmodule;
739 >              $cvsobject=Utilities::CVSmodule->new();
740                $cvsobject->set_base(
741                  "cmscvs.cern.ch:/cvs_server/repositories/SCRAM");
742                $cvsobject->set_auth("pserver");
# Line 452 | Line 752 | sub version {
752                print "\n";
753            }
754          }
755 +        0;
756   }
757  
758   sub list {
759          &environmentinit;
760 <        my $filename="$ENV{SCRAM_CONFIG}/project.lookup";
761 <        open ( LOCALLOOKUPDB, "<$filename" );
760 >        my $filename="$ENV{SCRAM_LOOKUPDB}";
761 >        if ( ! -f $ENV{SCRAM_LOOKUPDB} ) {
762 >          print "No installation database available - perhaps no projects".
763 >                " have been installed locally\n";
764 >          exit 1;
765 >        }
766          print "Installed Projects\n";
767          print "------------------\n";
768          print "|Project Name  | Project Version |\n";
769          print "----------------------------------\n";
770 <        while ( <LOCALLOOKUPDB> ) {
771 <          ( $name, $version, $type, $url ) = split ":", $_;
770 >        listdb($filename);
771 > }
772 >
773 > sub db {
774 >        my $subcmd=shift @ARGV;
775 >        &environmentinit;
776 >
777 >        switch : {
778 >        if ( $subcmd eq 'link' ) {
779 >          dblink($ENV{SCRAM_LOOKUPDB},@ARGV);
780 >          last switch;
781 >        }
782 >        if ( ! -f $ENV{SCRAM_LOOKUPDB} ) {
783 >          print "No installation database available - perhaps no projects".
784 >                "have been installed locally\n";
785 >          exit 1;
786 >        }
787 >        if ( $subcmd eq 'unlink' ) {
788 >          dbunlink($ENV{SCRAM_LOOKUPDB},@ARGV);
789 >          last switch;
790 >        }
791 >        if ( $subcmd eq 'showlinks' ) {
792 >          dblinklist($ENV{SCRAM_LOOKUPDB});
793 >          last switch;
794 >        }
795 >        } # end switch
796 >        
797 > }
798 >
799 > sub dblinklist {
800 >        my $filename=shift;
801 >        open (LOCALLOOKUPDB, "<$filename")  or
802 >                die "Unable to open local database $!";
803 >        while (<LOCALLOOKUPDB>) {
804 >          if ( $_=~/\!DB (.*)/) {
805 >            print $1,"\n";
806 >          }
807 >        }
808 >        close LOCALLOOKUPDB;
809 > }
810 >
811 > sub dblink {
812 >        my $filename=shift;
813 >        my $newdbfilename=shift;
814 >        my $exists=0;
815 >
816 >        if ( -e $filename ) {
817 >         if ( -e $newdbfilename ) {
818 >         # Check if its already there
819 >          open (LOCALLOOKUPDB, "<$filename")  or
820 >                die "Unable to open local database $!";
821 >           while (<LOCALLOOKUPDB>) {
822 >            if ( $_=~/\!DB $newdbfilename/ ) {
823 >                $exists=1;
824 >                last;
825 >            }
826 >           }
827 >          close LOCALLOOKUPDB;
828 >          # Add it
829 >          if ( ! $exists ) {
830 >            open (LOCALLOOKUPDB, ">>$filename")  or
831 >                die "Unable to open local database $!";
832 >            print LOCALLOOKUPDB "\!DB $newdbfilename\n";
833 >            close LOCALLOOKUPDB;
834 >          }
835 >         }
836 >         else {
837 >          print "Unknown file $newdbfilename\n";
838 >          exit 1;
839 >         }
840 >        }
841 >        else {
842 >          print "Unknown file $filename $!\n";
843 >          exit 1;
844 >        }
845 >        
846 > }
847 >
848 > sub dbunlink {
849 >        my $filename=shift;
850 >        my $dbfilename=shift;
851 >        if ( -e $filename ) {
852 >         # Check if its already there
853 >         open (LOCALLOOKUPDB, "<$filename")  or
854 >                die "Unable to open local database $!";
855 >         open (DBOUTFILE, ">$filename.tmp") or
856 >                die "Unable to open working file $!";
857 >         while (<LOCALLOOKUPDB>) {
858 >            if ( $_!~/\!DB $dbfilename/ ) {
859 >                print DBOUTFILE $_;
860 >            }
861 >           }
862 >         close LOCALLOOKUPDB;
863 >         close DBOUTFILE;
864 >         use File::Copy;
865 >         rename "$filename.tmp", $filename;
866 >        }
867 > }
868 >
869 > sub listdb {
870 >        my $filename=shift;
871 >        my $map;
872 >
873 >        use FileHandle;
874 >        my $fh=FileHandle->new();
875 >        open ( $fh, "<$filename" );
876 >        while ( $map=<$fh> ) {
877 >          if ( $map=~/^\!DB (.*)/ ) { # Check for other DB files
878 >                my $db=$1;
879 >                if ( -f $db ) {
880 >                  listdb($db);
881 >                }
882 >                next;
883 >          }
884 >          ( $name, $version, $type, $url ) = split ":", $map;
885            printf "%1s",$name;
886            printf "%25s\n",$version;
887            printf "--> %25s\n",$type.":".$url;
888          }
889 <        close LOCALLOOKUPDB;
889 >        close $fh;
890 >        0;
891   }
892  
893   sub arch {
# Line 482 | Line 901 | sub arch {
901   #
902  
903   sub setup {
904 +        my $interactive=0;
905 +
906 +        # process options
907 +        while ( $ARGV[0]=~"^-" ) {
908 +         if ( $ARGV[0]=~/-i/ ) {
909 +           shift @ARGV;
910 +           $interactive=1;
911 +         }
912 +         else {
913 +          error("scram: unknown option $ARGV[0] to project command");
914 +         }
915 +        }
916 +
917 +        localtop();
918 +        my $area=_localarea();
919          my $toolname=shift @ARGV;
920          my $insert=0;
921 +        toolbox()->interactive($interactive);
922  
488        &FullEnvInit;
489        if ( $ENV{SCRAM_BootStrapFiles}!~/\Q$ENV{LOCALTOP}\N\/\.SCRAM/ ) {
490          $ENV{SCRAM_BootStrapFiles}="$ENV{LOCALTOP}/.SCRAM:".
491                        $ENV{SCRAM_BootStrapFiles};
492        }
493        my $filebase="$ENV{LOCALTOP}/.SCRAM/$ENV{SCRAM_ARCH}";
494        rename "$filebase/clientsettings", "$filebase/clientsettings.old";
495        chdir $ENV{LOCALTOP}; # make sure we do this from the top dir
923          # If no toolname specified then its a full setup
924          if ( $toolname eq "" ) {
925 <           rename "$filebase/clientsettings_reqs",
499 <                                "$filebase/clientsettings_reqs.old";
500 <           use clientfile;
501 <           BuildClientFile( $ENV{SCRAM_ProjReqsDoc} );
502 <           # Work-around for Broken ARCH directories
925 >           # -- add architecture specific directories
926             use Utilities::AddDir;
927 <           AddDir::adddir("$ENV{LOCALTOP}/lib/$ENV{SCRAM_ARCH}");
928 <           AddDir::adddir("$ENV{LOCALTOP}/bin/$ENV{SCRAM_ARCH}");
927 >           AddDir::adddir($area->location()."/lib/$ENV{SCRAM_ARCH}");
928 >           AddDir::adddir($area->location()."/bin/$ENV{SCRAM_ARCH}");
929 >        
930 >           # -- check the releasetop area
931 >           # if the releasetop has the files copy them
932 >           my $releaseobj=_releasearea();
933 >           if ( $releaseobj->copysetup($ENV{LOCALTOP}) ) {
934 >              print "Doing Full Setup\n";
935 >              scrambasics()->setuptoolsinarea($area);
936 >           }
937          }
938          else {
939 <          # Check for the correct toolfile
509 <          # ideally try and download it if not already in .SCRAM
510 <          # Only scram toolbox files supported so far
511 <          if ( ! -e "$ENV{LOCALTOP}/.SCRAM/$toolname" ) {
512 <                &urlhandler::urlhandler("file:$ENV{SCRAM_HOME}/toolbox/"
513 <                        .$toolname, "$ENV{LOCALTOP}/.SCRAM/$toolname") ;
514 <          }
515 <          # Parse the toolfile and update the clientsettings file
516 <          # currently just append to the end
517 <          use clientfile;
518 <          #create a new clientfile containing just the tool
519 <          clientfile::openclientfile('add');
520 <          clientfile::_tool("file:$toolname");
521 <          clientfile::closeclientfile();
522 <          #Now splice it in to the original - replacing the previous one if
523 <          #necessary - a bit of a hack to say the least -fortunately is
524 <          # already rewrittten for the next release!
525 <        
526 <          open FILEIN, "$filebase/clientsettings" or die "$!\n";
527 <          while ( <FILEIN> ) {
528 <            push @filelines, $_;
529 <            next, if /^\s*#/;
530 <            chomp;
531 <            ($toolkey=$_)=~s/(.*?:).*/$1/;
532 <          }
533 <          close FILEIN;
534 <          open FILEIN, "<$filebase/clientsettings.old";
535 <          open FILEOUT, ">$filebase/clientsettings.tmp";
536 <          while ( <FILEIN> ) {
537 <           if ( ( $_=~/^$toolkey/ ) ) {
538 <            if ( $insert==0 ) {
539 <             foreach $line ( @filelines ) {
540 <                print FILEOUT $line;
541 <             }
542 <             $insert=1;
543 <            }
544 <            next;
545 <           }
546 <           else {
547 <                print FILEOUT $_;
548 <           }
549 <         }
550 <         if ( $insert==0 ) {
551 <          foreach $line ( @filelines ) {
552 <                print FILEOUT $line;
553 <          }
554 <         }
555 <         close FILEOUT;
556 <         close FILE;
557 <         rename "$filebase/clientsettings.tmp", "$filebase/clientsettings";
939 >            scrambasics()->setuptoolsinarea($area, $toolname,@ARGV);
940          }
941 <        
941 > }
942 >
943 > sub _releasearea {
944 >        if ( !defined $self->{releasearea} ) {
945 >           require Configuration::ConfigArea;
946 >           $self->{releasearea}=Configuration::ConfigArea->new();
947 >           $self->{releasearea}->bootstrapfromlocation($ENV{RELEASETOP});
948 >        }
949 >        return $self->{releasearea};
950 > }
951 >
952 > # get a toolbox object for the local area
953 > sub toolbox {
954 >        if ( ! defined $toolbox ) {
955 >           localtop();
956 >           my $area=_localarea();
957 >           $toolbox=scrambasics()->areatoolbox($area);
958 >        }
959 >        return $toolbox;
960 > }
961 >
962 > sub help_db {
963 > print <<ENDTEXT;
964 > scram database administration command.
965 >
966 > Usage:
967 >
968 >                 $bold scram db $normal subcommand
969 >
970 > subcommands:
971 >        link :
972 >                Make available an additional database for
973 >                project and list operations
974 >
975 >                $bold scram db link $normal /a/directory/path/project.lookup
976 >
977 >        unlink :
978 >                Remove a database from the link list. Note this does
979 >                not remove the database, just the link to it in scram.
980 >
981 >                $bold scram db unlink $normal /a/directory/path/project.lookup
982 >
983 >        showlinks :
984 >                List the databases that are linked in
985 >
986 > ENDTEXT
987   }
988  
989   sub help_setup {
# Line 568 | Line 995 | the complete installation process is ini
995  
996   Usage:
997  
998 <                 $bold scram setup $normal [toolname]
998 >                 $bold scram setup [-i]$normal [toolname] [[version] [url]]
999  
1000   toolname : The name of the tool setup file required.
1001 + version  : where more than one version exists specify the version
1002 + url      : when setting up a completely new tool specify the url too
1003 +
1004 + The -i option turns off the automatic search mechanism allowing for more
1005 + user interaction with the setup mechanism
1006   ENDTEXT
575 exit;
1007   }
1008  
1009   sub help_list {
1010   print <<ENDTEXT;
1011 < Create an entry in the SCRAM database so that an installed project can be
1012 < referenced in the 'project' command by a tag/version combination.
1013 < Usage: (command to be issued from inside an installed project)
1011 > List the available projects and versions installed in the local SCRAM database
1012 > (see scram install help)
1013 >
1014 > Usage:
1015  
1016 <        $bold   scram install $normal [project_tag [version_tag]]
1016 >        $bold   scram list $normal
1017  
586 If not specified the project_tag and version_tag default to the project
587 name and version of the installation.
1018   ENDTEXT
589 exit;
1019   }
1020 +
1021   sub help_project {
1022   print <<ENDTEXT;
1023   Setup a new project development area. The new area will appear in the current
# Line 630 | Line 1060 | project_version:
1060                   Specify the name of the SCRAM development area you wish to
1061                   create.
1062          
633 -n dir_name     :
634                 Specify name of the new development area directory
1063   ENDTEXT
1064   }
1065  
1066   sub help_version {
1067   print <<ENDTEXT;
1068 < With now $bold[version] $normal argument given, this command will simply
1068 > With now $bold [version] $normal argument given, this command will simply
1069   print to standard output the current version number.
1070  
1071   Providing a version argument will cause that version to be downloaded and
1072   installed, if not already locally available.
645 [Coming soon: When available locally, your current development area will
646 then be associated with the specified scram version rather than the default]
1073  
1074  
1075   Usage:
# Line 661 | Line 1087 | Usage:
1087   ENDTEXT
1088   }
1089  
664 sub help_devtest {
665 print <<ENDTEXT;
666 For SCRAM development only. Allows testing of new features.
667
668 Usage:
669        $bold   scram devtest
670 ENDTEXT
671 }
672
1090   sub help_runtime {
1091   print <<ENDTEXT;
1092   Echo to Standard Output the Runtime Environment for the current development area
1093   Output available in csh or sh flavours
1094  
1095   Usage:
1096 <        $bold   scram runtime [-csh|-sh] $normal
1096 >        1) $bold   scram runtime [-csh|-sh] $normal
1097 > or
1098 >        2) $bold   scram runtime [-csh|-sh] filename $normal
1099 > or
1100 >        3) $bold   scram runtime info filename [variable]$normal
1101 >
1102 > 1) For the general configuration environment
1103 > 2) For environment described in filename or
1104 >                                areatop/src/directory/BuildFile
1105 > 3) Display information concerning the environment in the given file
1106 >   (limited to variable if specified)
1107 >
1108 > The file for cases 2) and 3) are searched as follows :
1109 > a) straightforward filename
1110 > b) filename relative to local_area/src
1111 > c) filename relative to release_area/src
1112 > d) BuildFile relative to local_area/src
1113 > e) BuildFile relative to release_area/src
1114  
1115   Examples:
1116  
# Line 688 | Line 1122 | in a csh environment
1122   Setup the current environment to include the project Runtime Environment in a
1123   sh environment
1124  
1125 <       $bold  `scram runtime -sh` $normal
1125 >       $bold  eval `scram runtime -sh` $normal
1126 >
1127  
1128   ENDTEXT
1129   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines