ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Configuration/ConfigArea.pm
Revision: 1.35.2.2.2.2
Committed: Wed Apr 2 14:56:44 2008 UTC (17 years, 1 month ago) by muzaffar
Content type: text/plain
Branch: SCRAM_V2_0
CVS Tags: V2_2_2, V2_2_2_pre4, V2_2_2_pre3, V2_2_2_pre2, V2_2_2_pre1, V2_2_2-pre1, V2_2_1, forV2_2_1, V2_2_0, sm100112, V2_1_4, V2_1_3, V2_1_2, V2_1_1, V2_1_0, V2_0_6, V2_0_5, V2_0_4, V2_0_4_relcand2, V2_0_4_relcand1, V2_0_3, V2_0_3_relcand3, V2_0_3_relcand2, V2_0_3_relcand1, V2_0_2, V2_0_2_relcand1, V2_0_1, V2_0_1_relcand4, V2_0_1_relcand3, V2_0_1_relcand2, V2_0_1_relcand1, V2_0_0_relcand4, V2_0_0, V2_0_0_relcand3, V2_0_0_relcand2
Changes since 1.35.2.2.2.1: +1 -1 lines
Log Message:
added tools runtime values caching

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     $self->{admindir}=".SCRAM";
13 muzaffar 1.35.2.2.2.1 $self->{configurationdir} = "config";
14     $self->archname(shift || $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.35.2.2.2.1 return ($self->archdir()."/ToolCache.db.gz");
22 sashby 1.23 }
23    
24     sub projectcachename
25     {
26     my $self=shift;
27 muzaffar 1.35.2.2.2.1 return ($self->archdir()."/ProjectCache.db.gz");
28 sashby 1.23 }
29    
30 muzaffar 1.35.2.2.2.1 sub symlinks {
31 williamc 1.19 my $self=shift;
32 muzaffar 1.35.2.2.2.1 if (@_) {$self->{symlinks}=shift;}
33     return $self->{symlinks};
34 williamc 1.18 }
35    
36 muzaffar 1.35.2.2.2.1 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.35.2.2.2.1 sub configchksum {
47 williamc 1.19 my $self=shift;
48 muzaffar 1.35.2.2.2.1 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.35.2.2.2.1 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.35.2.2.2.1 $areaname=$self->version();
73 williamc 1.1 }
74 muzaffar 1.35.2.2.2.1 $self->location($location."/".$areaname);
75 muzaffar 1.34 $self->symlinks($symlinks);
76 muzaffar 1.35.2.2.2.1 if ($self->configchksum() ne "")
77     {
78     if ((!-defined $locarea) && (-f "${location}/${areaname}/".$self->admindir()."/Environment"))
79     {
80     $locarea=Configuration::ConfigArea->new($self->arch());
81     $locarea->bootstrapfromlocation("${location}/${areaname}");
82     }
83     if ((defined $locarea) && ($locarea->configchksum() != $self->configchksum()))
84     {
85     print "ERROR: Can not setup your current working area for SCRAM_ARCH:".$self->arch().".\n",
86     "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.35.2.2.2.1 sub releasetop {
112 sashby 1.23 my $self=shift;
113     if ( @_ ) {
114 muzaffar 1.35.2.2.2.1 $self->{releasetop}=shift;
115 sashby 1.23 }
116 muzaffar 1.35.2.2.2.1 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.35.2.2.2.1 my $location = $self->searchlocation(shift);
130 williamc 1.14 my $rv=0;
131 muzaffar 1.35.2.2.2.1 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.35.2.2.2.1 $self->archname($self->{archname});
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.35.2.2.2.1 if (defined $self->{location})
152     {
153     $self->archname($self->{archname});
154     }
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     $self->{archname}=shift;
194 muzaffar 1.35.2.2.2.1 if (defined $self->{location}) {
195     $self->archdir($self->{location}."/".$self->{admindir}."/".$self->{archname});
196     }
197 williamc 1.14 }
198     return $self->{archname};
199     }
200 williamc 1.1
201 williamc 1.14 sub archdir {
202     my $self=shift;
203     if ( @_ ) {
204     $self->{archdir}=shift;
205     }
206     return $self->{archdir};
207 williamc 1.1 }
208    
209 williamc 1.14 sub satellite {
210 williamc 1.1 my $self=shift;
211 muzaffar 1.35.2.2.2.1 my $relloc = $self->location();
212     my $sat=Configuration::ConfigArea->new($self->arch());
213 williamc 1.14 $sat->name($self->name());
214     $sat->version($self->version());
215     $sat->configurationdir($self->configurationdir());
216 sashby 1.23 $sat->sourcedir($self->sourcedir());
217 muzaffar 1.35.2.2.2.1 $sat->releasetop($relloc);
218     $sat->configchksum($self->configchksum());
219 williamc 1.14 $sat->setup(@_);
220 muzaffar 1.35.2.2.2.2 $self->copywithskip($self->archdir(),$sat->archdir(),["InstalledTools","ProjectCache.db.gz","RuntimeCache.db.gz","DirCache.db.gz","MakeData/DirCache","MakeData/DirCache.mk","MakeData/src.mk"]);
221 muzaffar 1.35.2.2.2.1 $envfile = $sat->archdir()."/Environment";
222     open ( $fh, "> $envfile" ) or $sat->error("Cannot Open \"$envfile\" file to Save\n $!");
223     print $fh "RELEASETOP=$relloc\n";
224     close($fh);
225     my $devconf = $sat->location()."/".$sat->configurationdir();
226     my $relconf = $self->location()."/".$self->configurationdir();
227     if (!-d $devconf)
228     {
229     $self->copywithskip($relconf,$devconf,['toolbox']);
230     }
231     $envfile = $sat->location()."/".$self->{admindir}."/Environment";
232     if (! -f $envfile)
233     {
234     $sat->save ();
235     }
236     Utilities::AddDir::copydir("${relconf}/toolbox/".$self->arch(),"${devconf}/toolbox/".$sat->arch());
237     Utilities::AddDir::adddir ($sat->location()."/".$sat->sourcedir());
238 williamc 1.14 return $sat;
239 williamc 1.1 }
240    
241 sashby 1.24 sub copywithskip {
242     my $self=shift;
243 muzaffar 1.35.2.2.2.1 my $src=shift;
244     my $des=shift;
245     my $filetoskip=shift || [];
246 williamc 1.14 my $rv=1;
247 muzaffar 1.35.2.2.2.1 if ( $src ne $des )
248     {
249     if ( -d $src )
250     {
251     my $fs=[];
252     foreach my $f (@$filetoskip) {push @$fs,"${src}/${f}";}
253     Utilities::AddDir::copydirwithskip($src,$des,$fs);
254     $rv=0;
255     }
256     }
257 williamc 1.14 return $rv;
258 williamc 1.9 }
259    
260 williamc 1.14 sub copyenv {
261 williamc 1.9 my $self=shift;
262 williamc 1.14 my $hashref=shift;
263    
264     foreach $elem ( keys %{$self->{ENV}} ) {
265     $$hashref{$elem}=$self->{ENV}{$elem};
266 williamc 1.9 }
267     }
268    
269 williamc 1.14 sub arch {
270 williamc 1.9 my $self=shift;
271 muzaffar 1.35.2.2.2.1 return $self->{archname};
272 williamc 1.1 }
273    
274 williamc 1.14 sub save {
275 williamc 1.1 my $self=shift;
276 williamc 1.14 $self->_SaveEnvFile();
277 williamc 1.1 }
278    
279 williamc 1.14 # ---- support routines
280 williamc 1.1
281 sashby 1.25 sub _SaveEnvFile
282     {
283     my $self=shift;
284    
285 muzaffar 1.35.2.2.2.1 my $fh;
286     my $envfile = $self->location()."/".$self->{admindir}."/Environment";
287     open ( $fh, "> $envfile" ) or $self->error("Cannot Open \"$envfile\" file to Save\n $!");
288 williamc 1.14
289 sashby 1.25 print $fh "SCRAM_PROJECTNAME=".$self->name()."\n";
290     print $fh "SCRAM_PROJECTVERSION=".$self->version()."\n";
291     print $fh "SCRAM_CONFIGDIR=".$self->configurationdir()."\n";
292     print $fh "SCRAM_SOURCEDIR=".$self->sourcedir()."\n";
293 muzaffar 1.35.2.2.2.1 print $fh "SCRAM_SYMLINKS=",$self->symlinks(),"\n";
294     print $fh "SCRAM_CONFIGCHKSUM=",$self->configchksum(),"\n";
295     close($fh);
296 williamc 1.9
297 sashby 1.25 # Set the default permissions (-rw-r--r--):
298 muzaffar 1.35.2.2.2.1 my $filemode = 0644;
299 sashby 1.25 chmod $filemode, $self->location()."/".$self->{admindir}."/Environment";
300     }
301 williamc 1.1
302 sashby 1.23 sub _LoadEnvFile
303     {
304     my $self=shift;
305 williamc 1.9
306 muzaffar 1.35.2.2.2.1 my $fh;
307     my $envfile = $self->location()."/".$self->{admindir}."/Environment";
308     open ( $fh, "< $envfile" ) or $self->error("Cannot open \"$envfile\" file for reading.\n $!");
309 sashby 1.23 while ( <$fh> )
310     {
311     chomp;
312     next if /^#/;
313     next if /^\s*$/ ;
314     ($name, $value)=split /=/;
315     eval "\$self->{ENV}{${name}}=\"$value\"";
316     }
317 muzaffar 1.35.2.2.2.1 close($fh);
318     $envfile = $self->archdir()."/Environment";
319     if (-f $envfile)
320     {
321     open ( $fh, "< $envfile" ) or $self->error("Cannot open \"$envfile\" file for reading.\n $!");
322     while ( <$fh> )
323     {
324     chomp;
325     next if /^#/;
326     next if /^\s*$/ ;
327     ($name, $value)=split /=/;
328     eval "\$self->{ENV}{${name}}=\"$value\"";
329     }
330     close($fh);
331     }
332 williamc 1.14
333 sashby 1.23 # -- set internal variables appropriately
334     if ( defined $self->{ENV}{"SCRAM_PROJECTNAME"} )
335     {
336     $self->name($self->{ENV}{"SCRAM_PROJECTNAME"});
337     }
338 muzaffar 1.35.2.2.2.1 if ( defined $self->{ENV}{"SCRAM_SYMLINKS"} )
339     {
340     $self->symlinks($self->{ENV}{"SCRAM_SYMLINKS"});
341     }
342     if ( defined $self->{ENV}{"SCRAM_CONFIGCHKSUM"} )
343     {
344     $self->configchksum($self->{ENV}{"SCRAM_CONFIGCHKSUM"});
345     }
346 sashby 1.23 if ( defined $self->{ENV}{"SCRAM_PROJECTVERSION"} )
347     {
348     $self->version($self->{ENV}{"SCRAM_PROJECTVERSION"});
349     }
350     if ( defined $self->{ENV}{"SCRAM_CONFIGDIR"} )
351     {
352     $self->configurationdir($self->{ENV}{"SCRAM_CONFIGDIR"});
353     }
354     if ( defined $self->{ENV}{"SCRAM_SOURCEDIR"} )
355     {
356     $self->sourcedir($self->{ENV}{"SCRAM_SOURCEDIR"});
357     }
358 muzaffar 1.35.2.2.2.1 if ( defined $self->{ENV}{"RELEASETOP"} )
359 sashby 1.23 {
360 muzaffar 1.35.2.2.2.1 $self->releasetop($self->{ENV}{"RELEASETOP"});
361 sashby 1.23 }
362     }
363 muzaffar 1.35.2.2.2.1 1;