Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2bf626b

Browse files
committed
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
1 parent 4f20506 commit 2bf626b

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

src/backend/utils/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fmgr-stamp: Gen_fmgrtab.pl $(catalogdir)/Catalog.pm $(top_srcdir)/src/include/ca
5252
touch $@
5353

5454
errcodes.h: $(top_srcdir)/src/backend/utils/errcodes.txt generate-errcodes.pl
55-
$(PERL) $(srcdir)/generate-errcodes.pl $< > $@
55+
$(PERL) $(srcdir)/generate-errcodes.pl --outfile $@ $<
5656

5757
ifneq ($(enable_dtrace), yes)
5858
probes.h: Gen_dummy_probes.sed

src/backend/utils/generate-errcodes.pl

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,31 @@
55

66
use strict;
77
use warnings;
8+
use Getopt::Long;
89

9-
print
10+
my $outfile = '';
11+
12+
GetOptions(
13+
'outfile=s' => \$outfile) or die "$0: wrong arguments";
14+
15+
open my $errcodes, '<', $ARGV[0]
16+
or die "$0: could not open input file '$ARGV[0]': $!\n";
17+
18+
my $outfh;
19+
if ($outfile)
20+
{
21+
open $outfh, '>', $outfile
22+
or die "$0: could not open output file '$outfile': $!\n";
23+
}
24+
else
25+
{
26+
$outfh = *STDOUT;
27+
}
28+
29+
print $outfh
1030
"/* autogenerated from src/backend/utils/errcodes.txt, do not edit */\n";
11-
print "/* there is deliberately not an #ifndef ERRCODES_H here */\n";
31+
print $outfh "/* there is deliberately not an #ifndef ERRCODES_H here */\n";
1232

13-
open my $errcodes, '<', $ARGV[0] or die;
1433

1534
while (<$errcodes>)
1635
{
@@ -25,7 +44,7 @@
2544
{
2645
my $header = $1;
2746
$header =~ s/^\s+//;
28-
print "\n/* $header */\n";
47+
print $outfh "\n/* $header */\n";
2948
next;
3049
}
3150

@@ -40,7 +59,8 @@
4059
# And quote them
4160
$sqlstate =~ s/([^,])/'$1'/g;
4261

43-
print "#define $errcode_macro MAKE_SQLSTATE($sqlstate)\n";
62+
print $outfh "#define $errcode_macro MAKE_SQLSTATE($sqlstate)\n";
4463
}
4564

4665
close $errcodes;
66+
close $outfh if ($outfile);

src/tools/msvc/Solution.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ sub GenerateFiles
662662
{
663663
print "Generating errcodes.h...\n";
664664
system(
665-
'perl src/backend/utils/generate-errcodes.pl src/backend/utils/errcodes.txt > src/backend/utils/errcodes.h'
665+
'perl src/backend/utils/generate-errcodes.pl --outfile src/backend/utils/errcodes.h src/backend/utils/errcodes.txt'
666666
);
667667
copyFile('src/backend/utils/errcodes.h',
668668
'src/include/utils/errcodes.h');

0 commit comments

Comments
 (0)