1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-22 23:02:54 +03:00

Add output file argument to generate-errcodes.pl

This is in preparation for building postgres with meson / ninja.

meson's 'capture' (redirecting stdout to a file) is a bit slower than programs
redirecting output themselves (mostly due to a python wrapper necessary for
windows). That doesn't matter for most things, but errcodes.h is a dependency
of nearly everything, making it a bit faster seem worthwhile.

Medium term it might also be worth avoiding writing errcodes.h if its contents
didn't actually change, to avoid unnecessary recompilations.

Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Discussion: https://postgr.es/m/5e216522-ba3c-f0e6-7f97-5276d0270029@enterprisedb.com
This commit is contained in:
Andres Freund 2022-07-18 12:15:09 -07:00
parent 4f20506fe0
commit 2bf626b714
3 changed files with 27 additions and 7 deletions

View File

@ -52,7 +52,7 @@ fmgr-stamp: Gen_fmgrtab.pl $(catalogdir)/Catalog.pm $(top_srcdir)/src/include/ca
touch $@ touch $@
errcodes.h: $(top_srcdir)/src/backend/utils/errcodes.txt generate-errcodes.pl errcodes.h: $(top_srcdir)/src/backend/utils/errcodes.txt generate-errcodes.pl
$(PERL) $(srcdir)/generate-errcodes.pl $< > $@ $(PERL) $(srcdir)/generate-errcodes.pl --outfile $@ $<
ifneq ($(enable_dtrace), yes) ifneq ($(enable_dtrace), yes)
probes.h: Gen_dummy_probes.sed probes.h: Gen_dummy_probes.sed

View File

@ -5,12 +5,31 @@
use strict; use strict;
use warnings; use warnings;
use Getopt::Long;
print my $outfile = '';
GetOptions(
'outfile=s' => \$outfile) or die "$0: wrong arguments";
open my $errcodes, '<', $ARGV[0]
or die "$0: could not open input file '$ARGV[0]': $!\n";
my $outfh;
if ($outfile)
{
open $outfh, '>', $outfile
or die "$0: could not open output file '$outfile': $!\n";
}
else
{
$outfh = *STDOUT;
}
print $outfh
"/* autogenerated from src/backend/utils/errcodes.txt, do not edit */\n"; "/* autogenerated from src/backend/utils/errcodes.txt, do not edit */\n";
print "/* there is deliberately not an #ifndef ERRCODES_H here */\n"; print $outfh "/* there is deliberately not an #ifndef ERRCODES_H here */\n";
open my $errcodes, '<', $ARGV[0] or die;
while (<$errcodes>) while (<$errcodes>)
{ {
@ -25,7 +44,7 @@ while (<$errcodes>)
{ {
my $header = $1; my $header = $1;
$header =~ s/^\s+//; $header =~ s/^\s+//;
print "\n/* $header */\n"; print $outfh "\n/* $header */\n";
next; next;
} }
@ -40,7 +59,8 @@ while (<$errcodes>)
# And quote them # And quote them
$sqlstate =~ s/([^,])/'$1'/g; $sqlstate =~ s/([^,])/'$1'/g;
print "#define $errcode_macro MAKE_SQLSTATE($sqlstate)\n"; print $outfh "#define $errcode_macro MAKE_SQLSTATE($sqlstate)\n";
} }
close $errcodes; close $errcodes;
close $outfh if ($outfile);

View File

@ -662,7 +662,7 @@ sub GenerateFiles
{ {
print "Generating errcodes.h...\n"; print "Generating errcodes.h...\n";
system( system(
'perl src/backend/utils/generate-errcodes.pl src/backend/utils/errcodes.txt > src/backend/utils/errcodes.h' 'perl src/backend/utils/generate-errcodes.pl --outfile src/backend/utils/errcodes.h src/backend/utils/errcodes.txt'
); );
copyFile('src/backend/utils/errcodes.h', copyFile('src/backend/utils/errcodes.h',
'src/include/utils/errcodes.h'); 'src/include/utils/errcodes.h');