1 |
williamc |
1.1 |
package Configuration::ConfigArea;
|
2 |
|
|
require 5.004;
|
3 |
|
|
use Utilities::AddDir;
|
4 |
williamc |
1.14 |
use Utilities::Verbose;
|
5 |
williamc |
1.6 |
use Cwd;
|
6 |
williamc |
1.14 |
@ISA=qw(Utilities::Verbose);
|
7 |
williamc |
1.1 |
|
8 |
williamc |
1.14 |
sub new {
|
9 |
muzaffar |
1.33 |
my $class=shift;
|
10 |
|
|
my $self={};
|
11 |
|
|
bless $self, $class;
|
12 |
|
|
$self->{admindir}=".SCRAM";
|
13 |
muzaffar |
1.36 |
$self->{configurationdir} = "config";
|
14 |
muzaffar |
1.37 |
$self->archname($ENV{SCRAM_ARCH});
|
15 |
muzaffar |
1.33 |
return $self;
|
16 |
williamc |
1.1 |
}
|
17 |
|
|
|
18 |
sashby |
1.23 |
sub toolcachename
|
19 |
|
|
{
|
20 |
|
|
my $self=shift;
|
21 |
muzaffar |
1.36 |
return ($self->archdir()."/ToolCache.db.gz");
|
22 |
sashby |
1.23 |
}
|
23 |
|
|
|
24 |
|
|
sub projectcachename
|
25 |
|
|
{
|
26 |
|
|
my $self=shift;
|
27 |
muzaffar |
1.36 |
return ($self->archdir()."/ProjectCache.db.gz");
|
28 |
sashby |
1.23 |
}
|
29 |
|
|
|
30 |
muzaffar |
1.36 |
sub symlinks {
|
31 |
williamc |
1.19 |
my $self=shift;
|
32 |
muzaffar |
1.36 |
if (@_) {$self->{symlinks}=shift;}
|
33 |
|
|
return $self->{symlinks};
|
34 |
williamc |
1.18 |
}
|
35 |
|
|
|
36 |
muzaffar |
1.36 |
sub calchksum {
|
37 |
|
|
my $self=shift;
|
38 |
|
|
my $dir=$self->location()."/".$self->configurationdir();
|
39 |
|
|
push @INC,$dir;
|
40 |
|
|
require SCRAM::Plugins::ProjectChkSum;
|
41 |
|
|
my $sum=&SCRAM::Plugins::ProjectChkSum::chksum($dir);
|
42 |
|
|
pop @INC;
|
43 |
|
|
return $sum;
|
44 |
williamc |
1.19 |
}
|
45 |
williamc |
1.18 |
|
46 |
muzaffar |
1.36 |
sub configchksum {
|
47 |
williamc |
1.19 |
my $self=shift;
|
48 |
muzaffar |
1.36 |
if (@_) {$self->{configchksum}=shift;}
|
49 |
|
|
return $self->{configchksum};
|
50 |
williamc |
1.9 |
}
|
51 |
|
|
|
52 |
muzaffar |
1.34 |
|
53 |
williamc |
1.14 |
sub name {
|
54 |
williamc |
1.9 |
my $self=shift;
|
55 |
williamc |
1.14 |
@_?$self->{name}=shift
|
56 |
|
|
:$self->{name};
|
57 |
williamc |
1.9 |
}
|
58 |
williamc |
1.7 |
|
59 |
williamc |
1.14 |
sub version {
|
60 |
williamc |
1.6 |
my $self=shift;
|
61 |
williamc |
1.14 |
@_?$self->{version}=shift
|
62 |
|
|
:$self->{version};
|
63 |
williamc |
1.9 |
}
|
64 |
williamc |
1.8 |
|
65 |
williamc |
1.1 |
sub setup {
|
66 |
|
|
my $self=shift;
|
67 |
williamc |
1.14 |
my $location=shift;
|
68 |
muzaffar |
1.36 |
my $areaname=shift || undef;
|
69 |
|
|
my $symlinks=shift || 0;
|
70 |
|
|
my $locarea = shift || undef;
|
71 |
williamc |
1.14 |
if ( (! defined $areaname) || ( $areaname eq "" ) ) {
|
72 |
muzaffar |
1.36 |
$areaname=$self->version();
|
73 |
williamc |
1.1 |
}
|
74 |
muzaffar |
1.36 |
$self->location($location."/".$areaname);
|
75 |
muzaffar |
1.34 |
$self->symlinks($symlinks);
|
76 |
muzaffar |
1.36 |
if ($self->configchksum() ne "")
|
77 |
|
|
{
|
78 |
|
|
if ((!-defined $locarea) && (-f "${location}/${areaname}/".$self->admindir()."/Environment"))
|
79 |
|
|
{
|
80 |
muzaffar |
1.37 |
$locarea=Configuration::ConfigArea->new();
|
81 |
muzaffar |
1.36 |
$locarea->bootstrapfromlocation("${location}/${areaname}");
|
82 |
|
|
}
|
83 |
|
|
if ((defined $locarea) && ($locarea->configchksum() != $self->configchksum()))
|
84 |
|
|
{
|
85 |
muzaffar |
1.37 |
print "ERROR: Can not setup your current working area for SCRAM_ARCH:$ENV{SCRAM_ARCH}.\n",
|
86 |
muzaffar |
1.36 |
"Your current development area ${location}/${areaname}\n",
|
87 |
|
|
"is using a different ${areaname}/config then the one used for\n",
|
88 |
|
|
$self->releasetop(),".\n";
|
89 |
|
|
exit 1;
|
90 |
|
|
}
|
91 |
|
|
}
|
92 |
|
|
Utilities::AddDir::adddir($self->archdir());
|
93 |
williamc |
1.9 |
}
|
94 |
|
|
|
95 |
williamc |
1.14 |
sub configurationdir {
|
96 |
williamc |
1.9 |
my $self=shift;
|
97 |
williamc |
1.14 |
if ( @_ ) {
|
98 |
|
|
$self->{configurationdir}=shift;
|
99 |
|
|
}
|
100 |
|
|
return (defined $self->{configurationdir})?$self->{configurationdir}:undef;
|
101 |
williamc |
1.9 |
}
|
102 |
|
|
|
103 |
sashby |
1.23 |
sub sourcedir {
|
104 |
|
|
my $self=shift;
|
105 |
|
|
if ( @_ ) {
|
106 |
|
|
$self->{sourcedir}=shift;
|
107 |
|
|
}
|
108 |
|
|
return (defined $self->{sourcedir})?$self->{sourcedir}:undef;
|
109 |
|
|
}
|
110 |
|
|
|
111 |
muzaffar |
1.36 |
sub releasetop {
|
112 |
williamc |
1.5 |
my $self=shift;
|
113 |
williamc |
1.14 |
if ( @_ ) {
|
114 |
muzaffar |
1.36 |
$self->{releasetop}=shift;
|
115 |
williamc |
1.14 |
}
|
116 |
muzaffar |
1.36 |
return (defined $self->{releasetop})?$self->{releasetop}:undef;
|
117 |
williamc |
1.1 |
}
|
118 |
|
|
|
119 |
sashby |
1.29 |
sub admindir()
|
120 |
|
|
{
|
121 |
|
|
my $self=shift;
|
122 |
|
|
|
123 |
|
|
@_ ? $self->{admindir} = shift
|
124 |
|
|
: $self->{admindir};
|
125 |
|
|
}
|
126 |
sashby |
1.21 |
|
127 |
williamc |
1.14 |
sub bootstrapfromlocation {
|
128 |
williamc |
1.1 |
my $self=shift;
|
129 |
muzaffar |
1.36 |
my $location = $self->searchlocation(shift);
|
130 |
williamc |
1.14 |
my $rv=0;
|
131 |
muzaffar |
1.36 |
if ( ! defined $location) {
|
132 |
williamc |
1.14 |
$rv=1;
|
133 |
williamc |
1.9 |
}
|
134 |
|
|
else {
|
135 |
williamc |
1.14 |
$self->location($location);
|
136 |
|
|
$self->_LoadEnvFile();
|
137 |
williamc |
1.9 |
}
|
138 |
williamc |
1.14 |
return $rv;
|
139 |
williamc |
1.1 |
}
|
140 |
|
|
|
141 |
|
|
sub location {
|
142 |
|
|
my $self=shift;
|
143 |
|
|
|
144 |
williamc |
1.5 |
if ( @_ ) {
|
145 |
williamc |
1.6 |
$self->{location}=shift;
|
146 |
muzaffar |
1.37 |
$self->archname($ENV{SCRAM_ARCH});
|
147 |
williamc |
1.5 |
}
|
148 |
|
|
elsif ( ! defined $self->{location} ) {
|
149 |
|
|
# try and find the release location
|
150 |
williamc |
1.9 |
$self->{location}=$self->searchlocation();
|
151 |
muzaffar |
1.36 |
if (defined $self->{location})
|
152 |
|
|
{
|
153 |
muzaffar |
1.37 |
$self->archname($ENV{SCRAM_ARCH});
|
154 |
muzaffar |
1.36 |
}
|
155 |
williamc |
1.5 |
}
|
156 |
|
|
return $self->{location};
|
157 |
|
|
}
|
158 |
|
|
|
159 |
|
|
sub searchlocation {
|
160 |
|
|
my $self=shift;
|
161 |
sashby |
1.20 |
|
162 |
williamc |
1.5 |
#start search in current directory if not specified
|
163 |
|
|
my $thispath;
|
164 |
williamc |
1.14 |
if ( @_ ) {
|
165 |
|
|
$thispath=shift
|
166 |
|
|
}
|
167 |
|
|
else {
|
168 |
|
|
$thispath=cwd();
|
169 |
|
|
}
|
170 |
sashby |
1.20 |
|
171 |
williamc |
1.5 |
my $rv=0;
|
172 |
|
|
|
173 |
williamc |
1.14 |
# chop off any files - we only want dirs
|
174 |
|
|
if ( -f $thispath ) {
|
175 |
|
|
$thispath=~s/(.*)\/.*/$1/;
|
176 |
|
|
}
|
177 |
williamc |
1.6 |
Sloop:{
|
178 |
|
|
do {
|
179 |
williamc |
1.14 |
$self->verbose("Searching $thispath");
|
180 |
williamc |
1.8 |
if ( -e "$thispath/".$self->{admindir} ) {
|
181 |
williamc |
1.14 |
$self->verbose("Found\n");
|
182 |
williamc |
1.5 |
$rv=1;
|
183 |
williamc |
1.6 |
last Sloop;
|
184 |
williamc |
1.5 |
}
|
185 |
williamc |
1.6 |
} while ( ($thispath=~s/(.*)\/.*/$1/)=~/./ ) };
|
186 |
sashby |
1.20 |
|
187 |
williamc |
1.5 |
return $rv?$thispath:undef;
|
188 |
williamc |
1.1 |
}
|
189 |
|
|
|
190 |
williamc |
1.14 |
sub archname {
|
191 |
williamc |
1.1 |
my $self=shift;
|
192 |
williamc |
1.14 |
if ( @_ ) {
|
193 |
muzaffar |
1.36 |
if (defined $self->{location}) {
|
194 |
muzaffar |
1.37 |
$self->archdir($self->{location}."/".$self->{admindir}."/".$ENV{SCRAM_ARCH});
|
195 |
muzaffar |
1.36 |
}
|
196 |
williamc |
1.14 |
}
|
197 |
muzaffar |
1.37 |
return $ENV{SCRAM_ARCH};
|
198 |
williamc |
1.14 |
}
|
199 |
williamc |
1.1 |
|
200 |
williamc |
1.14 |
sub archdir {
|
201 |
|
|
my $self=shift;
|
202 |
|
|
if ( @_ ) {
|
203 |
|
|
$self->{archdir}=shift;
|
204 |
|
|
}
|
205 |
|
|
return $self->{archdir};
|
206 |
williamc |
1.1 |
}
|
207 |
|
|
|
208 |
williamc |
1.14 |
sub satellite {
|
209 |
williamc |
1.1 |
my $self=shift;
|
210 |
muzaffar |
1.36 |
my $relloc = $self->location();
|
211 |
muzaffar |
1.37 |
my $sat=Configuration::ConfigArea->new();
|
212 |
williamc |
1.14 |
$sat->name($self->name());
|
213 |
|
|
$sat->version($self->version());
|
214 |
|
|
$sat->configurationdir($self->configurationdir());
|
215 |
sashby |
1.23 |
$sat->sourcedir($self->sourcedir());
|
216 |
muzaffar |
1.36 |
$sat->releasetop($relloc);
|
217 |
|
|
$sat->configchksum($self->configchksum());
|
218 |
williamc |
1.14 |
$sat->setup(@_);
|
219 |
muzaffar |
1.36 |
$self->copywithskip($self->archdir(),$sat->archdir(),["InstalledTools","ProjectCache.db.gz","RuntimeCache.db.gz","DirCache.db.gz","MakeData/DirCache","MakeData/DirCache.mk","MakeData/src.mk"]);
|
220 |
|
|
$envfile = $sat->archdir()."/Environment";
|
221 |
|
|
open ( $fh, "> $envfile" ) or $sat->error("Cannot Open \"$envfile\" file to Save\n $!");
|
222 |
|
|
print $fh "RELEASETOP=$relloc\n";
|
223 |
|
|
close($fh);
|
224 |
|
|
my $devconf = $sat->location()."/".$sat->configurationdir();
|
225 |
|
|
my $relconf = $self->location()."/".$self->configurationdir();
|
226 |
|
|
if (!-d $devconf)
|
227 |
|
|
{
|
228 |
|
|
$self->copywithskip($relconf,$devconf,['toolbox']);
|
229 |
|
|
}
|
230 |
|
|
$envfile = $sat->location()."/".$self->{admindir}."/Environment";
|
231 |
|
|
if (! -f $envfile)
|
232 |
|
|
{
|
233 |
|
|
$sat->save ();
|
234 |
|
|
}
|
235 |
muzaffar |
1.37 |
Utilities::AddDir::copydir("${relconf}/toolbox/$ENV{SCRAM_ARCH}","${devconf}/toolbox/$ENV{SCRAM_ARCH}");
|
236 |
muzaffar |
1.36 |
Utilities::AddDir::adddir ($sat->location()."/".$sat->sourcedir());
|
237 |
williamc |
1.14 |
return $sat;
|
238 |
williamc |
1.1 |
}
|
239 |
|
|
|
240 |
sashby |
1.24 |
sub copywithskip {
|
241 |
|
|
my $self=shift;
|
242 |
muzaffar |
1.36 |
my $src=shift;
|
243 |
|
|
my $des=shift;
|
244 |
|
|
my $filetoskip=shift || [];
|
245 |
williamc |
1.14 |
my $rv=1;
|
246 |
muzaffar |
1.36 |
if ( $src ne $des )
|
247 |
|
|
{
|
248 |
|
|
if ( -d $src )
|
249 |
|
|
{
|
250 |
|
|
my $fs=[];
|
251 |
|
|
foreach my $f (@$filetoskip) {push @$fs,"${src}/${f}";}
|
252 |
|
|
Utilities::AddDir::copydirwithskip($src,$des,$fs);
|
253 |
|
|
$rv=0;
|
254 |
|
|
}
|
255 |
|
|
}
|
256 |
williamc |
1.14 |
return $rv;
|
257 |
williamc |
1.9 |
}
|
258 |
|
|
|
259 |
williamc |
1.14 |
sub copyenv {
|
260 |
williamc |
1.9 |
my $self=shift;
|
261 |
williamc |
1.14 |
my $hashref=shift;
|
262 |
|
|
|
263 |
|
|
foreach $elem ( keys %{$self->{ENV}} ) {
|
264 |
|
|
$$hashref{$elem}=$self->{ENV}{$elem};
|
265 |
williamc |
1.9 |
}
|
266 |
|
|
}
|
267 |
|
|
|
268 |
williamc |
1.14 |
sub arch {
|
269 |
williamc |
1.9 |
my $self=shift;
|
270 |
muzaffar |
1.37 |
return $ENV{SCRAM_ARCH};
|
271 |
williamc |
1.1 |
}
|
272 |
|
|
|
273 |
williamc |
1.14 |
sub save {
|
274 |
williamc |
1.1 |
my $self=shift;
|
275 |
williamc |
1.14 |
$self->_SaveEnvFile();
|
276 |
williamc |
1.1 |
}
|
277 |
|
|
|
278 |
williamc |
1.14 |
# ---- support routines
|
279 |
williamc |
1.1 |
|
280 |
sashby |
1.25 |
sub _SaveEnvFile
|
281 |
|
|
{
|
282 |
|
|
my $self=shift;
|
283 |
|
|
|
284 |
muzaffar |
1.36 |
my $fh;
|
285 |
|
|
my $envfile = $self->location()."/".$self->{admindir}."/Environment";
|
286 |
|
|
open ( $fh, "> $envfile" ) or $self->error("Cannot Open \"$envfile\" file to Save\n $!");
|
287 |
williamc |
1.14 |
|
288 |
sashby |
1.25 |
print $fh "SCRAM_PROJECTNAME=".$self->name()."\n";
|
289 |
|
|
print $fh "SCRAM_PROJECTVERSION=".$self->version()."\n";
|
290 |
|
|
print $fh "SCRAM_CONFIGDIR=".$self->configurationdir()."\n";
|
291 |
|
|
print $fh "SCRAM_SOURCEDIR=".$self->sourcedir()."\n";
|
292 |
muzaffar |
1.36 |
print $fh "SCRAM_SYMLINKS=",$self->symlinks(),"\n";
|
293 |
|
|
print $fh "SCRAM_CONFIGCHKSUM=",$self->configchksum(),"\n";
|
294 |
|
|
close($fh);
|
295 |
williamc |
1.9 |
|
296 |
sashby |
1.25 |
# Set the default permissions (-rw-r--r--):
|
297 |
muzaffar |
1.36 |
my $filemode = 0644;
|
298 |
sashby |
1.25 |
chmod $filemode, $self->location()."/".$self->{admindir}."/Environment";
|
299 |
|
|
}
|
300 |
williamc |
1.1 |
|
301 |
sashby |
1.23 |
sub _LoadEnvFile
|
302 |
|
|
{
|
303 |
|
|
my $self=shift;
|
304 |
williamc |
1.9 |
|
305 |
muzaffar |
1.36 |
my $fh;
|
306 |
|
|
my $envfile = $self->location()."/".$self->{admindir}."/Environment";
|
307 |
|
|
open ( $fh, "< $envfile" ) or $self->error("Cannot open \"$envfile\" file for reading.\n $!");
|
308 |
sashby |
1.23 |
while ( <$fh> )
|
309 |
|
|
{
|
310 |
|
|
chomp;
|
311 |
|
|
next if /^#/;
|
312 |
|
|
next if /^\s*$/ ;
|
313 |
|
|
($name, $value)=split /=/;
|
314 |
|
|
eval "\$self->{ENV}{${name}}=\"$value\"";
|
315 |
|
|
}
|
316 |
muzaffar |
1.36 |
close($fh);
|
317 |
|
|
$envfile = $self->archdir()."/Environment";
|
318 |
|
|
if (-f $envfile)
|
319 |
|
|
{
|
320 |
|
|
open ( $fh, "< $envfile" ) or $self->error("Cannot open \"$envfile\" file for reading.\n $!");
|
321 |
|
|
while ( <$fh> )
|
322 |
|
|
{
|
323 |
|
|
chomp;
|
324 |
|
|
next if /^#/;
|
325 |
|
|
next if /^\s*$/ ;
|
326 |
|
|
($name, $value)=split /=/;
|
327 |
|
|
eval "\$self->{ENV}{${name}}=\"$value\"";
|
328 |
|
|
}
|
329 |
|
|
close($fh);
|
330 |
|
|
}
|
331 |
williamc |
1.14 |
|
332 |
sashby |
1.23 |
# -- set internal variables appropriately
|
333 |
|
|
if ( defined $self->{ENV}{"SCRAM_PROJECTNAME"} )
|
334 |
|
|
{
|
335 |
|
|
$self->name($self->{ENV}{"SCRAM_PROJECTNAME"});
|
336 |
|
|
}
|
337 |
muzaffar |
1.36 |
if ( defined $self->{ENV}{"SCRAM_SYMLINKS"} )
|
338 |
|
|
{
|
339 |
|
|
$self->symlinks($self->{ENV}{"SCRAM_SYMLINKS"});
|
340 |
|
|
}
|
341 |
|
|
if ( defined $self->{ENV}{"SCRAM_CONFIGCHKSUM"} )
|
342 |
|
|
{
|
343 |
|
|
$self->configchksum($self->{ENV}{"SCRAM_CONFIGCHKSUM"});
|
344 |
|
|
}
|
345 |
sashby |
1.23 |
if ( defined $self->{ENV}{"SCRAM_PROJECTVERSION"} )
|
346 |
|
|
{
|
347 |
|
|
$self->version($self->{ENV}{"SCRAM_PROJECTVERSION"});
|
348 |
|
|
}
|
349 |
|
|
if ( defined $self->{ENV}{"SCRAM_CONFIGDIR"} )
|
350 |
|
|
{
|
351 |
|
|
$self->configurationdir($self->{ENV}{"SCRAM_CONFIGDIR"});
|
352 |
|
|
}
|
353 |
|
|
if ( defined $self->{ENV}{"SCRAM_SOURCEDIR"} )
|
354 |
|
|
{
|
355 |
|
|
$self->sourcedir($self->{ENV}{"SCRAM_SOURCEDIR"});
|
356 |
|
|
}
|
357 |
muzaffar |
1.36 |
if ( defined $self->{ENV}{"RELEASETOP"} )
|
358 |
sashby |
1.23 |
{
|
359 |
muzaffar |
1.36 |
$self->releasetop($self->{ENV}{"RELEASETOP"});
|
360 |
sashby |
1.23 |
}
|
361 |
|
|
}
|
362 |
muzaffar |
1.36 |
1;
|