On 13.06.24 10:25, Peter Eisentraut wrote:
Add missing source files to nls.mk
Files in common/ and fe_utils/ that contain translatable strings need
to be listed in the nls.mk files of the programs that use them. (Not
great, but that's the way it works for now.) This usually requires
some manual analysis which is done about once during each major
release beta period. This time, I wrote a hackish script that figures
some of this out more automatically, so this update is a bit larger as
it also includes some files that were missed in the past.
For posterity, I have attached the script that used here. I hope to
improve on this process in the future.
#!/usr/bin/perl
use strict;
use warnings;
use autodie;
use File::Spec;
# Usage: $0 SUBDIR FILENAME...
my %args = ();
my %deps = ();
my $subdir = shift @ARGV;
sub process_deps
{
my $newstuff = 0;
foreach my $filename (keys %deps)
{
my $dir;
foreach my $d ($subdir, 'src', 'src/include')
{
if (-f "$d/$filename")
{
$dir = $d;
last;
}
}
next unless $dir;
open my $fh, '<', "$dir/$filename";
while (my $line = <$fh>)
{
if ($line =~ m!^#include "([^"]+)"!)
{
my $inc = $1;
if ($inc !~ m!/! || $inc =~ m!^common/! || $inc =~ m!^fe_utils/!)
{
if (!$deps{$inc})
{
$deps{$inc} = 1;
$newstuff = 1;
}
$inc =~ s!\.h!.c!;
if (!$deps{$inc} && (-f "src/$inc" || -f "$subdir/$inc"))
{
$deps{$inc} = 1;
$newstuff = 1;
}
}
}
}
close $fh;
}
return $newstuff;
}
foreach my $arg (@ARGV)
{
$deps{$arg} = 1;
}
while (process_deps()) {}
my @FRONTEND_COMMON_GETTEXT_FILES = qw(common/logging.c);
foreach my $f (@FRONTEND_COMMON_GETTEXT_FILES)
{
delete $deps{$f};
}
foreach my $k (keys %deps)
{
delete $deps{$k};
next unless $k =~ m!\.c!;
if ($k =~ m!common/! || $k =~ m!fe_utils!)
{
$deps{"src/$k"} = 1;
}
else
{
$deps{"$subdir/$k"} = 1;
}
}
my @triggers = qw(_
pg_log_error pg_log_error_detail pg_log_error_hint
pg_log_warning pg_log_warning_detail pg_log_warning_hint
pg_log_info pg_log_info_detail pg_log_info_hint
pg_fatal pg_log_generic pg_log_generic_v
);
foreach my $fn (keys %deps)
{
local $/;
my $found = 0;
open my $fh, '<', $fn;
my $contents = <$fh>;
close $fh;
foreach my $t (@triggers)
{
$found = 1 if $contents =~ /\b$t\b/;
}
delete $deps{$fn} if !$found;
}
print join("\n", sort map { File::Spec->abs2rel($_, $subdir) } keys %deps), "\n";