singleuse: add scan for use in other source codes
This should reduce false-positive to almost zero. Checks for presence in unit tests if --unit is specified, which is intended for debug builds where unit testing is enabled. Closes #11932
This commit is contained in:
Родитель
d850eea2d0
Коммит
d27576b2ad
|
@ -28,39 +28,21 @@
|
|||
#
|
||||
# Use it like this:
|
||||
#
|
||||
# $ ./scripts/singleuse.pl lib/.libs/libcurl.a
|
||||
# $ ./scripts/singleuse.pl [--unit] lib/.libs/libcurl.a
|
||||
#
|
||||
# Be aware that it might cause false positives due to various build options.
|
||||
# --unit : built to support unit tests
|
||||
#
|
||||
|
||||
my $unittests;
|
||||
if($ARGV[0] eq "--unit") {
|
||||
$unittests = "tests/unit ";
|
||||
shift @ARGV;
|
||||
}
|
||||
|
||||
my $file = $ARGV[0];
|
||||
|
||||
my %wl = (
|
||||
'Curl_none_cert_status_request' => 'multiple TLS backends',
|
||||
'Curl_none_check_cxn' => 'multiple TLS backends',
|
||||
'Curl_none_cleanup' => 'multiple TLS backends',
|
||||
'Curl_none_close_all' => 'multiple TLS backends',
|
||||
'Curl_none_data_pending' => 'multiple TLS backends',
|
||||
'Curl_none_engines_list' => 'multiple TLS backends',
|
||||
'Curl_none_init' => 'multiple TLS backends',
|
||||
'Curl_none_md5sum' => 'multiple TLS backends',
|
||||
'Curl_none_random' => 'multiple TLS backends',
|
||||
'Curl_none_session_free' => 'multiple TLS backends',
|
||||
'Curl_none_set_engine' => 'multiple TLS backends',
|
||||
'Curl_none_set_engine_default' => 'multiple TLS backends',
|
||||
'Curl_none_shutdown' => 'multiple TLS backends',
|
||||
'Curl_multi_dump' => 'debug build only',
|
||||
'Curl_parse_port' => 'UNITTEST',
|
||||
'Curl_shuffle_addr' => 'UNITTEST',
|
||||
'de_cleanup' => 'UNITTEST',
|
||||
'doh_decode' => 'UNITTEST',
|
||||
'doh_encode' => 'UNITTEST',
|
||||
'Curl_auth_digest_get_pair' => 'by digest_sspi',
|
||||
'curlx_uztoso' => 'cmdline tool use',
|
||||
'curlx_uztoul' => 'by krb5_sspi',
|
||||
'curlx_uitous' => 'by schannel',
|
||||
'Curl_islower' => 'by curl_fnmatch',
|
||||
'getaddressinfo' => 'UNITTEST',
|
||||
);
|
||||
|
||||
my %api = (
|
||||
|
@ -161,6 +143,23 @@ my %api = (
|
|||
'curl_easy_perform_ev' => 'debug-build',
|
||||
);
|
||||
|
||||
sub doublecheck {
|
||||
my ($f, $used) = @_;
|
||||
open(F, "git grep -le '$f\\W' -- lib ${unittests}packages|");
|
||||
my @also;
|
||||
while(<F>) {
|
||||
my $e = $_;
|
||||
chomp $e;
|
||||
if($e =~ /\.[c]$/) {
|
||||
if($e !~ /^lib\/${used}\.c/) {
|
||||
push @also, $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
close(F);
|
||||
return @also;
|
||||
}
|
||||
|
||||
open(N, "nm $file|") ||
|
||||
die;
|
||||
|
||||
|
@ -207,8 +206,15 @@ for(sort keys %exist) {
|
|||
#print "$_ is WL\n";
|
||||
}
|
||||
else {
|
||||
printf "%s is defined in %s, but not used outside\n", $_, $exist{$_};
|
||||
$err++;
|
||||
my $c = $_;
|
||||
my @also = doublecheck($c, $exist{$c});
|
||||
if(!scalar(@also)) {
|
||||
printf "%s in %s\n", $c, $exist{$c};
|
||||
$err++;
|
||||
}
|
||||
# foreach my $a (@also) {
|
||||
# print " $a\n";
|
||||
# }
|
||||
}
|
||||
}
|
||||
elsif($_ =~ /^curl_/) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче