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