1 |
#
|
2 |
# DateStampChecker.pm
|
3 |
#
|
4 |
# Originally Written by Christopher Williams
|
5 |
#
|
6 |
# Description
|
7 |
#
|
8 |
# Interface
|
9 |
# ---------
|
10 |
# new(localtop,releasetop) : A new DateStampChecker object
|
11 |
# datefiles(@files) : process files datestamps according to the ds files
|
12 |
|
13 |
package BuildSystem::DateStampChecker;
|
14 |
use Utilities::Verbose;
|
15 |
use BuildSystem::DateStampRecord;
|
16 |
use File::Copy;
|
17 |
use FileHandle;
|
18 |
require 5.004;
|
19 |
@ISA=qw(Utilities::Verbose);
|
20 |
|
21 |
sub new {
|
22 |
my $class=shift;
|
23 |
my $self={};
|
24 |
$self->{localtop}=shift;
|
25 |
$self->{releasetop}=shift;
|
26 |
bless $self, $class;
|
27 |
return $self;
|
28 |
}
|
29 |
|
30 |
sub datefiles {
|
31 |
my $self=shift;
|
32 |
my @dsfiles=@_;
|
33 |
|
34 |
my $file;
|
35 |
foreach $datafile ( @dsfiles ) {
|
36 |
$self->verbose("Processing $datafile\n");
|
37 |
my $ds=BuildSystem::DateStampRecord->new($datafile);
|
38 |
$ds->verbosity($self->verbosity());
|
39 |
my $date;
|
40 |
my $needsupdate;
|
41 |
my $productfile=$ds->product();
|
42 |
my (%files,%moddate);
|
43 |
|
44 |
# now get dates in our dependency list
|
45 |
my @datedfiles=$ds->dated();
|
46 |
if ( $#datedfiles >= 0 ) {
|
47 |
|
48 |
$needsupdate=1;
|
49 |
$date=$datedfiles[0][1]-1;
|
50 |
}
|
51 |
else {
|
52 |
# -- extra checks for local replacement of files
|
53 |
foreach $file ( $ds->contents() ) {
|
54 |
# -- only check files
|
55 |
if ( -f $file ) {
|
56 |
$files{$file}=$ds->filedate($file);
|
57 |
# -- check to see if we have a new local copy
|
58 |
if ( ($file=~/\Q$self->{releasetop}\E/) &&
|
59 |
($self->{releasetop} ne $self->{localtop}) ) {
|
60 |
($tempfile=$file)=~s/\Q$self->{releasetop}\E/$self->{localtop}/;
|
61 |
if ( -f $tempfile ) {
|
62 |
$files{$tempfile}=$files{$file};
|
63 |
$file=$tempfile;
|
64 |
}
|
65 |
}
|
66 |
$moddate{$file}=(stat($file))[9];
|
67 |
if ( $moddate{$file} != $files{$file} ) {
|
68 |
$self->verbose($file." changed");
|
69 |
$date=$moddate{$file}-1;
|
70 |
$needsupdate=1;
|
71 |
}
|
72 |
}
|
73 |
}
|
74 |
}
|
75 |
# time stamp the product file to be older than the dependencies
|
76 |
if ( $needsupdate == 1 ) { # touch file into the past
|
77 |
my $newproductfile;
|
78 |
if ( $productfile!~/\Q$self->{localtop}\E/ ) {
|
79 |
if ( $productfile=~/\Q$self->{releasetop}\E/ ) {
|
80 |
($newproductfile=$productfile)=~
|
81 |
s/\Q$self->{releasetop}\E/$self->{localtop}/;
|
82 |
$self->verbose("Copying $productfile to $newproductfile");
|
83 |
copy($productfile,$newproductfile);
|
84 |
}
|
85 |
else { # assume no path to worry about
|
86 |
$newproductfile=$self->{localtop}."/".$ENV{workdir}.
|
87 |
"/".$productfile;
|
88 |
# -- make a local copy of the product file if not already here
|
89 |
my $oldproductfile=$self->{releasetop}."/".$ENV{workdir}.
|
90 |
"/".$productfile;
|
91 |
if ( ! -f $newproductfile ) {
|
92 |
if ( -f $oldproductfile ) {
|
93 |
$self->verbose("Copying $oldproductfile to $newproductfile");
|
94 |
copy($oldproductfile,$newproductfile);
|
95 |
}
|
96 |
}
|
97 |
}
|
98 |
}
|
99 |
else {
|
100 |
$newproductfile=$productfile;
|
101 |
}
|
102 |
if ( -f $newproductfile ) {
|
103 |
$self->verbose("Blasting $newproductfile to the past ($date)");
|
104 |
# If the (local) productfile exists - make it older
|
105 |
utime($date,$date,$newproductfile);
|
106 |
}
|
107 |
else {
|
108 |
$self->verbose("SomeThing Wrong(?) with $newproductfile\n".
|
109 |
"RELEASETOP=".$self->{releasetop}."\n".
|
110 |
"LOCALTOP=".$self->{localtop}."\n".
|
111 |
"workdir=".$ENV{workdir});
|
112 |
}
|
113 |
}
|
114 |
else {
|
115 |
$self->verbose("No need to touch $productfile");
|
116 |
}
|
117 |
}
|
118 |
}
|