3 |
|
# Interface |
4 |
|
# --------- |
5 |
|
# new(ConfigArea) : A new BuildSetup |
6 |
< |
# BuildSetup(directory,targets) : prepare the ground for a build and build |
6 |
> |
# BuildDir(directory,targets) : prepare the ground for a build and build |
7 |
|
# getclass(directory) : return (Class, ClassDir, BuildFileobject) |
8 |
|
# associated with directory |
9 |
|
# setup(dir) |
13 |
|
use Utilities::Verbose; |
14 |
|
use Utilities::SCRAMUtils; |
15 |
|
use BuildSystem::BuildFile; |
16 |
+ |
use BuildSystem::DateStampRecord; |
17 |
|
use Utilities::AddDir; |
18 |
|
@ISA=qw(Utilities::Verbose); |
19 |
|
|
25 |
|
$self->{toolbox}=$self->{area}->toolbox(); |
26 |
|
$self->{projconfigdir}=$self->{area}->configurationdir(); |
27 |
|
$self->{localtop}=$self->{area}->location(); |
28 |
+ |
$self->{releasearea}=$self->{area}->linkarea(); |
29 |
+ |
if ( ! defined $self->{releasearea} ) { |
30 |
+ |
$self->{releasearea}=$self->{area}; |
31 |
+ |
} |
32 |
+ |
$self->{releasetop}=$self->{releasearea}->location(); |
33 |
|
$self->{buildfilename}="BuildFile"; |
34 |
+ |
#$self->verbosity(1); |
35 |
|
$self->_configurationsetup(); |
36 |
|
return $self; |
37 |
|
} |
40 |
|
my $self=shift; |
41 |
|
my $outfile=shift; |
42 |
|
|
43 |
< |
# -- specifiy these files for dependency information |
43 |
> |
# -- specify these files for dependency information |
44 |
|
my $depfile=$self->{projconfigdir}."/External_Dependencies"; |
45 |
|
|
46 |
|
# -- get list of dependent files |
128 |
|
my $classbf=BuildSystem::BuildFile->new($self->{area}); |
129 |
|
undef $ENV{LatestBuildFile}; # gets set by BuildFile |
130 |
|
$classbf->GenerateMakefile($classbuildfile, $classmakefile); |
131 |
< |
undef $ENV{LatestBuildFile}; # we dont want this included in the |
125 |
< |
# hierarchy |
131 |
> |
undef $ENV{LatestBuildFile}; # gets set by BuildFile |
132 |
|
} |
133 |
|
} |
134 |
|
else { |
175 |
|
my @Targets=@_; |
176 |
|
my $DefaultBuildFile=""; |
177 |
|
|
178 |
< |
# -- Create working directory |
173 |
< |
my $workdir=$self->{workdir}."/".$THISDIR; |
174 |
< |
chdir $self->{localtop}; |
175 |
< |
AddDir::adddir($workdir); |
176 |
< |
$ENV{workdir}=$workdir; |
177 |
< |
my $fullworkdir=$self->{localtop}."/".$ENV{workdir}; |
178 |
< |
chdir $fullworkdir || die "Unable to enter working directory $!"; |
179 |
< |
|
180 |
< |
# -- setup Class specifics |
178 |
> |
# -- Setup Class specifics |
179 |
|
($Class,$ClassDir,$classmakefile)=$self->classsetup($THISDIR); |
180 |
|
$ENV{classmakefile}=$classmakefile; |
181 |
|
$ENV{Class}=$Class; |
182 |
|
$ENV{ClassDir}=$ClassDir; |
183 |
|
$DefaultBuildFile=$ENV{classmakefile}; |
184 |
|
$ENV{DefaultBuildFile}=$DefaultBuildFile; |
187 |
– |
|
185 |
|
|
186 |
+ |
# -- Create working directory |
187 |
+ |
my $workdir=$self->{workdir}."/".$ClassDir; |
188 |
+ |
chdir $self->{localtop}; |
189 |
+ |
AddDir::adddir($workdir); |
190 |
+ |
$ENV{workdir}=$workdir; |
191 |
+ |
my $fullworkdir=$self->{localtop}."/".$ENV{workdir}; |
192 |
+ |
chdir $fullworkdir || die "Unable to enter working directory $!"; |
193 |
+ |
|
194 |
|
# -- Set up some other useful variables for the Build |
195 |
|
# set variables listing directories/files available |
196 |
|
my $fh=FileHandle->new(); |
197 |
< |
opendir $fh, "$self->{localtop}/$THISDIR"; |
197 |
> |
opendir $fh, "$self->{localtop}/$ClassDir"; |
198 |
|
my @allfiles= grep !/^\.\.?$/, readdir $fh; |
199 |
|
undef $fh; |
200 |
|
foreach $file ( @allfiles ) { |
201 |
< |
if ( -d "$self->{localtop}/$THISDIR/$file" ) { |
201 |
> |
if ( -d "$self->{localtop}/$ClassDir/$file" ) { |
202 |
|
$ENV{SCRAM_AVAILDIRS}=$ENV{SCRAM_AVAILDIRS}." ".$file; |
203 |
|
} |
204 |
|
else { |
230 |
|
|
231 |
|
$ENV{DefaultMakefile}="$ENV{TOOL_HOME}/basics.mk"; |
232 |
|
|
233 |
+ |
|
234 |
|
$SCRAM_GROUPSDIR=$self->{localtop}."/".$self->{projconfigdir}."/groups.mk"; |
235 |
|
if ( -f $SCRAM_GROUPSDIR ) { |
236 |
|
$ENV{SCRAM_GROUPSDIR}=$SCRAM_GROUPSDIR; |
238 |
|
|
239 |
|
# Do a datestamp check so that make will build files that have changed |
240 |
|
# rather than just those which are older than their dependencies |
241 |
+ |
$self->_checkdatestampindir($ClassDir); |
242 |
+ |
|
243 |
+ |
# -- call the block building method |
244 |
+ |
#$report=$bs->build(@Targets); |
245 |
+ |
|
246 |
+ |
|
247 |
|
# The main build here |
248 |
< |
$rv=system("gmake","--no-print-directory","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}",datestamp_config); |
237 |
< |
$rv=system("gmake","--no-print-directory","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}",datestamp, @Targets); |
248 |
> |
$rv=system("gmake","--no-print-directory","-r","-k","-f","$ENV{DefaultMakefile}","-I$ENV{TOOL_HOME}", @Targets); |
249 |
|
return $rv/256; # return the exit status of gmake |
250 |
+ |
|
251 |
+ |
} |
252 |
+ |
|
253 |
+ |
sub BuildIt { |
254 |
+ |
my $self=shift; |
255 |
+ |
my $dir=shift; |
256 |
+ |
|
257 |
+ |
# -- get the building block for the directory |
258 |
+ |
my $block=$self->_getdirblock($dir); |
259 |
+ |
|
260 |
+ |
# -- is there a class block associated with the directory? |
261 |
+ |
my ($class)=getclass($dir); |
262 |
+ |
my $classblock=$self->_getclassblock($class); |
263 |
+ |
|
264 |
+ |
# -- Search for Blocks up to tree root |
265 |
+ |
my @dirblocks=(); |
266 |
+ |
my @dirs=split /\//, $dir; |
267 |
+ |
my $fulldir=""; |
268 |
+ |
foreach $dire ( "/",@dirs ) { |
269 |
+ |
$fulldir=$fulldir."/".$dire; # root is // |
270 |
+ |
my $block=$self->_getdirblock($fulldir); |
271 |
+ |
last if $block->ignore(); # we dont need to go futher |
272 |
+ |
push @dirblocks, $block; |
273 |
+ |
} |
274 |
+ |
foreach $block ( $classblock, @dirblocks ) { |
275 |
+ |
# -- merge class blocks together |
276 |
+ |
foreach $name ( $block->classes() ) { |
277 |
+ |
$object->merge(); |
278 |
+ |
} |
279 |
+ |
foreach $classinst ( $block->classinst() ) { |
280 |
+ |
$types{$classinst->id()}=$class->newinst(); |
281 |
+ |
foreach $element ( $classinst ) { |
282 |
+ |
$types{$classinst->id()}->setelement($element, |
283 |
+ |
$classinst->value($element)); |
284 |
+ |
} |
285 |
+ |
} |
286 |
+ |
} |
287 |
+ |
|
288 |
+ |
# -- call the builder |
289 |
+ |
|
290 |
+ |
} |
291 |
+ |
|
292 |
+ |
sub _getdirblock { |
293 |
+ |
my $self=shift; |
294 |
+ |
my $dir=shift; |
295 |
+ |
|
296 |
+ |
if ( ! defined $self->{blocks}{$dir} ) { |
297 |
+ |
|
298 |
+ |
# -- get a buildfile and do a block parse |
299 |
+ |
my $bf=$self->_startbuildfile($dir); |
300 |
+ |
$bf->blockparse($self->{blocks}{$dir}); |
301 |
+ |
|
302 |
+ |
} |
303 |
+ |
return $self->{blocks}{$dir}; |
304 |
|
} |
305 |
|
|
306 |
|
sub getclass { |
329 |
|
else { |
330 |
|
# -- sort it out from classpath directives |
331 |
|
foreach $BlockClassA ( @{$self->{LoBCA}} ) { |
332 |
< |
foreach $elem ( @$BlockClassA ) { |
332 |
> |
next if ( $#{$BlockClassA} < $i ); |
333 |
> |
$elem=${$BlockClassA}[$i]; |
334 |
|
if ( $elem=~/^$DIRA[$i]\+/ ) { |
335 |
|
$elem=~s/^$DIRA[$i]//; |
336 |
|
} |
337 |
+ |
#print $elem." ".$DIRA[$i]."\n"; |
338 |
|
if ( $elem=~/^\+/ ) { |
339 |
|
($Class=$elem)=~s/^\+//; |
340 |
|
$ClassDir=$thispath; |
341 |
|
} |
342 |
< |
} |
342 |
> |
#} |
343 |
|
} |
344 |
|
} |
345 |
|
} |
352 |
|
$ClassDir="."; |
353 |
|
} |
354 |
|
|
355 |
< |
# -- retunrs |
355 |
> |
# -- returns |
356 |
|
($ClassDir_c=$ClassDir)=~s/^\.\///; |
357 |
|
return ( $Class, $ClassDir_c, $self->{pathbf}{$ClassDir}); |
358 |
|
} |
373 |
|
$bf->ParseBuildFile($self->{localtop}, $classdir, |
374 |
|
$self->{buildfilename}); |
375 |
|
} |
376 |
< |
elsif ( -e $ENV{RELEASETOP}."/".$thisfile ) { |
377 |
< |
$bf->buildfile("$ENV{RELEASETOP}/$thisfile"); |
378 |
< |
$bf->ParseBuildFile($ENV{RELEASETOP}, $classdir, |
379 |
< |
$slef->{buildfilename}); |
376 |
> |
elsif ( -e $self->{releasetop}."/".$thisfile ) { |
377 |
> |
$bf->buildfile($self->{releasetop}."/".$thisfile); |
378 |
> |
$bf->ParseBuildFile($self->{releasetop}, $classdir, |
379 |
> |
$self->{buildfilename}); |
380 |
|
} |
381 |
|
return $bf; |
382 |
|
} |
391 |
|
."/".$self->{buildfilename}); |
392 |
|
# -- generate top level makefile |
393 |
|
$self->verbose("Generating Top Level BuildFile"); |
394 |
+ |
undef $ENV{LatestBuildFile}; |
395 |
|
$self->{topbf}->ParseBuildFile($self->{localtop}, |
396 |
|
$self->{projconfigdir},$self->{buildfilename}); |
397 |
|
|
402 |
|
} |
403 |
|
|
404 |
|
} |
405 |
+ |
|
406 |
+ |
sub _checkdatestampindir { |
407 |
+ |
my $self=shift; |
408 |
+ |
my $dir=shift; |
409 |
+ |
|
410 |
+ |
# -- get all local .ds files |
411 |
+ |
my $fh=FileHandle->new(); |
412 |
+ |
my $ldir=$self->{localtop}."/".$self->{workdir}."/".$dir; |
413 |
+ |
opendir $fh, $ldir; |
414 |
+ |
my @dsfiles= grep /^.*\.ds$/, readdir $fh; |
415 |
+ |
$fh->close(); |
416 |
+ |
|
417 |
+ |
# -- copy across ds files from releasetop if not existing locally |
418 |
+ |
if ( $#dsfiles < 0 ) { |
419 |
+ |
# -- get all releasetop .ds files |
420 |
+ |
my $rdir=$self->{releasetop}."/".$self->{workdir}."/".$dir; |
421 |
+ |
opendir $fh, $rdir; |
422 |
+ |
my @releasedsfiles= grep /^.*\.ds$/, readdir $fh; |
423 |
+ |
foreach $file ( @releasedsfiles ) { |
424 |
+ |
use File::Copy; |
425 |
+ |
$self->verbose("Copying $file from $rdir to $ldir"); |
426 |
+ |
copy($rdir."/".$file,$ldir."/".$file); |
427 |
+ |
} |
428 |
+ |
$fh->close(); |
429 |
+ |
@dsfiles=@releasedsfiles; |
430 |
+ |
} |
431 |
+ |
|
432 |
+ |
# -- process ds files |
433 |
+ |
my $file; |
434 |
+ |
foreach $datafile ( @dsfiles ) { |
435 |
+ |
$self->verbose("Processing $ldir/$datafile\n"); |
436 |
+ |
my $ds=BuildSystem::DateStampRecord->new($ldir."/".$datafile); |
437 |
+ |
$ds->verbosity($self->verbosity()); |
438 |
+ |
my $needsupdate; |
439 |
+ |
my $productfile=$ds->product(); |
440 |
+ |
my (%files,%moddate); |
441 |
+ |
|
442 |
+ |
# now get dates in our dependency list |
443 |
+ |
my @datedfiles=$ds->dated(); |
444 |
+ |
if ( $#datedfiles >= 0 ) { |
445 |
+ |
|
446 |
+ |
$needsupdate=1; |
447 |
+ |
$date=$datedfiles[0][1]-1; |
448 |
+ |
} |
449 |
+ |
else { |
450 |
+ |
# -- extra checks for local replacement of files |
451 |
+ |
foreach $file ( $ds->contents() ) { |
452 |
+ |
# -- only check files |
453 |
+ |
if ( -f $file ) { |
454 |
+ |
$files{$file}=$ds->filedate($file); |
455 |
+ |
# -- check to see if we have a new local copy |
456 |
+ |
if ( ($file=~/\Q$self->{releasetop}\E/) && |
457 |
+ |
($self->{releasetop} ne $self->{localtop}) ) { |
458 |
+ |
($tempfile=$file)=~s/\Q$self->{releasetop}\E/$self->{localtop}/; |
459 |
+ |
if ( -f $tempfile ) { |
460 |
+ |
$files{$tempfile}=$files{$file}; |
461 |
+ |
$file=$tempfile; |
462 |
+ |
} |
463 |
+ |
} |
464 |
+ |
$moddate{$file}=(stat($file))[9]; |
465 |
+ |
if ( $moddate{$file} != $files{$file} ) { |
466 |
+ |
$self->verbose($file." changed"); |
467 |
+ |
$date=$moddate{$file}-1; |
468 |
+ |
$needsupdate=1; |
469 |
+ |
} |
470 |
+ |
} |
471 |
+ |
} |
472 |
+ |
} |
473 |
+ |
# time stamp the product file to be older than the dependencies |
474 |
+ |
if ( $needsupdate == 1 ) { # touch file into the past |
475 |
+ |
my $newproductfile; |
476 |
+ |
if ( $productfile!~/\Q$self->{localtop}\E/ ) { |
477 |
+ |
if ( $productfile=~/\Q$self->{releasetop}\E/ ) { |
478 |
+ |
($newproductfile=$productfile)=~ |
479 |
+ |
s/\Q$self->{releasetop}\E/$self->{localtop}/; |
480 |
+ |
$self->verbose("Copying $productfile to $newproductfile"); |
481 |
+ |
copy($productfile,$newproductfile); |
482 |
+ |
} |
483 |
+ |
else { # assume no path to worry about |
484 |
+ |
$newproductfile=$self->{localtop}."/".$ENV{workdir}. |
485 |
+ |
"/".$productfile; |
486 |
+ |
# -- make a local copy of the product file if not already here |
487 |
+ |
my $oldproductfile=$self->{releasetop}."/".$ENV{workdir}. |
488 |
+ |
"/".$productfile; |
489 |
+ |
if ( ! -f $newproductfile ) { |
490 |
+ |
if ( -f $oldproductfile ) { |
491 |
+ |
$self->verbose("Copying $oldproductfile to $newproductfile"); |
492 |
+ |
copy($oldproductfile,$newproductfile); |
493 |
+ |
} |
494 |
+ |
} |
495 |
+ |
} |
496 |
+ |
} |
497 |
+ |
else { |
498 |
+ |
$newproductfile=$productfile; |
499 |
+ |
} |
500 |
+ |
if ( -f $newproductfile ) { |
501 |
+ |
$self->verbose("Blasting $newproductfile to the past ($date)"); |
502 |
+ |
# If the (local) productfile exists - make it older |
503 |
+ |
utime($date,$date,$newproductfile); |
504 |
+ |
} |
505 |
+ |
else { |
506 |
+ |
$self->verbose("SomeThing Wrong(?) with $newproductfile\n". |
507 |
+ |
"RELEASETOP=".$self->{releasetop}."\n". |
508 |
+ |
"LOCALTOP=".$self->{localtop}."\n". |
509 |
+ |
"workdir=".$ENV{workdir}); |
510 |
+ |
} |
511 |
+ |
} |
512 |
+ |
else { |
513 |
+ |
$self->verbose("No need to touch $productfile"); |
514 |
+ |
} |
515 |
+ |
} |
516 |
+ |
undef $fh; |
517 |
+ |
} |