summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndres Freund2022-07-18 18:59:03 +0000
committerAndres Freund2022-07-18 19:24:23 +0000
commitdb0a272d123b8d7f4d4acbeb54f27682a566be83 (patch)
tree660f21e0afa01fd22abf920f5d68fb08354ed9ad
parent7c3c2cb9aeda4f288e89b25ede8cc2fe5997ac98 (diff)
ecpg: Output dir, source dir, stamp file argument for preproc/*.pl
This is in preparation for building postgres with meson / ninja. When building with meson, commands are run at the root of the build tree. Add an option to put build output into the appropriate place. This can be utilized by src/tools/msvc/ for a minor simplification, which also provides some coverage for the new option. Add option to generate a timestamp for check_rules.pl, so that proper dependencies on it having been run can be generated. Reviewed-by: Peter Eisentraut <[email protected]> Discussion: https://postgr.es/m/[email protected]
-rw-r--r--src/interfaces/ecpg/preproc/Makefile4
-rw-r--r--src/interfaces/ecpg/preproc/check_rules.pl24
-rw-r--r--src/interfaces/ecpg/preproc/parse.pl31
-rw-r--r--src/tools/msvc/Solution.pm5
4 files changed, 43 insertions, 21 deletions
diff --git a/src/interfaces/ecpg/preproc/Makefile b/src/interfaces/ecpg/preproc/Makefile
index ef6d645dee1..ec2359810e5 100644
--- a/src/interfaces/ecpg/preproc/Makefile
+++ b/src/interfaces/ecpg/preproc/Makefile
@@ -65,8 +65,8 @@ preproc.h: preproc.c
preproc.c: BISONFLAGS += -d
preproc.y: ../../../backend/parser/gram.y parse.pl ecpg.addons ecpg.header ecpg.tokens ecpg.trailer ecpg.type
- $(PERL) $(srcdir)/parse.pl $(srcdir) < $< > $@
- $(PERL) $(srcdir)/check_rules.pl $(srcdir) $<
+ $(PERL) $(srcdir)/parse.pl --srcdir $(srcdir) --parser $< --output $@
+ $(PERL) $(srcdir)/check_rules.pl --srcdir $(srcdir) --parser $<
# generate keyword headers
c_kwlist_d.h: c_kwlist.h $(GEN_KEYWORDLIST_DEPS)
diff --git a/src/interfaces/ecpg/preproc/check_rules.pl b/src/interfaces/ecpg/preproc/check_rules.pl
index 0a3fafc39fa..58a755f454a 100644
--- a/src/interfaces/ecpg/preproc/check_rules.pl
+++ b/src/interfaces/ecpg/preproc/check_rules.pl
@@ -19,16 +19,20 @@
use strict;
use warnings;
no warnings 'uninitialized';
+use Getopt::Long;
+my $srcdir = '.';
+my $parser = '../../../backend/parser/gram.y';
+my $stamp = '';
my $verbose = 0;
-if ($ARGV[0] eq '-v')
-{
- $verbose = shift;
-}
-my $path = shift || '.';
-my $parser = shift || '../../../backend/parser/gram.y';
-my $filename = $path . "/ecpg.addons";
+GetOptions(
+ 'srcdir=s' => \$srcdir,
+ 'parser=s' => \$parser,
+ 'stamp=s' => \$stamp,
+ 'verbose' => \$verbose,) or die "wrong arguments";
+
+my $filename = "$srcdir/ecpg.addons";
if ($verbose)
{
print "parser: $parser\n";
@@ -188,4 +192,10 @@ if ($verbose)
print "$cc rules checked\n";
}
+if ($stamp)
+{
+ open my $stampfh, '>', $stamp or die $!;
+ close $stampfh;
+}
+
exit $ret;
diff --git a/src/interfaces/ecpg/preproc/parse.pl b/src/interfaces/ecpg/preproc/parse.pl
index 5ec511fd013..a15f563ad45 100644
--- a/src/interfaces/ecpg/preproc/parse.pl
+++ b/src/interfaces/ecpg/preproc/parse.pl
@@ -15,9 +15,20 @@
use strict;
use warnings;
no warnings 'uninitialized';
+use Getopt::Long;
-my $path = shift @ARGV;
-$path = "." unless $path;
+my $srcdir = '.';
+my $outfile = '';
+my $parser = '';
+
+GetOptions(
+ 'srcdir=s' => \$srcdir,
+ 'output=s' => \$outfile,
+ 'parser=s' => \$parser,) or die "wrong arguments";
+
+# open parser / output file early, to raise errors early
+open(our $parserfh, '<', $parser) or die "could not open parser file $parser";
+open(our $outfh, '>', $outfile) or die "could not open output file $outfile";
my $copymode = 0;
my $brace_indent = 0;
@@ -128,15 +139,17 @@ dump_buffer('tokens');
dump_buffer('types');
dump_buffer('ecpgtype');
dump_buffer('orig_tokens');
-print '%%', "\n";
-print 'prog: statements;', "\n";
+print $outfh '%%', "\n";
+print $outfh 'prog: statements;', "\n";
dump_buffer('rules');
include_file('trailer', 'ecpg.trailer');
dump_buffer('trailer');
+close($parserfh);
+
sub main
{
- line: while (<>)
+ line: while (<$parserfh>)
{
if (/ERRCODE_FEATURE_NOT_SUPPORTED/)
{
@@ -442,7 +455,7 @@ sub main
sub include_file
{
my ($buffer, $filename) = @_;
- my $full = "$path/$filename";
+ my $full = "$srcdir/$filename";
open(my $fh, '<', $full) or die;
while (<$fh>)
{
@@ -498,9 +511,9 @@ sub add_to_buffer
sub dump_buffer
{
my ($buffer) = @_;
- print '/* ', $buffer, ' */', "\n";
+ print $outfh '/* ', $buffer, ' */', "\n";
my $ref = $buff{$buffer};
- print @$ref;
+ print $outfh @$ref;
return;
}
@@ -652,7 +665,7 @@ sub dump_line
sub preload_addons
{
- my $filename = $path . "/ecpg.addons";
+ my $filename = $srcdir . "/ecpg.addons";
open(my $fh, '<', $filename) or die;
# there may be multiple lines starting ECPG: and then multiple lines of code.
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index 840f251343c..312f9c3058e 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -746,9 +746,8 @@ sub GenerateFiles
'src/backend/parser/gram.y'))
{
print "Generating preproc.y...\n";
- chdir('src/interfaces/ecpg/preproc');
- system('perl parse.pl < ../../../backend/parser/gram.y > preproc.y');
- chdir('../../../..');
+ my $ecpg = 'src/interfaces/ecpg';
+ system("perl $ecpg/preproc/parse.pl --srcdir $ecpg/preproc --parser src/backend/parser/gram.y --output $ecpg/preproc/preproc.y");
}
unless (-f "src/port/pg_config_paths.h")