]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix util/find-doc-nits' check_env_vars to show where envvars were found
authorRichard Levitte <levitte@openssl.org>
Thu, 18 Sep 2025 09:29:10 +0000 (11:29 +0200)
committerNeil Horman <nhorman@openssl.org>
Thu, 30 Oct 2025 12:12:06 +0000 (08:12 -0400)
This displays the list of files with line number for each envvar.

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/28601)

util/find-doc-nits

index 06bcb1986219c24d1d54fa5b3121431fb4a86a97..28573a6269424c5470f1903aac76c16f0227f4cd 100755 (executable)
@@ -1348,13 +1348,14 @@ sub check_env_vars {
         while (my $line = <$fh>) {
             # for windows
             # for .in files
-            $env_list{$1} = 1 if ($line =~ /GetEnvironmentVariableW\([\s\S]*"([^"]+)",/
-                || $line =~ /\$ENV\{([^}"']+)\}/);
+            push @{$env_list{$1}}, "${filename}:$."
+                if ($line =~ /GetEnvironmentVariableW\([\s\S]*"([^"]+)",/
+                    || $line =~ /\$ENV\{([^}"']+)\}/);
             # this also handles ossl_safe_getenv
             if ($line =~ /getenv\(([^()\s]+)\)/) {
                 my $env1 = $1;
                 if ($env1 =~ /"([^"]+)"/) {
-                    $env_list{$1} = 1;
+                    push @{$env_list{$1}}, "${filename}:$.";
                 } elsif ($env1 =~ /([A-Z0-9_])/) {
                     push(@env_macro, $env1);
                 }
@@ -1365,12 +1366,12 @@ sub check_env_vars {
                 # if it's a string just add to the list
                 # otherwise look for the constant value later
                 if ($env1 =~ /"([^"]+)"/) {
-                    $env_list{$1} = 1;
+                    push @{$env_list{$1}}, "${filename}:$.";
                 } else {
                     push(@env_macro, $env1);
                 }
                 if ($env2 =~ /"([^"]+)"/) {
-                    $env_list{$1} = 1;
+                    push @{$env_list{$1}}, "${filename}:$.";
                 } else {
                     push(@env_macro, $env2);
                 }
@@ -1383,14 +1384,15 @@ sub check_env_vars {
     find(sub { push @env_headers, $File::Find::name if /\.h$/; },
          $config{sourcedir});
 
-     foreach my $filename (@env_headers) {
+    foreach my $filename (@env_headers) {
         open my $fh, '<', $filename or die "Can't open $filename: $!";
         while (my $line = <$fh>) {
             foreach my $em (@env_macro) {
-                $env_list{$1} = 1 if ($line =~ /define\s+\Q$em\E\s+"(\S+)"/);
+                push @{$env_list{$1}}, "${filename}:$."
+                    if ($line =~ /define\s+\Q$em\E\s+"(\S+)"/);
             }
         }
-     }
+    }
 
     # need to save the value before starting to delete from the hash
     my $number_of_env = scalar keys %env_list;
@@ -1417,7 +1419,12 @@ sub check_env_vars {
     $number_of_env = scalar keys %env_list;
     if ($number_of_env != 0) {
         print "Undocumented environment variables:\n";
-        print join("\n", sort keys %env_list)."\n";
+        foreach my $env_name (sort keys %env_list) {
+            print $env_name;
+            print " (found in '", join("', '", @{$env_list{$env_name}}), "')"
+                if ref $env_list{$env_name} eq 'ARRAY';
+            print "\n";
+        }
         err("Total:".$number_of_env."\n");
     }
 }