Skip to content

Commit ccd7608

Browse files
committed
Add message type 'usage' to report tool usage/parameter issues
Signed-off-by: Henry Cox <[email protected]>
1 parent 0653f1e commit ccd7608

File tree

7 files changed

+58
-25
lines changed

7 files changed

+58
-25
lines changed

bin/genhtml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5499,11 +5499,11 @@ if (@SourceFile::annotateScript) {
54995499
}
55005500
if (0 != (defined($diff_filename) ^ (0 != scalar(@base_filenames)))) {
55015501
if (@base_filenames) {
5502-
warn(
5502+
lcovutil::ignorable_warning($lcovutil::ERROR_USAGE,
55035503
"Specified --baseline-file without --diff-file: assuming no source differences. Hope that is OK.\n"
55045504
);
55055505
} else {
5506-
warn(
5506+
lcovutil::ignorable_warning($lcovutil::ERROR_USAGE,
55075507
"Specified --diff-file without --baseline-file: assuming baseline code coverage was empty (nothing covered). Hope that is OK\n"
55085508
);
55095509
# OK..just assume that the baseline is empty...
@@ -5633,14 +5633,15 @@ $html_epilog = get_html_epilog($html_epilog_file);
56335633

56345634
# Issue a warning if --no-sourceview is enabled together with --frames
56355635
if ($no_sourceview && defined($frames)) {
5636-
warn("option --frames disabled because --no-sourceview " .
5637-
"was specified!\n");
5636+
lcovutil::ignorable_warning($lcovutil::ERROR_USAGE,
5637+
"option --frames disabled because --no-sourceview was specified.");
56385638
$frames = undef;
56395639
}
56405640

56415641
# Issue a warning if --no-prefix is enabled together with --prefix
56425642
if ($no_prefix && @dir_prefix) {
5643-
warn("option --prefix disabled because --no-prefix was " . "specified!\n");
5643+
lcovutil::ignorable_warning($lcovutil::ERROR_USAGE,
5644+
"option --prefix disabled because --no-prefix was ignored");
56445645
@dir_prefix = undef;
56455646
}
56465647

bin/geninfo

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,8 @@ if ($gcov_version >= (9 << 16) &&
424424
if ($intermediate) {
425425
info("Using intermediate gcov format\n");
426426
if ($opt_derive_func_data) {
427-
warn("--derive-func-data is not compatible with " .
428-
"intermediate format - ignoring\n");
427+
lcovutil::ignorable_error($lcovutil::ERROR_USAGE,
428+
"--derive-func-data is not compatible with intermediate format");
429429
$opt_derive_func_data = 0;
430430
}
431431
if ($lcovutil::exclude_exception_branch && !$gcov_caps->{'json-format'}) {
@@ -578,7 +578,8 @@ foreach my $dir (@lcovutil::internal_dirs) {
578578
}
579579

580580
if ($initial && $lcovutil::br_coverage && !$intermediate) {
581-
warn("--initial does not generate branch coverage data\n");
581+
lcovutil::ignorable_error($lcovutil::ERROR_USAGE,
582+
"--initial does not generate branch coverage data");
582583
}
583584

584585
# where to write parallel child data
@@ -1018,6 +1019,11 @@ sub gen_info(@)
10181019
my %files;
10191020
my $total = 0;
10201021
foreach my $directory (@_) {
1022+
unless (-e $directory) {
1023+
lcovutil::ignorable_error($lcovutil::ERROR_USAGE,
1024+
"no such file or directory '$directory'");
1025+
next;
1026+
}
10211027
if (-d $directory) {
10221028
info("Scanning $directory for $ext files ...\n");
10231029

@@ -1040,22 +1046,37 @@ sub gen_info(@)
10401046
# keep track of directory where we found the file
10411047
foreach my $entry (@found) {
10421048
if (exists($files{$entry})) {
1043-
warn("duplicate file $directory in both $directory and " .
1044-
$files{$entry} . "\n");
1049+
lcovutil::ignorable_error(
1050+
$lcovutil::ERROR_USAGE,
1051+
"duplicate file $entry in both $files{$entry} and $directory"
1052+
.
1053+
(lcovutil::is_ignored($lcovutil::ERROR_USAGE) ?
1054+
' (skip latter)' :
1055+
''));
1056+
next;
10451057
} else {
10461058
++$total;
10471059
}
10481060
$files{$entry} = $directory;
10491061
}
10501062
} else {
1051-
die("no such file or directory '$directory'")
1052-
unless (-e $directory);
1063+
my ($name, $d, $e) = fileparse($directory, qr/\.[^.]*/);
1064+
if ($e ne $ext) {
1065+
lcovutil::ignorable_error($lcovutil::ERROR_USAGE,
1066+
"$directory has unsupported extension: expected '$ext'" .
1067+
($initial ? " for initial capture" : ""));
1068+
next;
1069+
}
10531070
# use the directory where we find the file as the base dir
1054-
my $d = dirname($directory);
1055-
10561071
if (exists($files{$directory})) {
1057-
warn("duplicate file $directory in both $d and " .
1058-
$files{$directory} . "\n");
1072+
lcovutil::ignorable_error(
1073+
$lcovutil::ERROR_USAGE,
1074+
"duplicate file $directory in both $files{$directory} and $d"
1075+
.
1076+
(lcovutil::is_ignored($lcovutil::ERROR_USAGE) ?
1077+
' (skip latter)' :
1078+
''));
1079+
next;
10591080
} else {
10601081
++$total;
10611082
}
@@ -1098,9 +1119,6 @@ sub gen_info(@)
10981119
lcovutil::info(2, "schedule %s in %d\n", $filename, scalar(@worklist));
10991120
# find the corresponding gcno file...
11001121
my ($name, $d, $e) = fileparse($filename, qr/\.[^.]*/);
1101-
die("unexpected extension '$e': should be $ext" .
1102-
($initial ? " for initial capture" : ""))
1103-
unless ($e eq $ext);
11041122
my ($gcda_file, $gcno_file);
11051123
if ($initial) {
11061124
$gcno_file = $filename;

bin/lcov

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ if (!($lcovutil::lcov_capture || @add_tracefile) &&
290290
foreach my $e (@lcovutil::extractVersionScript) {
291291
$e = "'$e'" if ($e =~ /\s/);
292292
}
293-
warn("--version-script ignored except with --capture or --add-tracefile");
293+
lcovutil::ignorable_warning($lcovutil::ERROR_USAGE,
294+
"--version-script ignored except with --capture or --add-tracefile");
294295
}
295296

296297
# Check list width option
@@ -324,7 +325,8 @@ if (@ARGV &&
324325

325326
if (defined($lcovutil::opt_no_external) &&
326327
!(defined($lcovutil::lcov_capture) && $lcovutil::lcov_capture != 0)) {
327-
warn("'--no-external' is ignored except in 'lcov --capture|-c'\n");
328+
lcovutil::ignorable_warning($lcovutil::ERROR_USAGE,
329+
"'--no-external' is ignored except in 'lcov --capture|-c'\n");
328330
$lcovutil::opt_no_external = 0;
329331
}
330332

@@ -616,7 +618,8 @@ sub userspace_reset()
616618
my $count = 0;
617619
foreach my $current_dir (@dirs) {
618620
if (!-d $current_dir) {
619-
warn("$current_dir is not a directory - skpping\n");
621+
lcovutil::ignorable_error($lcovutil::ERROR_USAGE,
622+
"$current_dir is not a directory");
620623
next;
621624
}
622625
++$count;

lib/lcovutil.pm

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ our @EXPORT_OK = qw($tool_name $tool_dir $lcov_version $lcov_url
6666
$ERROR_BRANCH $ERROR_EMPTY $ERROR_FORMAT $ERROR_VERSION $ERROR_UNUSED
6767
$ERROR_PACKAGE $ERROR_CORRUPT $ERROR_NEGATIVE $ERROR_COUNT
6868
$ERROR_UNSUPPORTED $ERROR_DEPRECATED $ERROR_INCONSISTENT_DATA
69-
$ERROR_CALLBACK $ERROR_RANGE $ERROR_UTILITY
69+
$ERROR_CALLBACK $ERROR_RANGE $ERROR_UTILITY $ERROR_USAGE
7070
$ERROR_PARALLEL report_parallel_error
7171
$stop_on_error
7272
@@ -123,6 +123,7 @@ our $ERROR_CALLBACK = 16; # callback produced an error
123123
our $ERROR_INCONSISTENT_DATA = 17; # somthing wrong with .info
124124
our $ERROR_RANGE = 18; # line number out of range
125125
our $ERROR_UTILITY = 19; # some tool failed - e.g., 'find'
126+
our $ERROR_USAGE = 20; # misusing some feature
126127

127128
our %geninfoErrs = ("gcov" => $ERROR_GCOV,
128129
"source" => $ERROR_SOURCE,
@@ -143,6 +144,7 @@ our %geninfoErrs = ("gcov" => $ERROR_GCOV,
143144
"deprecated" => $ERROR_DEPRECATED,
144145
"callback" => $ERROR_CALLBACK,
145146
'utility' => $ERROR_UTILITY,
147+
'usage' => $ERROR_USAGE,
146148
"package" => $ERROR_PACKAGE,);
147149
our $stop_on_error; # attempt to keep going
148150
our $warn_once_per_file = 1;
@@ -1205,8 +1207,8 @@ sub munge_file_patterns
12051207
last;
12061208
}
12071209
}
1208-
warn(
1209-
"--$flag pattern '$pat' does not seem to be case insensitive - but you asked for case insenstive matching\n"
1210+
lcovutil::ignorable_warning($lcovutil::ERROR_USAGE,
1211+
"--$flag pattern '$pat' does not seem to be case insensitive - but you asked for case insenstive matching"
12101212
);
12111213
}
12121214
}

man/genhtml.1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,6 +2198,9 @@ The requested feature is not supported for this tool configuration. For example
21982198
The include/exclude/erase/substitute/omit pattern did not match any file pathnames.
21992199
.br
22002200

2201+
.B usage:
2202+
unsupported usage detected - e.g. an unsupported option combination.
2203+
22012204
.B utility:
22022205
a tool called during processing returned an error code (e.g., 'find' encountered an unreadable directory).
22032206

man/geninfo.1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,9 @@ the requested feature is not supported for this tool configuration. For example
789789
.B unused:
790790
the include/exclude/erase/omit/substitute pattern did not match any file pathnames.
791791

792+
.B usage:
793+
unsupported usage detected - e.g. an unsupported option combination.
794+
792795
.B utility:
793796
a tool called during processing returned an error code (e.g., 'find' encountered an unreadable directory).
794797

man/lcov.1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,9 @@ the requested feature is not supported for this tool configuration. For example
11321132
.B unused:
11331133
the include/exclude/erase/omit/substitute pattern did not match any file pathnames.
11341134

1135+
.B usage:
1136+
unsupported usage detected - e.g. an unsupported option combination.
1137+
11351138
.B utility:
11361139
a tool called during processing returned an error code (e.g., 'find' encountered an unreadable directory).
11371140

0 commit comments

Comments
 (0)