Skip to content

Commit b9de825

Browse files
committed
lcov: Enable userspace package capture with only data files
Previously lcov's --from-package capture mechanism required that .gcno files and source were present on the test machine. This patch modifies --from-package capturing to work when only .gcda files are present in the package captured on the test machine. It works by linking the .gcda files collected on the test machine into their natural location on the build machine. This requires existing .gcda files to be removed. Signed-off-by: Peter Oberparleiter <[email protected]>
1 parent 0e4f090 commit b9de825

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

bin/geninfo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ sub gen_info($)
710710
{
711711
info("Scanning $directory for $ext files ...\n");
712712

713-
@file_list = `find "$directory" $maxdepth $follow -name \\*$ext -type f 2>/dev/null`;
713+
@file_list = `find "$directory" $maxdepth $follow -name \\*$ext -type f -o -type l 2>/dev/null`;
714714
chomp(@file_list);
715715
if (!@file_list) {
716716
warn("WARNING: no $ext files found in $directory - ".

bin/lcov

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,84 @@ sub kernel_capture()
12851285
kernel_capture_from_dir($data_dir, $gcov_gkv, $build);
12861286
}
12871287

1288+
#
1289+
# link_data_cb(datadir, rel, graphdir)
1290+
#
1291+
# Create symbolic link in GRAPDIR/REL pointing to DATADIR/REL.
1292+
#
1293+
1294+
sub link_data_cb($$$)
1295+
{
1296+
my ($datadir, $rel, $graphdir) = @_;
1297+
my $absfrom = catfile($datadir, $rel);
1298+
my $absto = catfile($graphdir, $rel);
1299+
my $base;
1300+
my $dir;
1301+
1302+
if (-e $absto) {
1303+
die("ERROR: could not create symlink at $absto: ".
1304+
"File already exists!\n");
1305+
}
1306+
if (-l $absto) {
1307+
# Broken link - possibly from an interrupted earlier run
1308+
unlink($absto);
1309+
}
1310+
1311+
# Check for graph file
1312+
$base = $absto;
1313+
$base =~ s/\.(gcda|da)$//;
1314+
if (! -e $base.".gcno" && ! -e $base.".bbg" && ! -e $base.".bb") {
1315+
die("ERROR: No graph file found for $absfrom in ".
1316+
dirname($base)."!\n");
1317+
}
1318+
1319+
symlink($absfrom, $absto) or
1320+
die("ERROR: could not create symlink at $absto: $!\n");
1321+
}
1322+
1323+
#
1324+
# unlink_data_cb(datadir, rel, graphdir)
1325+
#
1326+
# Remove symbolic link from GRAPHDIR/REL to DATADIR/REL.
1327+
#
1328+
1329+
sub unlink_data_cb($$$)
1330+
{
1331+
my ($datadir, $rel, $graphdir) = @_;
1332+
my $absfrom = catfile($datadir, $rel);
1333+
my $absto = catfile($graphdir, $rel);
1334+
my $target;
1335+
1336+
return if (!-l $absto);
1337+
$target = readlink($absto);
1338+
return if (!defined($target) || $target ne $absfrom);
1339+
1340+
unlink($absto) or
1341+
warn("WARNING: could not remove symlink $absto: $!\n");
1342+
}
1343+
1344+
#
1345+
# link_data(datadir, graphdir, create)
1346+
#
1347+
# If CREATE is non-zero, create symbolic links in GRAPHDIR for data files
1348+
# found in DATADIR. Otherwise remove link in GRAPHDIR.
1349+
#
1350+
1351+
sub link_data($$$)
1352+
{
1353+
my ($datadir, $graphdir, $create) = @_;
1354+
1355+
$datadir = abs_path($datadir);
1356+
$graphdir = abs_path($graphdir);
1357+
if ($create) {
1358+
lcov_find($datadir, \&link_data_cb, $graphdir, '\.gcda$',
1359+
'\.da$');
1360+
} else {
1361+
lcov_find($datadir, \&unlink_data_cb, $graphdir, '\.gcda$',
1362+
'\.da$');
1363+
}
1364+
}
1365+
12881366
#
12891367
# package_capture()
12901368
#
@@ -1320,7 +1398,9 @@ sub package_capture()
13201398
} else {
13211399
# Build directory needs to be passed to geninfo
13221400
$base_directory = $build;
1323-
lcov_geninfo($dir);
1401+
link_data($dir, $base_directory, 1);
1402+
lcov_geninfo($base_directory);
1403+
link_data($dir, $base_directory, 0);
13241404
}
13251405
}
13261406

0 commit comments

Comments
 (0)