Jan Kratochvil 3b9eb3
#! /usr/bin/perl
Jan Kratochvil 3b9eb3
# Compare build logs for the testsuite results regressions.
Jan Kratochvil 3b9eb3
# $Id$
Jan Kratochvil 3b9eb3
Jan Kratochvil 3b9eb3
use strict;
Jan Kratochvil 3b9eb3
use warnings;
Jan Kratochvil 3b9eb3
use Data::Dumper;
Jan Kratochvil 3b9eb3
Jan Kratochvil 3b9eb3
my $reverse=shift @ARGV if ($ARGV[0]||"") eq "-r";
Jan Kratochvil 3b9eb3
Jan Kratochvil 3b9eb3
sub readfile($)
Jan Kratochvil 3b9eb3
{
Jan Kratochvil 3b9eb3
my($filename)=@_;
Jan Kratochvil 3b9eb3
Jan Kratochvil 3b9eb3
	local *F;
Jan Kratochvil 3b9eb3
	open F,$filename or die "open \"$filename\": $!";
Jan Kratochvil 3b9eb3
	my $F=do { local $/; <F>; };
Jan Kratochvil 3b9eb3
	close F or die "close \"$filename\": $!";
Jan Kratochvil 3b9eb3
	return $F;
Jan Kratochvil 3b9eb3
}
Jan Kratochvil 3b9eb3
Jan Kratochvil 3b9eb3
sub writefile($$)
Jan Kratochvil 3b9eb3
{
Jan Kratochvil 3b9eb3
my($filename,$content)=@_;
Jan Kratochvil 3b9eb3
Jan Kratochvil 3b9eb3
	local *F;
Jan Kratochvil 3b9eb3
	open F,">$filename" or die "create \"$filename\": $!";
Jan Kratochvil 3b9eb3
	print F $content or die "write \"$filename\": $!";
Jan Kratochvil 3b9eb3
	close F or die "close \"$filename\": $!";
Jan Kratochvil 3b9eb3
}
Jan Kratochvil 3b9eb3
Jan Kratochvil 3b9eb3
local *DIR;
Jan Kratochvil 3b9eb3
opendir DIR,"tests" or die "opendir: $!";
Jan Kratochvil 3b9eb3
my %arch;
Jan Kratochvil 3b9eb3
for my $name (sort readdir(DIR)) {
Jan Kratochvil 3b9eb3
	next if $name!~/-([^-]*)[.]log$/o;
Jan Kratochvil 3b9eb3
	my $arch=$1;
Jan Kratochvil 3b9eb3
	(my $sum=$name)=~s/log$/sum/ or die;
Jan Kratochvil 3b9eb3
	my $i=readfile "tests/$name";
Jan Kratochvil 3b9eb3
	my $o="";
Jan Kratochvil 3b9eb3
	while ($i=~/\n(Native configuration is.*?Summary ===\n.*?\n)make\Q[\E/gs) {
Jan Kratochvil 3b9eb3
		$o.=$1;
Jan Kratochvil 3b9eb3
	}
Jan Kratochvil 3b9eb3
	# Version string differs.
Jan Kratochvil 3b9eb3
	$o=~s{/builddir/build/BUILD/binutils-[^/]*/+}{}g;
Jan Kratochvil 3b9eb3
	$o=~s{^(Version .*) 20\d{6}$}{$1}mg;
Jan Kratochvil 3b9eb3
	$o=~s{^(\Q../as-new\E) 20\d{6}$}{$1}mg;
Jan Kratochvil 3b9eb3
	$o=~s{^(build-[^/]*/ld/ld-new) 20\d{6}$}{$1}mg;
Jan Kratochvil 3b9eb3
	writefile "tests/$sum",$o;
Jan Kratochvil 3b9eb3
	push @{$arch{$arch}},$sum;
Jan Kratochvil 3b9eb3
}
Jan Kratochvil 3b9eb3
closedir DIR or die "closedir: $!";
Jan Kratochvil 3b9eb3
Jan Kratochvil 3b9eb3
for (values(%arch)) {
Jan Kratochvil 3b9eb3
	next if 2==@$_;
Jan Kratochvil 3b9eb3
	warn "Single element: ".${$_}[0]."\n" if 1==@$_;
Jan Kratochvil 3b9eb3
	die "Not 2 elements:\n".Dumper($_) if 1!=@$_;
Jan Kratochvil 3b9eb3
}
Jan Kratochvil 3b9eb3
Jan Kratochvil 3b9eb3
system("rm -f tests/gdbcompare-*.diff") and die;
Jan Kratochvil 3b9eb3
Jan Kratochvil 3b9eb3
for my $arch (sort keys(%arch)) {
Jan Kratochvil 3b9eb3
	next if 2!=@{$arch{$arch}};
Jan Kratochvil 3b9eb3
	# sub trans { return {"."=>0,"-"=>1}->{($_[0]=~/([-.])[^-.]+[.]\w+$/)[0]}.$_[0]; };
Jan Kratochvil 3b9eb3
	sub trans { return $_[0]; };
Jan Kratochvil 3b9eb3
	my @sorted=sort { my $a1=trans $a; my $b1=trans $b; ($b1 cmp $a1) * ($reverse ? -1 : +1); } @{$arch{$arch}};
Jan Kratochvil 3b9eb3
	do { system $_ and die $_; } for "diff -u tests/'".$sorted[1]."' tests/'".$sorted[0]."' >tests/gdbcompare-'$arch'.sum.diff;true";
Jan Kratochvil 3b9eb3
}
Jan Kratochvil 3b9eb3
Jan Kratochvil 3b9eb3
system("vim tests/gdbcompare-*.sum.diff");