1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
#!/usr/bin/perl
#------------------------------------------------------------------------------
#*
#* Determined and output Makefile depedencies for the test diff files.
#*
#* USAGE:
#* mkdiffdepend test_001.inp test_002.inp test_003.sh
#* printf "test_001.inp\ntest_002.inp\ntest_003.sh\n" | mkdiffdepend
#**
use strict;
use warnings;
use COD::SOptions qw( getOptions );
my $script_depend_file;
my $output_dir = '.';
@ARGV = getOptions(
'--script-depend' => \$script_depend_file,
'-o,--output-directory' => \$output_dir,
);
my %script_depend;
if( $script_depend_file ) {
open my $inp, '<', $script_depend_file or
die "$0: $script_depend_file: ERROR, unable to open file for " .
'reading -- ' . ( lc $! ) . ".\n";
while( my $depend_line = <$inp> ) {
chomp $depend_line;
my( $script, $depend ) = split /\s*:\s*/, $depend_line;
$script_depend{$script} = $depend;
}
close $inp or
die "$0: $script_depend_file: ERROR, unable to properly close the " .
'file after reading -- ' . ( lc $! ) . ".\n";
}
$output_dir =~ s{/$}{};
# Read the test input file names from STDIN if no filenames are provided
# as command-line arguments.
my @filenames = @ARGV ? @ARGV : <>;
my %processed_targets;
for my $filename (@filenames) {
chomp $filename;
my $target;
my @prereq;
if( $filename =~ m{.*/(.+?)_(\d{2,4})[.]\w{3}$} ) {
$target = "${output_dir}/${1}_${2}.diff";
next if $processed_targets{$target};
my $prereq = "scripts/$1";
@prereq = ( $prereq );
if( exists $script_depend{$prereq} ) {
push @prereq, $script_depend{$prereq};
}
} elsif ( $filename =~ /[.]sh$/ ) {
my @dependencies =
split /\n/, `tools/mkshdepend $filename | head -n -3`;
for my $dependency (@dependencies) {
my( $target_now, $prereq_now ) = split /\s*:\s*/, $dependency;
next if !$target_now || !$prereq_now;
$target = $target_now if !$target;
push @prereq, ( split /\s+/, ${prereq_now} );
}
next if !$target || !@prereq;
$target =~ s/[.]sh[.]log$/.diff/;
$target =~ s/shtests/shoutputs/;
my @prereq_now = @prereq;
foreach( @prereq ) {
next if !exists $script_depend{$_};
push @prereq_now, $script_depend{$_};
}
@prereq = @prereq_now;
}
next if !@prereq;
my $line = "$target: " . ( join ' ', @prereq );
print $line, "\n";
$processed_targets{$target} = 1;
}
|