about summary refs log tree commit diff
path: root/pkgs/development/tools/analysis/lcov/find-source.patch
blob: 428ae399d4ea59e63f2a2874f5e96f90c7bdf946 (plain) (blame)
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
81
82
83
84
--- lcov-1.8/bin/geninfo	2010-01-29 11:14:46.000000000 +0100
+++ lcov-1.8/bin/geninfo	2010-04-18 23:33:43.000000000 +0200
@@ -51,6 +51,7 @@
 
 use strict;
 use File::Basename; 
+use Cwd qw(abs_path);
 use File::Spec::Functions qw /abs2rel catdir file_name_is_absolute splitdir
 			      splitpath rel2abs/;
 use Getopt::Long;
@@ -95,6 +96,7 @@ sub match_filename($@);
 sub solve_ambiguous_match($$$);
 sub split_filename($);
 sub solve_relative_path($$);
+sub find_source_file($$);
 sub read_gcov_header($);
 sub read_gcov_file($);
 sub info(@);
@@ -964,7 +966,7 @@ sub process_dafile($$)
 
 		if (defined($source))
 		{
-			$source = solve_relative_path($base_dir, $source);
+ 			$source = find_source_file($base_dir, $source);
 		}
 
 		# gcov will happily create output even if there's no source code
@@ -981,18 +983,9 @@ sub process_dafile($$)
 			die("ERROR: could not read source file $source\n");
 		}
 
-		@matches = match_filename(defined($source) ? $source :
-					  $gcov_file, keys(%{$instr}));
+		next if ! -r $source;
 
-		# 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);
@@ -1242,6 +1235,25 @@ sub solve_relative_path($$)
 }
 
 
+sub find_source_file($$)
+{
+        my ($base_dir, $source) = @_;
+        my $dir = $base_dir;
+
+        # Hack to make absolute paths work on Nixpkgs coverage
+        # reports.  The source is in /nix/store/<bla>/.build/<bla>.
+        $source = $1 if $source =~ /^\/.*\/\.build\/(.*)$/;
+        
+        while (!-e "$dir/$source") {
+                $dir = $dir . "/..";
+                if (length $dir > 1000) {
+                        return "$base_dir/$source";
+                }
+        }
+        return abs_path("$dir/$source");
+}
+
+
 #
 # match_filename(gcov_filename, list)
 #
@@ -1918,7 +1930,7 @@ sub process_graphfile($$)
 
 	# Get path to data file in absolute and normalized form (begins with /,
 	# contains no more ../ or ./)
-	$graph_filename = solve_relative_path($cwd, $graph_filename);
+	$graph_filename = find_source_file($cwd, $graph_filename);
 
 	# Get directory and basename of data file
 	($graph_dir, $graph_basename) = split_filename($graph_filename);