Add output file argument to generate-errcodes.pl
authorAndres Freund <[email protected]>
Mon, 18 Jul 2022 19:15:09 +0000 (12:15 -0700)
committerAndres Freund <[email protected]>
Mon, 18 Jul 2022 19:24:35 +0000 (12:24 -0700)
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 <[email protected]>
Discussion: https://postgr.es/m/5e216522-ba3c-f0e6-7f97-5276d0270029@enterprisedb.com

src/backend/utils/Makefile
src/backend/utils/generate-errcodes.pl
src/tools/msvc/Solution.pm

index ebda1df72b53d88b881ed102a901b019cf7393d7..2011c5148d37d17f1c97c443b3a4323861a846b1 100644 (file)
@@ -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
index 5727ff76cc3040e0eb10495735b99d6af8af2dd5..5045027fb26e99adfee7fe5898230dbb1ee67aff 100644 (file)
@@ -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);
index 98121c0f5f8bfdcfde41cd89c2eb4327c88dd22e..a66b04c242df6f6eff208d52146cf11d7b25361e 100644 (file)
@@ -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');