From 54a5ad0c6feefe2147f04d370a19b6e34b79f99e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 31 Aug 2009 15:02:01 +0000 Subject: [PATCH] * Hacked up a patch to let lcov find source files referenced by a path relative to some arbitrary parent of the .gcno file. For instance, this happens when building Subversion with coverage. svn path=/nixpkgs/trunk/; revision=16902 --- .../tools/analysis/lcov/default.nix | 2 + .../tools/analysis/lcov/find-source.patch | 140 ++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 pkgs/development/tools/analysis/lcov/find-source.patch diff --git a/pkgs/development/tools/analysis/lcov/default.nix b/pkgs/development/tools/analysis/lcov/default.nix index 439238b524f..d611f92d051 100644 --- a/pkgs/development/tools/analysis/lcov/default.nix +++ b/pkgs/development/tools/analysis/lcov/default.nix @@ -8,6 +8,8 @@ stdenv.mkDerivation rec { sha256 = "1cx3haizs0rw6wjsn486qcn50f3qpybflkkb1780cg6s8jzcwdin"; }; + patches = [ ./find-source.patch ]; + preBuild = '' makeFlagsArray=(PREFIX=$out BIN_DIR=$out/bin MAN_DIR=$out/share/man) ''; diff --git a/pkgs/development/tools/analysis/lcov/find-source.patch b/pkgs/development/tools/analysis/lcov/find-source.patch new file mode 100644 index 00000000000..015e255824c --- /dev/null +++ b/pkgs/development/tools/analysis/lcov/find-source.patch @@ -0,0 +1,140 @@ +diff -x '*~' -rc lcov-1.7-orig/bin/geninfo lcov-1.7/bin/geninfo +*** lcov-1.7-orig/bin/geninfo 2008-11-17 14:50:26.000000000 +0100 +--- lcov-1.7/bin/geninfo 2009-08-28 18:33:21.000000000 +0200 +*************** +*** 51,56 **** +--- 51,57 ---- + + use strict; + use File::Basename; ++ use Cwd qw(abs_path); + use Getopt::Long; + use Digest::MD5 qw(md5_base64); + +*************** +*** 81,86 **** +--- 82,88 ---- + sub solve_ambiguous_match($$$); + sub split_filename($); + sub solve_relative_path($$); ++ sub find_source_file($$); + sub get_dir($); + sub read_gcov_header($); + sub read_gcov_file($); +*************** +*** 724,730 **** + + if (defined($source)) + { +! $source = solve_relative_path($base_dir, $source); + } + + # gcov will happily create output even if there's no source code +--- 726,732 ---- + + if (defined($source)) + { +! $source = find_source_file($base_dir, $source); + } + + # gcov will happily create output even if there's no source code +*************** +*** 741,758 **** + die("ERROR: could not read source file $source\n"); + } + +! @matches = match_filename(defined($source) ? $source : +! $gcov_file, keys(%bb_content)); + + # Skip files that are not mentioned in the graph file +! if (!@matches) +! { +! warn("WARNING: cannot find an entry for ".$gcov_file. +! " in $graph_file_extension file, skipping ". +! "file!\n"); +! unlink($gcov_file); +! next; +! } + + # Read in contents of gcov file + @result = read_gcov_file($gcov_file); +--- 743,764 ---- + die("ERROR: could not read source file $source\n"); + } + +! next if ! -r $source; +! +! #@matches = match_filename(defined($source) ? $source : +! # $gcov_file, keys(%bb_content)); + + # Skip files that are not mentioned in the graph file +! #if (!@matches) +! #{ +! # warn("WARNING: cannot find an entry for ".$gcov_file. +! # " in $graph_file_extension file, skipping ". +! # "file!\n"); +! # unlink($gcov_file); +! # next; +! #} +! +! @matches = ($source); + + # Read in contents of gcov file + @result = read_gcov_file($gcov_file); +*************** +*** 949,954 **** +--- 955,974 ---- + } + + ++ sub find_source_file($$) ++ { ++ my ($base_dir, $source) = @_; ++ my $dir = $base_dir; ++ while (!-e "$dir/$source") { ++ $dir = $dir . "/.."; ++ if (length $dir > 1000) { ++ return "$base_dir/$source"; ++ } ++ } ++ return abs_path("$dir/$source"); ++ } ++ ++ + # + # match_filename(gcov_filename, list) + # +*************** +*** 1478,1484 **** + $function_name =~ s/\W/_/g; + (undef, $filename) = + read_gcno_string(*INPUT, $endianness); +! $filename = solve_relative_path($base_dir, $filename); + + read(INPUT, $packed_word, 4); + $lineno = unpack_int32($packed_word, $endianness); +--- 1498,1504 ---- + $function_name =~ s/\W/_/g; + (undef, $filename) = + read_gcno_string(*INPUT, $endianness); +! $filename = find_source_file($base_dir, $filename); + + read(INPUT, $packed_word, 4); + $lineno = unpack_int32($packed_word, $endianness); +*************** +*** 1530,1536 **** + } + if ($blocks > 1) + { +! $filename = solve_relative_path( + $base_dir, $filename); + if (!defined($result{$filename})) + { +--- 1550,1556 ---- + } + if ($blocks > 1) + { +! $filename = find_source_file( + $base_dir, $filename); + if (!defined($result{$filename})) + {