ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/scram
Revision: 1.23
Committed: Fri Apr 16 14:47:06 1999 UTC (26 years, 1 month ago) by williamc
Branch: MAIN
CVS Tags: V0_9
Branch point for: V0_9branch
Changes since 1.22: +8 -3 lines
Log Message:
Add -n switch to project command

File Contents

# User Rev Content
1 williamc 1.8 #!/usr/local/bin/perl5
2 williamc 1.1 #
3     # User Interface
4     #
5    
6     $inputcmd=shift;
7     $found='false';
8 williamc 1.13 $bold = "\033[1m";
9     $normal = "\033[0m";
10 williamc 1.15 @allowed_commands=qw(project build install version list arch setup);
11 williamc 1.1
12 williamc 1.21 if ( $inputcmd ne "" ) {
13     foreach $command ( @allowed_commands ) {
14     if ( $command=~/^$inputcmd/i) {
15 williamc 1.13 # Deal with a help request
16     do{ helpheader($command);
17     &{"help_".$command}; exit; } if $ARGV[0]=~/help/i;
18     &$command; $found='true';
19     last;
20     }
21 williamc 1.21 }
22 williamc 1.1 }
23    
24     if ( ! ( $found=~/true/ ) ) {
25 williamc 1.15 helpheader('Recognised Commands');
26 williamc 1.1 foreach $command ( @allowed_commands ) {
27 williamc 1.15 print " $bold scram ".$command.$normal."\n";
28 williamc 1.1 }
29 williamc 1.15 print "\n";
30     print "Help on individual commands available through\n\n";
31     print "$bold scram".$normal." command$bold help $normal\n\n";
32 williamc 1.1 }
33    
34 williamc 1.14 sub help_build {
35     &build;
36     }
37 williamc 1.1 sub build {
38     # is this a based or free release?
39     FullEnvInit();
40     use BuildSetup;
41 williamc 1.10 $ENV{MAKETARGETS}=join ' ',@ARGV;
42 williamc 1.1 BuildSetup($ENV{THISDIR},@ARGV);
43     # system("$ENV{TOOL_HOME}/BuildSetup",$ENV{THISDIR},@ARGV);
44     }
45    
46     sub project {
47 williamc 1.7 # process options
48     while ( $ARGV[0]=~"^-" ) {
49 williamc 1.23 if ( $ARGV[0]=~/-n/ ) {
50     shift @ARGV;
51     $ENV{devareaname}=shift @ARGV;
52     }
53     if ( $ARGV[0]=~/-d/ ) { #installation area directory
54     shift @ARGV;
55 williamc 1.7 chdir $ARGV[0];
56     shift @ARGV;
57     }
58     }
59 williamc 1.1 my $project=shift @ARGV;
60     my $version=shift @ARGV;
61     environmentinit();
62     use File::Copy;
63 williamc 1.2 use Utilities::AddDir;
64 williamc 1.1
65     use BootStrapProject;
66     # get the bootstrap files downloaded
67     BootStrapProject("$project\?\?$version");
68     # Go setup the rest of the environement, now we can
69 williamc 1.23 chdir $ENV{LOCALTOP};
70     &localtop;
71 williamc 1.1 LoadEnvFile();
72     #
73     # Now create the directories specified in the interface
74     #
75     foreach $key ( keys %ENV ) {
76     if ( $key=~/^INT/ ) {
77 williamc 1.5 AddDir::adddir($ENV{$key});
78 williamc 1.1 }
79     }
80 williamc 1.6 if ( ! -e "$ENV{LOCALTOP}/$ENV{projconfigdir}" ) {
81     system("cp", "-r", "$ENV{RELEASETOP}/$ENV{projconfigdir}",
82     "$ENV{LOCALTOP}/$ENV{projconfigdir}");
83     }
84 williamc 1.1 use clientfile;
85     BuildClientFile( $ENV{SCRAM_ProjReqsDoc} );
86 williamc 1.7 use Cwd;
87 williamc 1.20 print "\nInstallation Procedure Complete. \n".
88     "Installation Located at:\n".cwd()."\n";
89 williamc 1.1 }
90 williamc 1.7
91 williamc 1.1 sub FullEnvInit {
92     environmentinit();
93     localtop();
94     LoadEnvFile();
95     }
96    
97     sub environmentinit {
98 williamc 1.2 use Utilities::setarchitecture;
99 williamc 1.1 my $name;
100     my $value;
101    
102     $ENV{LatestBuildFile}=""; # stop recursive behaviour in make
103 williamc 1.4 setarchitecture::setarch();
104 williamc 1.1 $ENV{INTwork}="tmp/$ENV{SCRAM_ARCH}";
105     $ENV{INTlib}="lib/$ENV{SCRAM_ARCH}";
106     $ENV{INTsrc}="src";
107     $ENV{INTbin}="bin/$ENV{SCRAM_ARCH}";
108     $ENV{INTlog}="logs";
109    
110     if ( ! ( exists $ENV{SCRAM_HOME}) ){
111 williamc 1.8 $ENV{SCRAM_HOME}="/afs/cern.ch/cms/Releases";
112 williamc 1.1 print "Warning : Environment Variable SCRAM_HOME not set.\n";
113     print "Defaulting to $ENV{SCRAM_HOME}\n";
114     }
115     if ( ! ( exists $ENV{SCRAM_CONFIG} ) ){
116 williamc 1.3 $ENV{SCRAM_CONFIG}="$ENV{SCRAM_HOME}/configuration";
117 williamc 1.1 }
118     if ( ! ( exists $ENV{TOOL_HOME} ) ){
119 williamc 1.4 $ENV{TOOL_HOME}="$ENV{SCRAM_HOME}/src";
120 williamc 1.1 }
121     if ( ! ( exists $ENV{SCRAM_LOOKUPDB} ) ){
122     $ENV{SCRAM_LOOKUPDB}="$ENV{SCRAM_CONFIG}/project.lookup";
123     }
124     }
125    
126     sub localtop {
127     # find localtop
128     use Cwd;
129     my $thispath=cwd;
130     block: {
131     do {
132     if ( -e "$thispath/.SCRAM" ) {
133     $ENV{LOCALTOP}=$thispath;
134     last block;
135     }
136     } while ( ( $thispath=~s/(.*)\/.*/$1/ )=~/./ );
137     if ( ! (defined $ENV{LOCALTOP}) ) {
138     print "Unable to locate the top of local release. Exiting\n";
139 williamc 1.18 exit 1;
140 williamc 1.1 }
141     } #end block
142 williamc 1.19 ($ENV{THISDIR}=cwd)=~s/^\Q$ENV{LOCALTOP}\L//;
143 williamc 1.1 $ENV{THISDIR}=~s/^\///;
144     $ENV{SCRAM_WORKDIR}="$ENV{LOCALTOP}/.SCRAM";
145     }
146    
147     sub LoadEnvFile {
148     open ( SCRAMENV, "<$ENV{SCRAM_WORKDIR}/Environment" ) ||
149     die "Cant find Environment file $!\n";
150     while ( <SCRAMENV> ) {
151     chomp;
152     next if /^#/;
153     next if /^\s*$/ ;
154     ($name, $value)=split /=/;
155     eval "\$ENV{${name}}=\"$value\"";
156     }
157     close SCRAMENV;
158     }
159    
160     sub env {
161     print "Sorry - Not yet\n";
162     }
163    
164     #
165     # Create a lookup tag in the site database
166     #
167     sub install ( $tagname, $version ) {
168     my $tagname=shift @ARGV;
169     my $version=shift @ARGV;
170    
171     # create database entry
172     &FullEnvInit;
173     if ( $version eq "" ) {
174     $version=$ENV{SCRAM_PROJVERSION};
175     }
176     if ( $tagname eq "" ) {
177     $tagname=$ENV{SCRAM_PROJECTNAME};
178     }
179     my $filename="$ENV{SCRAM_CONFIG}/project.lookup";
180     my $outfile="$ENV{SCRAM_CONFIG}/project.lookup.tmp";
181     open ( LOCALLOOKUPDB, "<$filename" );
182 williamc 1.16 open ( OUTFILE , ">$outfile" ) or die "Unable to open $outfile $!\n";
183 williamc 1.1 while ( <LOCALLOOKUPDB> ) {
184     if ( /^$tagname/ ) {
185     print "Related tag :".$_."\n";
186     if ( /$version/) {
187     print "$tagname $version already exists. Overwrite (y/n)\n";
188     if ( ! (<STDIN>=~/y/i ) ) {
189     print "Aborting install ...\n";
190     close OUTFILE;
191     close LOCALLOOKUPDB;
192     exit 1;
193     }
194     }
195     else {
196     print OUTFILE $_;
197     }
198     }
199     else {
200     print OUTFILE $_;
201     }
202     }
203     print OUTFILE "$tagname:$version:file:$ENV{LOCALTOP}".
204     "/.SCRAM/InstallFile\n";
205     close OUTFILE;
206     close LOCALLOOKUPDB;
207     copy ( "$outfile", "$filename" )
208     || die "Unable to copy $! \n";
209    
210     }
211    
212     sub help_install() {
213    
214     print <<ENDTEXT;
215     Associates a label with the current release in the SCRAM database.
216     This allows other users to refer to a centrally installed project by
217     this label rather than a remote url reference.
218    
219     Usage:
220    
221     scram install [[label] [version]]
222    
223     label : override default label (the project name of the current release)
224     version : the version tag of the current release. If version is not
225     specified the base release version will be taken by default.
226    
227     ENDTEXT
228     exit;
229     }
230    
231     sub helpheader ($label) {
232     my $label=shift;
233     print <<ENDTEXT;
234     *************************************************************************
235     SCRAM HELP --------- $label
236     *************************************************************************
237     ENDTEXT
238     }
239    
240     sub version {
241     print "Scram version : prototype\n";
242     }
243    
244     sub list {
245     &environmentinit;
246     my $filename="$ENV{SCRAM_CONFIG}/project.lookup";
247     open ( LOCALLOOKUPDB, "<$filename" );
248     print "Installed Projects\n";
249     print "------------------\n";
250     print "|Project Name | Project Version |\n";
251     print "----------------------------------\n";
252     while ( <LOCALLOOKUPDB> ) {
253     ( $name, $version, $type, $url ) = split ":", $_;
254     printf "%1s",$name;
255     printf "%25s\n",$version;
256     printf "--> %25s\n",$type.":".$url;
257     }
258     close LOCALLOOKUPDB;
259     }
260    
261     sub arch {
262     &environmentinit();
263     print "$ENV{SCRAM_ARCH}\n";
264 williamc 1.11 }
265    
266 williamc 1.12
267     #
268     # Setup a new tool
269     #
270    
271     sub setup {
272     my $toolname=shift @ARGV;
273    
274     &FullEnvInit;
275     if ( $ENV{SCRAM_BootStrapFiles}!~/$ENV{LOCALTOP}\/\.SCRAM/ ) {
276     $ENV{SCRAM_BootStrapFiles}="$ENV{LOCALTOP}/.SCRAM:".
277     $ENV{SCRAM_BootStrapFiles};
278     }
279 williamc 1.20 # If no toolname specified then its a full setup
280     if ( $toolname eq "" ) {
281     my $filebase="$ENV{LOCALTOP}/.SCRAM/$ENV{SCRAM_ARCH}";
282     rename "$filebase/clientsettings", "$filebase/clientsettings.old";
283     rename "$filebase/clientsettings_reqs",
284     "$filebase/clientsettings_reqs.old";
285     use clientfile;
286     BuildClientFile( $ENV{SCRAM_ProjReqsDoc} );
287     }
288     else {
289     # Check for the correct toolfile
290     # ideally try and download it if not already in .SCRAM
291     # Only scram toolbox files supported so far
292     if ( ! -e "$ENV{LOCALTOP}/.SCRAM/$toolname" ) {
293 williamc 1.12 &urlhandler::urlhandler("file:$ENV{SCRAM_HOME}/toolbox/"
294     .$toolname, "$ENV{LOCALTOP}/.SCRAM/$toolname") ;
295 williamc 1.20 }
296     # Parse the toolfile and update the clientsettings file
297     # currently just append to the end
298     use clientfile;
299     clientfile::openclientfile('add');
300     clientfile::_tool("file:$toolname");
301     closeclientfile;
302 williamc 1.12 }
303     }
304    
305 williamc 1.13 sub help_setup {
306 williamc 1.12
307     print <<ENDTEXT;
308 williamc 1.14 Allows installation of a new tool/external package into an already
309 williamc 1.20 existing area. If not toolname is specified, the complete installation
310     process is initiated.
311 williamc 1.12
312     Usage:
313    
314 williamc 1.20 $bold scram setup $normal [toolname]
315 williamc 1.12
316     toolname : The name of the tool setup file required.
317     ENDTEXT
318     exit;
319 williamc 1.13 }
320    
321     sub help_list {
322     print <<ENDTEXT;
323     Create an entry in the SCRAM database so that an installed project can be
324     referenced in the 'project' command by a tag/version combination.
325     Usage: (command to be issued from inside an installed project)
326    
327 williamc 1.14 $bold scram install $normal [project_tag [version_tag]]
328 williamc 1.13
329     If not specified the project_tag and version_tag default to the project
330     name and version of the installation.
331     ENDTEXT
332     exit;
333     }
334     sub help_project {
335     print <<ENDTEXT;
336     Setup a new project development area. The new area will appear in the current
337     working directory.
338     Usage:
339    
340     $bold scram project [-d install_area] $normal project_url [project_version]
341    
342     Options:
343    
344     project_url: The url of a scram bootstrap file.
345     Currently supported types are:
346     $bold Database label $normal
347     Labels can be assigned to bootstrap files for easy
348     access (See "scram install" command). If you
349     specify a label you must also specify a project_version.
350     e.g.
351    
352     scram project SCRAM V1_0
353    
354     scram project ORCA ORCA_1_1_1
355    
356     To see the list of installed projects use the
357     "scram list" command.
358    
359     $bold file: $normal A regular file on an accessable file system
360     e.g.
361    
362     file:~/myprojects/projecta/config/BootStrapFile
363    
364     project_version:
365     Only for use with a database label
366    
367     -d install_area:
368     Indicate a project installation area into which the new
369     project area should appear. Default is the current working
370     directory.
371    
372 williamc 1.14 ENDTEXT
373     }
374    
375     sub help_version {
376     print <<ENDTEXT;
377     Print the version number of scram
378     Usage:
379     $bold scram version $normal
380    
381     ENDTEXT
382     }
383    
384     sub help_arch {
385     print <<ENDTEXT;
386     Print out the architecture flag for the current machine.
387    
388     Usage:
389     $bold scram arch $normal
390 williamc 1.13 ENDTEXT
391 williamc 1.1 }