aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2022-07-18 12:15:09 -0700
committerAndres Freund <andres@anarazel.de>2022-07-18 12:24:35 -0700
commit2bf626b714b5189d6041c228f74cdb769ea169fa (patch)
tree305a951a1a709dfdc4c9323529df55ebcae1469b
parent4f20506fe04092a9174bfc6dea908c3dfdbaaf1e (diff)
downloadpostgresql-2bf626b714b5189d6041c228f74cdb769ea169fa.tar.gz
postgresql-2bf626b714b5189d6041c228f74cdb769ea169fa.zip
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
-rw-r--r--src/backend/utils/Makefile2
-rw-r--r--src/backend/utils/generate-errcodes.pl30
-rw-r--r--src/tools/msvc/Solution.pm2
3 files changed, 27 insertions, 7 deletions
diff --git a/src/backend/utils/Makefile b/src/backend/utils/Makefile
index ebda1df72b5..2011c5148d3 100644
--- a/src/backend/utils/Makefile
+++ b/src/backend/utils/Makefile
@@ -52,7 +52,7 @@ fmgr-stamp: Gen_fmgrtab.pl $(catalogdir)/Catalog.pm $(top_srcdir)/src/include/ca
touch $@
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)
probes.h: Gen_dummy_probes.sed
diff --git a/src/backend/utils/generate-errcodes.pl b/src/backend/utils/generate-errcodes.pl
index 5727ff76cc3..5045027fb26 100644
--- a/src/backend/utils/generate-errcodes.pl
+++ b/src/backend/utils/generate-errcodes.pl
@@ -5,12 +5,31 @@
use strict;
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";
-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>)
{
@@ -25,7 +44,7 @@ while (<$errcodes>)
{
my $header = $1;
$header =~ s/^\s+//;
- print "\n/* $header */\n";
+ print $outfh "\n/* $header */\n";
next;
}
@@ -40,7 +59,8 @@ while (<$errcodes>)
# And quote them
$sqlstate =~ s/([^,])/'$1'/g;
- print "#define $errcode_macro MAKE_SQLSTATE($sqlstate)\n";
+ print $outfh "#define $errcode_macro MAKE_SQLSTATE($sqlstate)\n";
}
close $errcodes;
+close $outfh if ($outfile);
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index 98121c0f5f8..a66b04c242d 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -662,7 +662,7 @@ sub GenerateFiles
{
print "Generating errcodes.h...\n";
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',
'src/include/utils/errcodes.h');