From: Daniel Stenberg Date: Mon, 25 Sep 2023 07:42:12 +0000 (+0200) Subject: singleuse: add scan for use in other source codes X-Git-Tag: curl-8_4_0~139 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d27576b2adf79553de89c5e694cf76d1c44a655f;p=thirdparty%2Fcurl.git 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 --- diff --git a/scripts/singleuse.pl b/scripts/singleuse.pl index 48dd3387fb..7b0b099647 100755 --- a/scripts/singleuse.pl +++ b/scripts/singleuse.pl @@ -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() { + 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_/) {