зеркало из https://github.com/mozilla/pjs.git
Bug 362392: mddepend.pl stat() optimizations. r=neil, moa=bsmedberg, a=schrep
This commit is contained in:
Родитель
de680f87c7
Коммит
4c0d9689c3
|
@ -46,63 +46,94 @@
|
|||
#
|
||||
# Send comments, improvements, bugs to Steve Lamm (slamm@netscape.com).
|
||||
|
||||
#$debug = 1;
|
||||
use strict;
|
||||
|
||||
$outfile = shift @ARGV;
|
||||
use constant DEBUG => 0;
|
||||
|
||||
my $outfile = shift @ARGV;
|
||||
my $silent = $ENV{MAKEFLAGS} =~ /^\w*s|\s-s/;
|
||||
|
||||
%alldeps={};
|
||||
my $line = '';
|
||||
my %alldeps;
|
||||
# Parse dependency files
|
||||
while ($line = <>) {
|
||||
$line =~ s/\r?\n$//; # Handle both unix and DOS line endings
|
||||
($obj,$rest) = split /\s*:\s+/, $line, 2;
|
||||
next if $obj eq '' || $rest eq '';
|
||||
|
||||
while (<>) {
|
||||
s/\r?\n$//; # Handle both unix and DOS line endings
|
||||
$line .= $_;
|
||||
if ($line =~ /\\$/) {
|
||||
chop $rest;
|
||||
$hasSlash = 1;
|
||||
} else {
|
||||
$hasSlash = 0;
|
||||
chop $line;
|
||||
next;
|
||||
}
|
||||
push @{$alldeps{$obj}}, split /\s+/, $rest;
|
||||
print "add $obj $rest\n" if $debug;
|
||||
|
||||
while ($hasSlash and $line = <>) {
|
||||
$line =~ s/\r?\n$//; # Handle both unix and DOS line endings
|
||||
if ($line =~ /\\$/) {
|
||||
chop $line;
|
||||
} else {
|
||||
$hasSlash = 0;
|
||||
}
|
||||
$line =~ s/^\s+//;
|
||||
push @{$alldeps{$obj}}, split /\s+/, $line;
|
||||
print "add $obj $line\n" if $debug;
|
||||
my ($obj,$rest) = split /\s*:\s+/, $line, 2;
|
||||
$line = '';
|
||||
next if !$obj || !$rest;
|
||||
|
||||
my @deps = split /\s+/, $rest;
|
||||
push @{$alldeps{$obj}}, @deps;
|
||||
if (DEBUG >= 2) {
|
||||
foreach my $dep (@deps) { print "add $obj $dep\n"; }
|
||||
}
|
||||
}
|
||||
|
||||
# Test dependencies
|
||||
foreach $obj (keys %alldeps) {
|
||||
$deps = $alldeps{$obj};
|
||||
my %modtimes; # cache
|
||||
my @objs; # force rebuild on these
|
||||
OBJ_LOOP: foreach my $obj (keys %alldeps) {
|
||||
my $mtime = (stat $obj)[9] or next;
|
||||
|
||||
$mtime = (stat $obj)[9] or next;
|
||||
my %not_in_cache;
|
||||
my $deps = $alldeps{$obj};
|
||||
foreach my $dep_file (@{$deps}) {
|
||||
my $dep_mtime = $modtimes{$dep_file};
|
||||
if (not defined $dep_mtime) {
|
||||
print "Skipping $dep_file for $obj, will stat() later\n" if DEBUG >= 2;
|
||||
$not_in_cache{$dep_file} = 1;
|
||||
next;
|
||||
}
|
||||
|
||||
foreach $dep_file (@{$deps}) {
|
||||
if (not defined($dep_mtime = $modtimes{$dep_file})) {
|
||||
$dep_mtime = (stat $dep_file)[9];
|
||||
$modtimes{$dep_file} = $dep_mtime;
|
||||
print "Found $dep_file in cache\n" if DEBUG >= 2;
|
||||
|
||||
if ($dep_mtime > $mtime) {
|
||||
print "$dep_file($dep_mtime) newer than $obj($mtime)\n" if DEBUG;
|
||||
}
|
||||
if ($dep_mtime ne '' and $dep_mtime > $mtime) {
|
||||
print "$obj($mtime) older than $dep_file($dep_mtime)\n" if $debug;
|
||||
push @objs, $obj;
|
||||
# Object will be marked for rebuild. No need to check other dependencies.
|
||||
last;
|
||||
elsif ($dep_mtime == -1) {
|
||||
print "Couldn't stat $dep_file for $obj\n" if DEBUG;
|
||||
}
|
||||
else {
|
||||
print "$dep_file($dep_mtime) older than $obj($mtime)\n" if DEBUG >= 2;
|
||||
next;
|
||||
}
|
||||
|
||||
push @objs, $obj; # dependency is missing or newer
|
||||
next OBJ_LOOP; # skip checking the rest of the dependencies
|
||||
}
|
||||
|
||||
foreach my $dep_file (keys %not_in_cache) {
|
||||
print "STAT $dep_file for $obj\n" if DEBUG >= 2;
|
||||
my $dep_mtime = $modtimes{$dep_file} = (stat $dep_file)[9] || -1;
|
||||
|
||||
if ($dep_mtime > $mtime) {
|
||||
print "$dep_file($dep_mtime) newer than $obj($mtime)\n" if DEBUG;
|
||||
}
|
||||
elsif ($dep_mtime == -1) {
|
||||
print "Couldn't stat $dep_file for $obj\n" if DEBUG;
|
||||
}
|
||||
else {
|
||||
print "$dep_file($dep_mtime) older than $obj($mtime)\n" if DEBUG >= 2;
|
||||
next;
|
||||
}
|
||||
|
||||
push @objs, $obj; # dependency is missing or newer
|
||||
next OBJ_LOOP; # skip checking the rest of the dependencies
|
||||
}
|
||||
|
||||
# If we get here it means nothing needs to be done for $obj
|
||||
}
|
||||
|
||||
# Output objects to rebuild (if needed).
|
||||
if (@objs) {
|
||||
$new_output = "@objs: FORCE\n";
|
||||
my $old_output;
|
||||
my $new_output = "@objs: FORCE\n";
|
||||
|
||||
# Read in the current dependencies file.
|
||||
open(OLD, "<$outfile")
|
||||
|
@ -113,7 +144,7 @@ if (@objs) {
|
|||
if ($new_output ne $old_output) {
|
||||
open(OUT, ">$outfile") and print OUT "$new_output";
|
||||
print "Updating dependencies file, $outfile\n" unless $silent;
|
||||
if ($debug) {
|
||||
if (DEBUG) {
|
||||
print "new: $new_output\n";
|
||||
print "was: $old_output\n" if $old_output ne '';
|
||||
}
|
||||
|
@ -122,7 +153,8 @@ if (@objs) {
|
|||
# Remove the old dependencies because all objects are up to date.
|
||||
print "Removing old dependencies file, $outfile\n" unless $silent;
|
||||
|
||||
if ($debug) {
|
||||
if (DEBUG) {
|
||||
my $old_output;
|
||||
open(OLD, "<$outfile")
|
||||
and $old_output = <OLD>;
|
||||
close(OLD);
|
||||
|
|
Загрузка…
Ссылка в новой задаче