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

# Content
1 package Configuration::ConfigArea;
2 require 5.004;
3 use Utilities::AddDir;
4 use Utilities::Verbose;
5 use Cwd;
6 @ISA=qw(Utilities::Verbose);
7
8 sub new {
9 my $class=shift;
10 my $self={};
11 bless $self, $class;
12 $self->{admindir}=".SCRAM";
13 $self->{configurationdir} = "config";
14 $self->archname(shift || $ENV{SCRAM_ARCH});
15 return $self;
16 }
17
18 sub toolcachename
19 {
20 my $self=shift;
21 return ($self->archdir()."/ToolCache.db.gz");
22 }
23
24 sub projectcachename
25 {
26 my $self=shift;
27 return ($self->archdir()."/ProjectCache.db.gz");
28 }
29
30 sub symlinks {
31 my $self=shift;
32 if (@_) {$self->{symlinks}=shift;}
33 return $self->{symlinks};
34 }
35
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 }
45
46 sub configchksum {
47 my $self=shift;
48 if (@_) {$self->{configchksum}=shift;}
49 return $self->{configchksum};
50 }
51
52
53 sub name {
54 my $self=shift;
55 @_?$self->{name}=shift
56 :$self->{name};
57 }
58
59 sub version {
60 my $self=shift;
61 @_?$self->{version}=shift
62 :$self->{version};
63 }
64
65 sub setup {
66 my $self=shift;
67 my $location=shift;
68 my $areaname=shift || undef;
69 my $symlinks=shift || 0;
70 my $locarea = shift || undef;
71 if ( (! defined $areaname) || ( $areaname eq "" ) ) {
72 $areaname=$self->version();
73 }
74 $self->location($location."/".$areaname);
75 $self->symlinks($symlinks);
76 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 }
94
95 sub configurationdir {
96 my $self=shift;
97 if ( @_ ) {
98 $self->{configurationdir}=shift;
99 }
100 return (defined $self->{configurationdir})?$self->{configurationdir}:undef;
101 }
102
103 sub sourcedir {
104 my $self=shift;
105 if ( @_ ) {
106 $self->{sourcedir}=shift;
107 }
108 return (defined $self->{sourcedir})?$self->{sourcedir}:undef;
109 }
110
111 sub releasetop {
112 my $self=shift;
113 if ( @_ ) {
114 $self->{releasetop}=shift;
115 }
116 return (defined $self->{releasetop})?$self->{releasetop}:undef;
117 }
118
119 sub admindir()
120 {
121 my $self=shift;
122
123 @_ ? $self->{admindir} = shift
124 : $self->{admindir};
125 }
126
127 sub bootstrapfromlocation {
128 my $self=shift;
129 my $location = $self->searchlocation(shift);
130 my $rv=0;
131 if ( ! defined $location) {
132 $rv=1;
133 }
134 else {
135 $self->location($location);
136 $self->_LoadEnvFile();
137 }
138 return $rv;
139 }
140
141 sub location {
142 my $self=shift;
143
144 if ( @_ ) {
145 $self->{location}=shift;
146 $self->archname($self->{archname});
147 }
148 elsif ( ! defined $self->{location} ) {
149 # try and find the release location
150 $self->{location}=$self->searchlocation();
151 if (defined $self->{location})
152 {
153 $self->archname($self->{archname});
154 }
155 }
156 return $self->{location};
157 }
158
159 sub searchlocation {
160 my $self=shift;
161
162 #start search in current directory if not specified
163 my $thispath;
164 if ( @_ ) {
165 $thispath=shift
166 }
167 else {
168 $thispath=cwd();
169 }
170
171 my $rv=0;
172
173 # chop off any files - we only want dirs
174 if ( -f $thispath ) {
175 $thispath=~s/(.*)\/.*/$1/;
176 }
177 Sloop:{
178 do {
179 $self->verbose("Searching $thispath");
180 if ( -e "$thispath/".$self->{admindir} ) {
181 $self->verbose("Found\n");
182 $rv=1;
183 last Sloop;
184 }
185 } while ( ($thispath=~s/(.*)\/.*/$1/)=~/./ ) };
186
187 return $rv?$thispath:undef;
188 }
189
190 sub archname {
191 my $self=shift;
192 if ( @_ ) {
193 $self->{archname}=shift;
194 if (defined $self->{location}) {
195 $self->archdir($self->{location}."/".$self->{admindir}."/".$self->{archname});
196 }
197 }
198 return $self->{archname};
199 }
200
201 sub archdir {
202 my $self=shift;
203 if ( @_ ) {
204 $self->{archdir}=shift;
205 }
206 return $self->{archdir};
207 }
208
209 sub satellite {
210 my $self=shift;
211 my $relloc = $self->location();
212 my $sat=Configuration::ConfigArea->new($self->arch());
213 $sat->name($self->name());
214 $sat->version($self->version());
215 $sat->configurationdir($self->configurationdir());
216 $sat->sourcedir($self->sourcedir());
217 $sat->releasetop($relloc);
218 $sat->configchksum($self->configchksum());
219 $sat->setup(@_);
220 $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 $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 return $sat;
239 }
240
241 sub copywithskip {
242 my $self=shift;
243 my $src=shift;
244 my $des=shift;
245 my $filetoskip=shift || [];
246 my $rv=1;
247 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 return $rv;
258 }
259
260 sub copyenv {
261 my $self=shift;
262 my $hashref=shift;
263
264 foreach $elem ( keys %{$self->{ENV}} ) {
265 $$hashref{$elem}=$self->{ENV}{$elem};
266 }
267 }
268
269 sub arch {
270 my $self=shift;
271 return $self->{archname};
272 }
273
274 sub save {
275 my $self=shift;
276 $self->_SaveEnvFile();
277 }
278
279 # ---- support routines
280
281 sub _SaveEnvFile
282 {
283 my $self=shift;
284
285 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
289 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 print $fh "SCRAM_SYMLINKS=",$self->symlinks(),"\n";
294 print $fh "SCRAM_CONFIGCHKSUM=",$self->configchksum(),"\n";
295 close($fh);
296
297 # Set the default permissions (-rw-r--r--):
298 my $filemode = 0644;
299 chmod $filemode, $self->location()."/".$self->{admindir}."/Environment";
300 }
301
302 sub _LoadEnvFile
303 {
304 my $self=shift;
305
306 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 while ( <$fh> )
310 {
311 chomp;
312 next if /^#/;
313 next if /^\s*$/ ;
314 ($name, $value)=split /=/;
315 eval "\$self->{ENV}{${name}}=\"$value\"";
316 }
317 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
333 # -- set internal variables appropriately
334 if ( defined $self->{ENV}{"SCRAM_PROJECTNAME"} )
335 {
336 $self->name($self->{ENV}{"SCRAM_PROJECTNAME"});
337 }
338 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 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 if ( defined $self->{ENV}{"RELEASETOP"} )
359 {
360 $self->releasetop($self->{ENV}{"RELEASETOP"});
361 }
362 }
363 1;