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

Commit 7c3c2cb

Browse files
committed
psql: Output dir and dependency generation for sql_help
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. To deal with dependencies to the variable set of input files to this script, add an option to generate a dependency file (which meson / ninja can consume). Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com> Discussion: https://postgr.es/m/5e216522-ba3c-f0e6-7f97-5276d0270029@enterprisedb.com
1 parent a91242b commit 7c3c2cb

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

src/bin/psql/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ sql_help.c: sql_help.h
5656
touch $@
5757

5858
sql_help.h: create_help.pl $(wildcard $(REFDOCDIR)/*.sgml)
59-
$(PERL) $< $(REFDOCDIR) $*
59+
$(PERL) $< --docdir $(REFDOCDIR) --basename $*
6060

6161
psqlscanslash.c: FLEXFLAGS = -Cfe -p -p
6262
psqlscanslash.c: FLEX_NO_BACKUP=yes

src/bin/psql/create_help.pl

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,43 @@
2121

2222
use strict;
2323
use warnings;
24+
use Getopt::Long;
2425

25-
my $docdir = $ARGV[0] or die "$0: missing required argument: docdir\n";
26-
my $hfile = $ARGV[1] . '.h'
27-
or die "$0: missing required argument: output file\n";
28-
my $cfile = $ARGV[1] . '.c';
26+
my $docdir = '';
27+
my $outdir = '.';
28+
my $depfile = '';
29+
my $hfilebasename = '';
2930

30-
my $hfilebasename;
31-
if ($hfile =~ m!.*/([^/]+)$!)
32-
{
33-
$hfilebasename = $1;
34-
}
35-
else
36-
{
37-
$hfilebasename = $hfile;
38-
}
31+
GetOptions(
32+
'docdir=s' => \$docdir,
33+
'outdir=s' => \$outdir,
34+
'basename=s' => \$hfilebasename,
35+
'depfile=s' => \$depfile,) or die "$0: wrong arguments";
36+
37+
$docdir or die "$0: missing required argument: docdir\n";
38+
$hfilebasename or die "$0: missing required argument: basename\n";
39+
40+
my $hfile = $hfilebasename . '.h';
41+
my $cfile = $hfilebasename . '.c';
3942

4043
my $define = $hfilebasename;
4144
$define =~ tr/a-z/A-Z/;
4245
$define =~ s/\W/_/g;
4346

4447
opendir(DIR, $docdir)
4548
or die "$0: could not open documentation source dir '$docdir': $!\n";
46-
open(my $hfile_handle, '>', $hfile)
49+
open(my $hfile_handle, '>', "$outdir/$hfile")
4750
or die "$0: could not open output file '$hfile': $!\n";
48-
open(my $cfile_handle, '>', $cfile)
51+
open(my $cfile_handle, '>', "$outdir/$cfile")
4952
or die "$0: could not open output file '$cfile': $!\n";
5053

54+
my $depfile_handle;
55+
if ($depfile)
56+
{
57+
open($depfile_handle, '>', $depfile)
58+
or die "$0: could not open output file '$depfile': $!\n";
59+
}
60+
5161
print $hfile_handle "/*
5262
* *** Do not change this file by hand. It is automatically
5363
* *** generated from the DocBook documentation.
@@ -98,6 +108,9 @@
98108
my ($cmdid, @cmdnames, $cmddesc, $cmdsynopsis);
99109
$file =~ /\.sgml$/ or next;
100110

111+
print $depfile_handle "$outdir/$cfile $outdir/$hfile: $docdir/$file\n"
112+
if ($depfile);
113+
101114
open(my $fh, '<', "$docdir/$file") or next;
102115
my $filecontent = join('', <$fh>);
103116
close $fh;
@@ -216,4 +229,5 @@
216229

217230
close $cfile_handle;
218231
close $hfile_handle;
232+
close $depfile_handle if ($depfile);
219233
closedir DIR;

src/tools/msvc/Solution.pm

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -692,9 +692,8 @@ sub GenerateFiles
692692
if (IsNewer('src/bin/psql/sql_help.h', 'src/bin/psql/create_help.pl'))
693693
{
694694
print "Generating sql_help.h...\n";
695-
chdir('src/bin/psql');
696-
system("perl create_help.pl ../../../doc/src/sgml/ref sql_help");
697-
chdir('../../..');
695+
my $psql = 'src/bin/psql';
696+
system("perl $psql/create_help.pl --docdir doc/src/sgml/ref --outdir $psql --basename sql_help");
698697
}
699698

700699
if (IsNewer('src/common/kwlist_d.h', 'src/include/parser/kwlist.h'))

0 commit comments

Comments
 (0)