ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Configuration/ConfigArea.pm
Revision: 1.41
Committed: Wed Mar 13 13:20:48 2013 UTC (12 years, 2 months ago) by muzaffar
Content type: text/plain
Branch: MAIN
CVS Tags: V2_2_5_pre2, V2_2_5_pre1, HEAD
Changes since 1.40: +7 -7 lines
Log Message:
fix time stamp issue of toolfile w.r.t timestamp files

File Contents

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