Skip to content

Commit a357297

Browse files
ggouaillardetoberpar
authored andcommitted
genhtml: support a comma separated list of prefixes
the --prefix option of genhtml now takes a comma separated list of prefixes instead of a single prefix. this can be required when running lcov vs projects configure'd with VPATH and in which source files are both in the source and build directories. Signed-off-by: Gilles Gouaillardet <[email protected]>
1 parent 231cfb6 commit a357297

File tree

1 file changed

+68
-27
lines changed

1 file changed

+68
-27
lines changed

bin/genhtml

Lines changed: 68 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ sub get_affecting_tests($$$);
194194
sub combine_info_files($$);
195195
sub merge_checksums($$$);
196196
sub combine_info_entries($$$);
197-
sub apply_prefix($$);
197+
sub apply_prefix($@);
198198
sub system_no_output($@);
199199
sub read_config($);
200200
sub apply_config($);
@@ -212,6 +212,7 @@ sub get_br_found_and_hit($);
212212
sub warn_handler($);
213213
sub die_handler($);
214214
sub parse_ignore_errors(@);
215+
sub parse_dir_prefix(@);
215216
sub rate($$;$$$);
216217

217218

@@ -259,7 +260,8 @@ sub gen_png($$$@);
259260

260261
# Global variables & initialization
261262
our %info_data; # Hash containing all data from .info file
262-
our $dir_prefix; # Prefix to remove from all sub directories
263+
our @opt_dir_prefix; # Array of prefixes to remove from all sub directories
264+
our @dir_prefix;
263265
our %test_description; # Hash containing test descriptions if available
264266
our $date = get_date_string();
265267

