7 |
|
# ----------- |
8 |
|
# creates and manages a configuration area |
9 |
|
# |
10 |
< |
# Options |
10 |
> |
# Notes |
11 |
|
# ------- |
12 |
< |
# ConfigArea_location |
13 |
< |
# ConfigArea_name |
12 |
> |
# Persistency - remember to call the save method to make changes persistent |
13 |
|
# |
14 |
|
# Interface |
15 |
|
# --------- |
16 |
|
# new() : A new ConfigArea object |
17 |
+ |
# name() : get/set project name |
18 |
+ |
# setup(dir[,areaname]) : setup a fresh area in dir |
19 |
+ |
# satellite(dir[,areaname]) : setup a satellite area in dir |
20 |
+ |
# version() : get/set project version |
21 |
|
# location([dir]) : set/return the location of the work area |
22 |
|
# bootstrapfromlocation([location]) : bootstrap the object based on location. |
23 |
|
# no location specified - cwd used |
24 |
|
# return 0 if succesful 1 otherwise |
25 |
+ |
# requirementsdoc() : get set the requirements doc |
26 |
|
# searchlocation([startdir]) : returns the location directory. search starts |
27 |
|
# from cwd if not specified |
24 |
– |
# defaultdirname() : return the default directory name string |
28 |
|
# scramversion() : return the scram version associated with |
29 |
|
# area |
30 |
|
# configurationdir() : return the location of the project |
33 |
|
# copysetup(location) : copy the architecture specific tool setup |
34 |
|
# returns 0 if successful, 1 otherwise |
35 |
|
# copyenv($ref) : copy the areas environment into the hashref |
36 |
+ |
# toolbox() : return the areas toolbox object |
37 |
+ |
# save() : save changes permanently |
38 |
+ |
# linkto(location) : link the current area to that at location |
39 |
+ |
# unlinkarea() : destroy link (autosave) |
40 |
+ |
# linkarea([ConfigArea]) : link the current area to the apec Area Object |
41 |
+ |
# - temporary |
42 |
+ |
# align() : adjust hard paths to suit local loaction |
43 |
|
|
44 |
|
package Configuration::ConfigArea; |
45 |
|
require 5.004; |
46 |
+ |
use URL::URLcache; |
47 |
|
use Utilities::AddDir; |
48 |
|
use Utilities::Verbose; |
49 |
|
use Cwd; |
56 |
|
|
57 |
|
# data init |
58 |
|
$self->{admindir}=".SCRAM"; |
59 |
+ |
$self->{cachedir}="cache"; |
60 |
+ |
undef $self->{linkarea}; |
61 |
|
|
62 |
|
return $self; |
63 |
|
} |
64 |
|
|
65 |
+ |
sub cache { |
66 |
+ |
my $self=shift; |
67 |
+ |
if ( @_ ) { |
68 |
+ |
$self->{cache}=shift; |
69 |
+ |
} |
70 |
+ |
elsif ( ! defined $self->{cache} ) { |
71 |
+ |
my $loc=$self->location()."/".$self->{admindir}."/".$self->{cachedir}; |
72 |
+ |
$self->{cache}=URL::URLcache->new($loc); |
73 |
+ |
} |
74 |
+ |
return $self->{cache}; |
75 |
+ |
} |
76 |
+ |
|
77 |
+ |
sub name { |
78 |
+ |
my $self=shift; |
79 |
+ |
@_?$self->{name}=shift |
80 |
+ |
:$self->{name}; |
81 |
+ |
} |
82 |
+ |
|
83 |
+ |
sub version { |
84 |
+ |
my $self=shift; |
85 |
+ |
@_?$self->{version}=shift |
86 |
+ |
:$self->{version}; |
87 |
+ |
} |
88 |
+ |
|
89 |
+ |
sub setup { |
90 |
+ |
my $self=shift; |
91 |
+ |
my $location=shift; |
92 |
+ |
my $areaname; |
93 |
+ |
|
94 |
+ |
# -- check we have a project name and version |
95 |
+ |
my $name=$self->name(); |
96 |
+ |
my $vers=$self->version(); |
97 |
+ |
if ( ( ! defined $name ) && ( ! defined $version )) { |
98 |
+ |
$self->error("Set ConfigArea name and version before setup"); |
99 |
+ |
} |
100 |
+ |
|
101 |
+ |
# -- check arguments and set location |
102 |
+ |
if ( ! defined $location ) { |
103 |
+ |
$self->error("ConfigArea: Cannot setup new area without a location"); |
104 |
+ |
} |
105 |
+ |
if ( @_ ) { |
106 |
+ |
$areaname=shift; |
107 |
+ |
} |
108 |
+ |
if ( (! defined $areaname) || ( $areaname eq "" ) ) { |
109 |
+ |
# -- make up a name from the project name and version |
110 |
+ |
$vers=~s/^$name\_//; |
111 |
+ |
$areaname=$name."_".$vers; |
112 |
+ |
} |
113 |
+ |
my $arealoc=$location."/".$areaname; |
114 |
+ |
my $workloc=$arealoc."/".$self->{admindir}; |
115 |
+ |
$self->verbose("Building at $arealoc"); |
116 |
+ |
$self->location($arealoc); |
117 |
+ |
|
118 |
+ |
# -- create top level structure and work area |
119 |
+ |
AddDir::adddir($workloc); |
120 |
+ |
|
121 |
+ |
# -- add a cache |
122 |
+ |
$self->cache(); |
123 |
+ |
|
124 |
+ |
# -- Save Environment File |
125 |
+ |
$self->_SaveEnvFile(); |
126 |
+ |
|
127 |
+ |
} |
128 |
+ |
|
129 |
|
sub configurationdir { |
130 |
|
my $self=shift; |
131 |
|
if ( @_ ) { |
132 |
|
$self->{configurationdir}=shift; |
133 |
|
} |
134 |
< |
if ( ! defined $self->{configurationdir} ) { |
135 |
< |
$self->_LoadEnvFile(); |
136 |
< |
$self->{configurationdir}=$self->{ENV}{projconfigdir}; |
134 |
> |
return (defined $self->{configurationdir})?$self->{configurationdir}:undef; |
135 |
> |
} |
136 |
> |
|
137 |
> |
sub toolbox { |
138 |
> |
my $self=shift; |
139 |
> |
if ( ! defined $self->{toolbox} ) { |
140 |
> |
$self->{toolbox}=BuildSystem::ToolBox->new($self); |
141 |
> |
} |
142 |
> |
return $self->{toolbox}; |
143 |
> |
} |
144 |
> |
|
145 |
> |
sub requirementsdoc { |
146 |
> |
my $self=shift; |
147 |
> |
if ( @_ ) { |
148 |
> |
$self->{reqdoc}=shift; |
149 |
> |
} |
150 |
> |
if ( defined $self->{reqdoc} ) { |
151 |
> |
return $self->location()."/".$self->{reqdoc}; |
152 |
> |
} |
153 |
> |
else { |
154 |
> |
return undef; |
155 |
|
} |
61 |
– |
return $self->{configurationdir}; |
156 |
|
} |
157 |
|
|
158 |
|
sub scramversion { |
219 |
|
|
220 |
|
my $rv=0; |
221 |
|
|
128 |
– |
print $thispath." --not shortened\n"; |
222 |
|
# chop off any files - we only want dirs |
223 |
|
if ( -f $thispath ) { |
224 |
|
$thispath=~s/(.*)\/.*/$1/; |
132 |
– |
print $thispath." --shortened\n"; |
225 |
|
} |
226 |
|
Sloop:{ |
227 |
|
do { |
236 |
|
return $rv?$thispath:undef; |
237 |
|
} |
238 |
|
|
239 |
+ |
sub satellite { |
240 |
+ |
my $self=shift; |
241 |
+ |
|
242 |
+ |
# -- create the sat object |
243 |
+ |
my $sat=Configuration::ConfigArea->new(); |
244 |
+ |
$sat->name($self->name()); |
245 |
+ |
$sat->version($self->version()); |
246 |
+ |
$sat->requirementsdoc($self->{reqdoc}); |
247 |
+ |
$sat->configurationdir($self->configurationdir()); |
248 |
+ |
$sat->setup(@_); |
249 |
+ |
|
250 |
+ |
# -- copy across the cache |
251 |
+ |
copy($self->cache()->location(),$sat->cache()->location()); |
252 |
+ |
# and make sure in reinitialises |
253 |
+ |
undef ($sat->{cache}); |
254 |
+ |
|
255 |
+ |
# -- link it to this area |
256 |
+ |
$sat->linkarea($self); |
257 |
+ |
|
258 |
+ |
} |
259 |
+ |
|
260 |
|
sub copy { |
261 |
|
my $self=shift; |
262 |
|
my $destination=shift; |
266 |
|
AddDir::copydir($temp,"$destination/".$self->{admindir}); |
267 |
|
} |
268 |
|
|
269 |
+ |
sub align { |
270 |
+ |
my $self=shift; |
271 |
+ |
use File::Copy; |
272 |
+ |
|
273 |
+ |
$self->_LoadEnvFile(); |
274 |
+ |
my $Envfile=$self->location()."/".$self->{admindir}."/Environment"; |
275 |
+ |
my $tmpEnvfile=$Envfile.".bak"; |
276 |
+ |
my $rel=$self->{ENV}{RELEASETOP}; |
277 |
+ |
my $local=$self->location(); |
278 |
+ |
|
279 |
+ |
rename( $Envfile, $tmpEnvfile ); |
280 |
+ |
use FileHandle; |
281 |
+ |
my $fh=FileHandle->new(); |
282 |
+ |
my $fout=FileHandle->new(); |
283 |
+ |
open ( $fh, "<".$tmpEnvfile ) or |
284 |
+ |
$self->error("Cannot find Environment file. Area Corrupted? (" |
285 |
+ |
.$self->location().")\n $!"); |
286 |
+ |
open ( $fout, ">".$Envfile ) or |
287 |
+ |
$self->error("Cannot find Environment file. Area Corrupted? (" |
288 |
+ |
.$self->location().")\n $!"); |
289 |
+ |
while ( <$fh> ) { |
290 |
+ |
$_=~s/\Q$rel\L/$local/g; |
291 |
+ |
print $fout $_; |
292 |
+ |
} |
293 |
+ |
undef $fh; |
294 |
+ |
undef $fout; |
295 |
+ |
} |
296 |
+ |
|
297 |
|
sub copysetup { |
298 |
|
my $self=shift; |
299 |
|
my $dest=shift; |
325 |
|
return $ENV{SCRAM_ARCH}; |
326 |
|
} |
327 |
|
|
328 |
+ |
sub linkto { |
329 |
+ |
my $self=shift; |
330 |
+ |
my $location=shift; |
331 |
+ |
if ( -d $location ) { |
332 |
+ |
my $area=Configuration::ConfigArea->new(); |
333 |
+ |
$area->bootstrapfromlocation($location); |
334 |
+ |
$self->linkarea($area); |
335 |
+ |
} |
336 |
+ |
else { |
337 |
+ |
$self->error("ConfigArea : Unable to link to non existing directory ". |
338 |
+ |
$location); |
339 |
+ |
} |
340 |
+ |
} |
341 |
+ |
|
342 |
+ |
sub unlinkarea { |
343 |
+ |
my $self=shift; |
344 |
+ |
undef $self->{linkarea}; |
345 |
+ |
$self->{linkarea}=undef; |
346 |
+ |
$self->save(); |
347 |
+ |
} |
348 |
+ |
|
349 |
+ |
sub linkarea { |
350 |
+ |
my $self=shift; |
351 |
+ |
my $area=shift; |
352 |
+ |
if ( defined $area ) { |
353 |
+ |
$self->{linkarea}=$area; |
354 |
+ |
} |
355 |
+ |
return (defined $self->{linkarea} && $self->{linkarea} ne "")? |
356 |
+ |
$self->{linkarea}:undef; |
357 |
+ |
} |
358 |
+ |
|
359 |
+ |
sub save { |
360 |
+ |
my $self=shift; |
361 |
+ |
$self->_SaveEnvFile(); |
362 |
+ |
} |
363 |
+ |
|
364 |
|
# ---- support routines |
365 |
+ |
|
366 |
+ |
sub _SaveEnvFile { |
367 |
+ |
my $self=shift; |
368 |
+ |
use FileHandle; |
369 |
+ |
my $fh=FileHandle->new(); |
370 |
+ |
open ( $fh, ">".$self->location()."/".$self->{admindir}."/". |
371 |
+ |
"Environment" ) or |
372 |
+ |
$self->error("Cannot Open Environment file to Save (" |
373 |
+ |
.$self->location().")\n $!"); |
374 |
+ |
|
375 |
+ |
print $fh "SCRAM_PROJECTNAME=".$self->name()."\n"; |
376 |
+ |
print $fh "SCRAM_PROJECTVERSION=".$self->version()."\n"; |
377 |
+ |
print $fh "projconfigdir=".$self->configurationdir()."\n"; |
378 |
+ |
print $fh "SCRAM_ProjReqsDoc=".$self->{reqdoc}."\n"; |
379 |
+ |
if ( defined $self->linkarea() ) { |
380 |
+ |
my $area=$self->linkarea()->location(); |
381 |
+ |
if ( $area ne "" ) { |
382 |
+ |
print $fh "RELEASETOP=".$area."\n"; |
383 |
+ |
} |
384 |
+ |
} |
385 |
+ |
undef $fh; |
386 |
+ |
} |
387 |
+ |
|
388 |
+ |
|
389 |
|
sub _LoadEnvFile { |
390 |
|
my $self=shift; |
391 |
|
|
403 |
|
eval "\$self->{ENV}{${name}}=\"$value\""; |
404 |
|
} |
405 |
|
undef $fh; |
406 |
< |
} |
407 |
< |
|
408 |
< |
sub _savevar { |
409 |
< |
my $self=shift; |
410 |
< |
my $fh=shift; |
411 |
< |
my $name=shift; |
412 |
< |
my $val=shift; |
413 |
< |
print $fh "#".$name."\n"; |
414 |
< |
print $fh $val."\n"; |
415 |
< |
} |
416 |
< |
|
417 |
< |
sub _restorevars { |
418 |
< |
my $self=shift; |
419 |
< |
my $fh=shift; |
420 |
< |
my $varhash=shift; |
421 |
< |
|
422 |
< |
while ( <$fh>=~/^#(.*)/ ) { |
423 |
< |
$name=$1; |
424 |
< |
chomp $name; |
425 |
< |
$value=<$fh>; |
426 |
< |
chomp $value; |
226 |
< |
$$varhash{$name}=$value; |
227 |
< |
#print "Restoring ".$name."=".$value."\n"; |
228 |
< |
} |
406 |
> |
|
407 |
> |
# -- set internal variables appropriately |
408 |
> |
if ( defined $self->{ENV}{"SCRAM_PROJECTNAME"} ) { |
409 |
> |
$self->name($self->{ENV}{"SCRAM_PROJECTNAME"}); |
410 |
> |
} |
411 |
> |
if ( defined $self->{ENV}{"SCRAM_PROJECTVERSION"} ) { |
412 |
> |
$self->version($self->{ENV}{"SCRAM_PROJECTVERSION"}); |
413 |
> |
} |
414 |
> |
if ( defined $self->{ENV}{"projconfigdir"} ) { |
415 |
> |
$self->configurationdir($self->{ENV}{projconfigdir}); |
416 |
> |
} |
417 |
> |
if ( defined $self->{ENV}{"SCRAM_ProjReqsDoc"} ) { |
418 |
> |
$self->requirementsdoc($self->{ENV}{SCRAM_ProjReqsDoc}); |
419 |
> |
} |
420 |
> |
if ( ( defined $self->{ENV}{"RELEASETOP"} ) && |
421 |
> |
($self->{ENV}{"RELEASETOP"} ne $self->location())) { |
422 |
> |
$self->linkto($self->{ENV}{"RELEASETOP"}); |
423 |
> |
} |
424 |
> |
else { |
425 |
> |
$self->{ENV}{"RELEASETOP"}=$self->location(); |
426 |
> |
} |
427 |
|
} |