Skip to content

Commit db0a272

Browse files
committed
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 <peter.eisentraut@enterprisedb.com> Discussion: https://postgr.es/m/5e216522-ba3c-f0e6-7f97-5276d0270029@enterprisedb.com
1 parent 7c3c2cb commit db0a272

File tree

4 files changed

+43
-21
lines changed

4 files changed

+43
-21
lines changed

src/interfaces/ecpg/preproc/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ preproc.h: preproc.c
6565
preproc.c: BISONFLAGS += -d
6666

6767
preproc.y: ../../../backend/parser/gram.y parse.pl ecpg.addons ecpg.header ecpg.tokens ecpg.trailer ecpg.type
68-
$(PERL) $(srcdir)/parse.pl $(srcdir) < $< > $@
69-
$(PERL) $(srcdir)/check_rules.pl $(srcdir) $<
68+
$(PERL) $(srcdir)/parse.pl --srcdir $(srcdir) --parser $< --output $@
69+
$(PERL) $(srcdir)/check_rules.pl --srcdir $(srcdir) --parser $<
7070

7171
# generate keyword headers
7272
c_kwlist_d.h: c_kwlist.h $(GEN_KEYWORDLIST_DEPS)

src/interfaces/ecpg/preproc/check_rules.pl

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,20 @@
1919
use strict;
2020
use warnings;
2121
no warnings 'uninitialized';
22+
use Getopt::Long;
2223

24+
my $srcdir = '.';
25+
my $parser = '../../../backend/parser/gram.y';
26+
my $stamp = '';
2327
my $verbose = 0;
24-
if ($ARGV[0] eq '-v')
25-
{
26-
$verbose = shift;
27-
}
28-
my $path = shift || '.';
29-
my $parser = shift || '../../../backend/parser/gram.y';
3028

31-
my $filename = $path . "/ecpg.addons";
29+
GetOptions(
30+
'srcdir=s' => \$srcdir,
31+
'parser=s' => \$parser,
32+
'stamp=s' => \$stamp,
33+
'verbose' => \$verbose,) or die "wrong arguments";
34+
35+
my $filename = "$srcdir/ecpg.addons";
3236
if ($verbose)
3337
{
3438
print "parser: $parser\n";
@@ -188,4 +192,10 @@
188192
print "$cc rules checked\n";
189193
}
190194

195+
if ($stamp)
196+
{
197+
open my $stampfh, '>', $stamp or die $!;
198+
close $stampfh;
199+
}
200+
191201
exit $ret;

src/interfaces/ecpg/preproc/parse.pl

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,20 @@
1515
use strict;
1616
use warnings;
1717
no warnings 'uninitialized';
18+
use Getopt::Long;
1819

19-
my $path = shift @ARGV;
20-
$path = "." unless $path;
20+
my $srcdir = '.';
21+
my $outfile = '';
22+
my $parser = '';
23+
24+
GetOptions(
25+
'srcdir=s' => \$srcdir,
26+
'output=s' => \$outfile,
27+
'parser=s' => \$parser,) or die "wrong arguments";
28+
29+
# open parser / output file early, to raise errors early
30+
open(our $parserfh, '<', $parser) or die "could not open parser file $parser";
31+
open(our $outfh, '>', $outfile) or die "could not open output file $outfile";
2132

2233
my $copymode = 0;
2334
my $brace_indent = 0;
@@ -128,15 +139,17 @@
128139
dump_buffer('types');
129140
dump_buffer('ecpgtype');
130141
dump_buffer('orig_tokens');
131-
print '%%', "\n";
132-
print 'prog: statements;', "\n";
142+
print $outfh '%%', "\n";
143+
print $outfh 'prog: statements;', "\n";
133144
dump_buffer('rules');
134145
include_file('trailer', 'ecpg.trailer');
135146
dump_buffer('trailer');
136147

148+
close($parserfh);
149+
137150
sub main
138151
{
139-
line: while (<>)
152+
line: while (<$parserfh>)
140153
{
141154
if (/ERRCODE_FEATURE_NOT_SUPPORTED/)
142155
{
@@ -442,7 +455,7 @@ sub main
442455
sub include_file
443456
{
444457
my ($buffer, $filename) = @_;
445-
my $full = "$path/$filename";
458+
my $full = "$srcdir/$filename";
446459
open(my $fh, '<', $full) or die;
447460
while (<$fh>)
448461
{
@@ -498,9 +511,9 @@ sub add_to_buffer
498511
sub dump_buffer
499512
{
500513
my ($buffer) = @_;
501-
print '/* ', $buffer, ' */', "\n";
514+
print $outfh '/* ', $buffer, ' */', "\n";
502515
my $ref = $buff{$buffer};
503-
print @$ref;
516+
print $outfh @$ref;
504517
return;
505518
}
506519

@@ -652,7 +665,7 @@ sub dump_line
652665

653666
sub preload_addons
654667
{
655-
my $filename = $path . "/ecpg.addons";
668+
my $filename = $srcdir . "/ecpg.addons";
656669
open(my $fh, '<', $filename) or die;
657670

658671
# there may be multiple lines starting ECPG: and then multiple lines of code.

src/tools/msvc/Solution.pm

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -746,9 +746,8 @@ sub GenerateFiles
746746
'src/backend/parser/gram.y'))
747747
{
748748
print "Generating preproc.y...\n";
749-
chdir('src/interfaces/ecpg/preproc');
750-
system('perl parse.pl < ../../../backend/parser/gram.y > preproc.y');
751-
chdir('../../../..');
749+
my $ecpg = 'src/interfaces/ecpg';
750+
system("perl $ecpg/preproc/parse.pl --srcdir $ecpg/preproc --parser src/backend/parser/gram.y --output $ecpg/preproc/preproc.y");
752751
}
753752

754753
unless (-f "src/port/pg_config_paths.h")

0 commit comments

Comments
 (0)