Skip to content

Commit

Permalink
mkdep: handle breakage from srcdir changes
Browse files Browse the repository at this point in the history
The handling of "path" and "fullpath" was inconsistent, resulting in a
lot of missing dependencies regardless if a separate build directory
was in use.

Signed-off-by: H. Peter Anvin <[email protected]>
  • Loading branch information
H. Peter Anvin committed Jul 28, 2024
1 parent 68d5993 commit 8ef2fa2
Showing 1 changed file with 44 additions and 20 deletions.
64 changes: 44 additions & 20 deletions tools/mkdep.pl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"#-- Everything below is generated by mkdep.pl - do not edit --#\n";

# This converts from filenames to full pathnames for our dependencies
# These are arrays of [full path, Makefile path]
my %dep_path = ();

# List of files that cannot be found; these *must* be excluded
Expand All @@ -73,52 +74,68 @@

#
# Scan files for dependencies
# $path is the full filesystem path, $file Makefile name
#
sub scandeps {
# path is the filesystem path, file what the output should call it
my($path, $file) = @_;
my $line;
my %xdeps;
my %mdeps;

open(my $fh, '<', $path)
or return; # If not openable, assume generated
print STDERR "mkdep: scanning file: $path\n" if ( $debug );

my $fh;
if (!open($fh, '<', $path)) {
print STDERR " -> missing, assume generated\n" if ( $debug );
return;
}

while ( defined($line = <$fh>) ) {
chomp $line;
$line =~ s:/\*.*\*/::g;
$line =~ s://.*$::;
if ( $line =~ /^\s*\#\s*include\s+\"(.*)\"\s*$/ ) {
my $nf = $1;
if (!defined($dep_path{$nf})) {
my $dp = $dep_path{$nf};
if (!defined($dp)) {
push(@must_exclude, $nf);
print STDERR " -> $nf [missing]\n" if ( $debug );
next;
}
$nf = $dep_path{$nf};
$mdeps{$nf}++;
$xdeps{$nf}++ unless ( defined($deps{$nf}) );
my $dn = $dp->[1];
$mdeps{$dn}++;
$xdeps{$dn} = $dp unless ( defined($deps{$dn}) );
printf STDERR " -> %s (%s)\n", $nf, $dn if ( $debug );
}
}
close($fh);
$deps{$file} = [keys(%mdeps)];

foreach my $xf ( keys(%xdeps) ) {
scandeps($xf);
scandeps(@{$xdeps{$xf}});
}
}

# %deps contains direct dependencies. This subroutine resolves
# indirect dependencies that result.
sub alldeps($$) {
my($file, $level) = @_;
my %adeps;
sub _alldeps($$$) {
my($file, $level, $adeps) = @_;

return if ($adeps->{$file});

printf STDERR " %s-> %s\n", (' ' x $level), $file;
$adeps->{$file}++;

foreach my $dep ( @{$deps{$file}} ) {
$adeps{$dep} = 1;
foreach my $idep ( alldeps($dep, $level+1) ) {
$adeps{$idep} = 1;
}
_alldeps($dep, $level+1, $adeps);
}
}

sub alldeps($) {
my($file) = @_;

my %adeps;
_alldeps($file, 1, \%adeps);
return sort(keys(%adeps));
}

Expand Down Expand Up @@ -177,7 +194,7 @@ ($)
my $fpath = $1;
my $fbase = basename($fpath);
if (!defined($dep_path{$fbase})) {
$dep_path{$fbase} = $fpath;
$dep_path{$fbase} = [$fpath, $fpath];
print STDERR "Makefile: $fbase -> $fpath\n";
}
} elsif ( $line =~ /^\s*\#\s*@([a-z0-9-]+):\s*\"([^\"]*)\"/ ) {
Expand Down Expand Up @@ -249,7 +266,8 @@ ($)
@deps = sort(keys(%deps));
} elsif ( $dfile =~ /^(.*)\.[Cc]$/ ) {
$ofile = convert_file($1, $sep).$obj.':';
@deps = ($dfile,alldeps($dfile,1));
print STDERR "mkdep: dependencies for: $dfile\n";
@deps = alldeps($dfile);
}

if (defined($ofile)) {
Expand Down Expand Up @@ -332,12 +350,15 @@ ($$)

foreach my $sdir ( @searchdirs ) {
my $dir = mycatdir($sdir, $fdir);

if ($scanned{$dir}) {
# Have already been here
$found = 1;
next;
}

print STDERR "mkdep: scanning directory $dir\n" if ( $debug );

opendir(DIR, $dir) or next;
$scanned{$dir}++;
$found++;
Expand All @@ -351,9 +372,12 @@ ($$)
if ( $file =~ /\.[Cc]$/ ) {
push(@cfiles, [$fullpath, $path]);
} elsif ( $file =~ /\.[Hh]$/ ) {
print STDERR "Filesystem: $file -> $path\n" if ( $debug );
$dep_path{$file} = $path; # Allow the blank filename
$dep_path{$path} = $path; # Also allow the full pathname
print STDERR "mkdep: filesystem: $file -> $path\n" if ( $debug );
if (defined($dep_path{$file})) {
print STDERR "mkdep: warning: more than one instance of filename $file!\n";
}
$dep_path{$file} = [$fullpath, $path];
$dep_path{$path} = [$fullpath, $path];
}
}
closedir(DIR);
Expand Down

0 comments on commit 8ef2fa2

Please sign in to comment.