Skip to content

Commit

Permalink
Bugfix: 'genhtml --prefix' fails if prefix directory contains source
Browse files Browse the repository at this point in the history
files.  See #245

Signed-off-by:  Henry Cox <henry.cox@mediatek.com>
  • Loading branch information
henry2cox committed Nov 6, 2023
1 parent b90c76d commit bf135ca
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 15 deletions.
32 changes: 28 additions & 4 deletions bin/genhtml
Original file line number Diff line number Diff line change
Expand Up @@ -5971,11 +5971,35 @@ sub gen_html()
$no_prefix = 1;
}
} else {
my $msg = "Using user-specified filename prefix ";
for my $i (0 .. $#dir_prefix) {
$dir_prefix[$i] =~ s/$lcovutil::dirseparator+$//;
my $msg = "Using user-specified filename prefix ";
my $dirs = $current_data->directories();
my $i = 0;
# somewhat of a hack: the layout code doesn't react well when
# the 'prefix' directory contains source files (as opposed to
# containing a directory which contains source files).
# Rather than trying to handle that special case, just munge the
# prefix to be something we like better.
while ($i <= $#dir_prefix) {
my $p = $dir_prefix[$i];
# remove redundant /'s
$p =~ s/$lcovutil::dirseparator+$//;
$p = substr($p, 0, -1)
if $lcovutil::dirseparator eq substr($p, -1);
while (exists($dirs->{$p}) && $p) {
$p = File::Basename::dirname($p);
}
unless ($p) {
lcovutil::info("skipping prefix $dir_prefix[$i]\n");
splice(@dir_prefix, $i, 1);
next;
}
lcovutil::info(
"using prefix '$p' (rather than '$dir_prefix[$i]')\n")
if ($p ne $dir_prefix[$i]);
$dir_prefix[$i] = $p;
$msg .= ", " unless 0 == $i;
$msg .= "\"" . $dir_prefix[$i] . "\"";
$msg .= "\"" . $p . "\"";
++$i;
}
info($msg . "\n");
}
Expand Down
13 changes: 13 additions & 0 deletions lib/lcovutil.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5213,6 +5213,19 @@ sub files
return keys %{$self->[FILES]};
}

sub directories
{
my $self = shift;
# return hash of directories whcih contain source files
my %dirs;
foreach my $f ($self->files()) {
my $d = File::Basename::dirname($f);
$dirs{$d} = [] unless exists($dirs{$d});
push(@{$dirs{$d}}, $f);
}
return \%dirs;
}

sub file_exists
{
my ($self, $name) = @_;
Expand Down
55 changes: 44 additions & 11 deletions tests/gendiffcov/simple/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ DIFFCOV_OPTS="--function-coverage --branch-coverage --highlight --demangle-cpp -
#DIFFCOV_OPTS="--function-coverage --branch-coverage --highlight --demangle-cpp --frame"
#DIFFCOV_OPTS='--function-coverage --branch-coverage --highlight --demangle-cpp'

rm -f test.cpp *.gcno *.gcda a.out *.info *.info.gz diff.txt diff_r.txt diff_broken.txt *.log *.err *.json dumper* results.xlsx annotate.{cpp,exe}
rm -rf ./cover_db ./baseline ./current ./differential* ./reverse ./diff_no_baseline ./no_baseline ./no_annotation ./no_owners differential_nobranch reverse_nobranch baseline-filter* noncode_differential* broken mismatchPath elidePath ./cover_db ./criteria ./mismatched ./navigation differential_prop proportion ./annotate
rm -f test.cpp *.gcno *.gcda a.out *.info *.info.gz diff.txt diff_r.txt diff_broken.txt *.log *.err *.json dumper* results.xlsx annotate.{cpp,exe} c d
rm -rf ./cover_db ./baseline ./current ./differential* ./reverse ./diff_no_baseline ./no_baseline ./no_annotation ./no_owners differential_nobranch reverse_nobranch baseline-filter* noncode_differential* broken mismatchPath elidePath ./cover_db ./criteria ./mismatched ./navigation differential_prop proportion ./annotate ./current-* ./current_prefix*

if [ "x$COVER" != 'x' ] && [ 0 != $LOCAL_COVERAGE ] ; then
cover -delete
Expand Down Expand Up @@ -358,16 +358,49 @@ if [ 0 != $? ] ; then
fi
fi
#genhtml current.info --output-directory ./current
echo genhtml $DIFFCOV_OPTS --show-details current.info --output-directory ./current $IGNORE
$COVER $LCOV_HOME/bin/genhtml $DIFFCOV_OPTS current.info --show-details --output-directory ./current $IGNORE
if [ 0 != $? ] ; then
echo "ERROR: genhtml current failed"
status=1
if [ 0 == $KEEP_GOING ] ; then
exit 1
# check that vanilla, flat, hierarchical work with and without prefix
now=`date`
for mode in '' '--flat' '--hierarchical' ; do
echo genhtml $DIFFCOV_OPTS $mode --show-details current.info --output-directory ./current$mode $IGNORE
$COVER $LCOV_HOME/bin/genhtml $mode $DIFFCOV_OPTS current.info --show-details --output-directory ./current$mode $IGNORE --current-date "$now"
if [ 0 != $? ] ; then
echo "ERROR: genhtml current $mode failed"
status=1
if [ 0 == $KEEP_GOING ] ; then
exit 1
fi
fi
fi
# run again with prefix
echo genhtml $DIFFCOV_OPTS $mode --show-details current.info --output-directory ./current_prefix$mode $IGNORE --prefix `pwd`
$COVER $LCOV_HOME/bin/genhtml $mode $DIFFCOV_OPTS current.info --show-details --output-directory ./current_prefix$mode $IGNORE --prefix `pwd` --current-date "$now"
if [ 0 != $? ] ; then
echo "ERROR: genhtml current $mode --prefix failed"
status=1
if [ 0 == $KEEP_GOING ] ; then
exit 1
fi
fi
diff current$mode/index.html current_prefix$mode/index.html
if [ 0 != $? ] ; then
echo "ERROR: diff current $mode --prefix failed"
status=1
if [ 0 == $KEEP_GOING ] ; then
exit 1
fi
fi
# and content should be the same
ls current$mode > c
ls current_prefix$mode > d
diff c d
if [ 0 != $? ] ; then
echo "ERROR: diff current $mode content differs"
status=1
if [ 0 == $KEEP_GOING ] ; then
exit 1
fi
fi
done
diff -u simple.cpp simple2.cpp | sed -e "s|simple2*\.cpp|$ROOT/test.cpp|g" > diff.txt
Expand Down

0 comments on commit bf135ca

Please sign in to comment.