3 # Lame script to compare two build logs.
5 # The script intercepts directory changes and compiler invocations and
6 # compares the compiler invocations for equality. Equality is defined
7 # as "same options in both invocations ignoring order". So we only test
8 # a necessary condition.
10 # Both builds must be configured with the same --prefix. Otherwise,
11 # the value of -DVG_LIBDIR= will differ. They also need to use the same
18 my $prog_name = "compare-build-logs";
25 [--gcc] intercept GCC invocations (this is default)
27 [--clang] intercept clang invocations
39 GetOptions
( "gcc" => sub { $compiler = "gcc" },
40 "clang" => sub { $compiler = "clang" },
41 "v" => sub { $verbose = 1 },
44 my $num_arg = $#ARGV + 1;
53 # Hashes: relative filename -> compiler invocation
54 my %cmd1 = read_log_file
($log1);
55 my %cmd2 = read_log_file
($log2);
57 # Compare the log files
59 foreach my $file (keys %cmd1) {
61 print "*** $file missing in $log2\n";
63 compare_invocations
($file, $cmd1{$file }, $cmd2{$file});
66 foreach my $file (keys %cmd2) {
68 print "*** $file missing in $log1\n";
74 # Compare two lines |c1| and |c2| which are compiler invocations for |file|.
75 # Basically, we look at a compiler invocation as a sequence of blank-separated
77 sub compare_invocations
{
78 my ($file, $c1, $c2) = @_;
79 my ($found1, $found2);
80 # print "COMPARE $file\n";
82 # Remove stuff that has embedded spaces
84 # Remove: `test -f 'whatever.c' || echo './'`
89 if ($found1 && $found2) {
90 die if ($found1 ne $found2);
94 $c1 =~ s
|-o
[ ][ ]*([^ ][^ ]*)||;
96 $c2 =~ s
|-o
[ ][ ]*([^ ][^ ]*)||;
98 if ($found1 && $found2) {
99 die if ($found1 ne $found2);
102 # The remaining lines are considered to be blank-separated options and file
103 # names. They should be identical in both invocations (but in any order).
106 foreach my $k (split /\s+/,$c1) {
109 foreach my $k (split /\s+/,$c2) {
112 # foreach my $zz (keys %o1) {
115 foreach my $k (keys %o1) {
117 print "*** '$k' is missing in compilation of '$file' in $log2\n";
120 foreach my $k (keys %o2) {
122 print "*** '$k' is missing in compilation of '$file' in $log1\n";
127 # Read a compiler log file.
128 # Return hash: relative (to build root) file name -> compiler invocation
136 print "...reading $log\n" if ($verbose);
138 open(LOG
, "$log") || die "cannot open $log\n";
139 while (my $line = <LOG
>) {
141 if ($line =~ /^make/) {
142 if ($line =~ /Entering directory/) {
148 # Append a slash if not present
149 $root = "$root/" if (! ($root =~ /\
/$/));
150 print "...build root is $root\n" if ($verbose);
152 # print "DIR = $dir\n";
156 if ($line =~ /^\s*[^\s]*$compiler\s/) {
157 # If line ends in \ read continuation line.
158 while ($line =~ /\\$/) {
165 my $file = extract_file
($line);
166 $file = "$dir/$file"; # make absolute
167 $file =~ s/$root//; # remove build root
168 # print "FILE $file\n";
169 $cmd{"$file"} = $line;
174 my $num_invocations = int(keys %cmd);
176 if ($num_invocations == 0) {
177 print "*** File $log does not contain any compiler invocations\n";
179 print "...found $num_invocations invocations\n" if ($verbose);
184 # Extract a file name from the command line. Assume there is a -o filename
185 # present. If not, issue a warning.
189 # Look for -o executable
190 if ($line =~ /-o[ ][ ]*([^ ][^ ]*)/) {
193 print "*** Could not extract file name from $line\n";