@@ -402,7 +404,7 @@ if (!GetOptions("output-directory|o=s" => \$output_directory,
402404
"keep-descriptions|k" => \$keep_descriptions,
403405
"css-file|c=s" => \$css_filename,
404406
"baseline-file|b=s" => \$base_filename,
405-
"prefix|p=s" => \$dir_prefix,
407+
"prefix|p=s" => \@opt_dir_prefix,
406408
"num-spaces=i" => \$tab_size,
407409
"no-prefix" => \$no_prefix,
408410
"no-sourceview" => \$no_sourceview,
@@ -466,6 +468,9 @@ if ($version)
466468
# Determine which errors the user wants us to ignore
467469
parse_ignore_errors(@opt_ignore_errors);
468470

471+
# Split the list of prefixes if needed
472+
parse_dir_prefix(@opt_dir_prefix);
473+
469474
# Check for info filename
470475
if (!@info_filenames)
471476
{
@@ -519,11 +524,11 @@ if ($no_sourceview && defined($frames))
519524
}
520525

521526
# Issue a warning if --no-prefix is enabled together with --prefix
522-
if ($no_prefix && defined($dir_prefix))
527+
if ($no_prefix && @dir_prefix)
523528
{
524529
warn("WARNING: option --prefix disabled because --no-prefix was ".
525530
"specified!\n");
526-
$dir_prefix = undef;
531+
@dir_prefix = undef;
527532
}
528533

529534
@fileview_sortlist = ($SORT_FILE);
@@ -869,14 +874,16 @@ sub gen_html()
869874
# User requested that we leave filenames alone
870875
info("User asked not to remove filename prefix\n");
871876
}
872-
elsif (!defined($dir_prefix))
877+
elsif (! @dir_prefix)
873878
{
874879
# Get prefix common to most directories in list
875-
$dir_prefix = get_prefix(1, keys(%info_data));
880+
my $prefix = get_prefix(1, keys(%info_data));
876881

877-
if ($dir_prefix)
882+
if ($prefix)
878883
{
879-
info("Found common filename prefix \"$dir_prefix\"\n");
884+
info("Found common filename prefix \"$prefix\"\n");
885+
$dir_prefix[0] = $prefix;
886+
880887
}
881888
else
882889
{
@@ -886,11 +893,17 @@ sub gen_html()
886893
}
887894
else
888895
{
889-
info("Using user-specified filename prefix \"".
890-
"$dir_prefix\"\n");
891-
$dir_prefix =~ s/\/+$//;
896+
my $msg = "Using user-specified filename prefix ";
897+
for my $i (0 .. $#dir_prefix)
898+
{
899+
$dir_prefix[$i] =~ s/\/+$//;
900+
$msg .= ", " unless 0 == $i;
901+
$msg .= "\"" . $dir_prefix[$i] . "\"";
902+
}
903+
info($msg . "\n");
892904
}
893905

906+
894907
# Read in test description file if specified
895908
if ($desc_filename)
896909
{
@@ -936,10 +949,10 @@ sub gen_html()
936949
$dir_name = "root" if ($dir_name eq "");
937950

938951
# Remove prefix if applicable
939-
if (!$no_prefix && $dir_prefix)
952+
if (!$no_prefix && @dir_prefix)
940953
{
941-
# Match directory names beginning with $dir_prefix
942-
$dir_name = apply_prefix($dir_name, $dir_prefix);
954+
# Match directory names beginning with one of @dir_prefix
955+
$dir_name = apply_prefix($dir_name,@dir_prefix);
943956
}
944957

945958
# Generate name for directory overview HTML page
@@ -1077,8 +1090,8 @@ sub process_dir($)
10771090
# Remove prefix if applicable
10781091
if (!$no_prefix)
10791092
{
1080-
# Match directory name beginning with $dir_prefix
1081-
$rel_dir = apply_prefix($rel_dir, $dir_prefix);
1093+
# Match directory name beginning with one of @dir_prefix
1094+
$rel_dir = apply_prefix($rel_dir,@dir_prefix);
10821095
}
10831096

10841097
$trunc_dir = $rel_dir;
@@ -1260,7 +1273,7 @@ sub write_function_page($$$$$$$$$$$$$$$$$$)
12601273

12611274
sub process_file($$$)
12621275
{
1263-
info("Processing file ".apply_prefix($_[2], $dir_prefix)."\n");
1276+
info("Processing file ".apply_prefix($_[2], @dir_prefix)."\n");
12641277

12651278
my $trunc_dir = $_[0];
12661279
my $rel_dir = $_[1];
@@ -5704,22 +5717,25 @@ sub remove_unused_descriptions()
57045717

57055718

57065719
#
5707-
# apply_prefix(filename, prefix)
5720+
# apply_prefix(filename, PREFIXES)
57085721
#
5709-
# If FILENAME begins with PREFIX, remove PREFIX from FILENAME and return
5710-
# resulting string, otherwise return FILENAME.
5722+
# If FILENAME begins with PREFIX from PREFIXES, remove PREFIX from FILENAME
5723+
# and return resulting string, otherwise return FILENAME.
57115724
#
57125725

5713-
sub apply_prefix($$)
5726+
sub apply_prefix($@)
57145727
{
5715-
my $filename = $_[0];
5716-
my $prefix = $_[1];
5728+
my $filename = shift;
5729+
my @dir_prefix = @_;
57175730

5718-
if (defined($prefix) && ($prefix ne ""))
5731+
if (@dir_prefix)
57195732
{
5720-
if ($filename =~ /^\Q$prefix\E\/(.*)$/)
5733+
foreach my $prefix (@dir_prefix)
57215734
{
5722-
return substr($filename, length($prefix) + 1);
5735+
if ($prefix ne "" && $filename =~ /^\Q$prefix\E\/(.*)$/)
5736+
{
5737+
return substr($filename, length($prefix) + 1);
5738+
}
57235739
}
57245740
}
57255741

@@ -5975,6 +5991,31 @@ sub parse_ignore_errors(@)
59755991
}
59765992
}
59775993

5994+
#
5995+
# parse_dir_prefix(@dir_prefix)
5996+
#
5997+
# Parse user input about the prefix list
5998+
#
5999+
6000+
sub parse_dir_prefix(@)
6001+
{
6002+
my (@opt_dir_prefix) = @_;
6003+
my $item;
6004+
6005+
return if (!@opt_dir_prefix);
6006+
6007+
foreach $item (@opt_dir_prefix) {
6008+
$item =~ s/\s//g;
6009+
if ($item =~ /,/) {
6010+
# Split and add comma-separated parameters
6011+
push(@dir_prefix, split(/,/, $item));
6012+
} else {
6013+
# Add single parameter
6014+
push(@dir_prefix, $item);
6015+
}
6016+
}
6017+
}
6018+
59786019
#
59796020
# rate(hit, found[, suffix, precision, width])
59806021
#

0 commit comments

Comments
 (0)