postgres.git / summary / log / commit / refs

commit    7c3c2cb9aeda4f288e89b25ede8cc2fe5997ac98
Author:   Andres Freund <andres@anarazel.de>
Date:     Mon Jul 18 18:57:31 2022 +0000
First released in: 16.0

    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


src/bin/psql/Makefile | 2 +- src/bin/psql/create_help.pl | 44 +++++++++++++++++++++++++++++--------------- src/tools/msvc/Solution.pm | 5 ++--- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/bin/psql/Makefile b/src/bin/psql/Makefile index 58ec4a89b49..d38775af467 100644 --- a/src/bin/psql/Makefile +++ b/src/bin/psql/Makefile @@ -56,7 +56,7 @@ sql_help.c: sql_help.h touch $@ sql_help.h: create_help.pl $(wildcard $(REFDOCDIR)/*.sgml) - $(PERL) $< $(REFDOCDIR) $* + $(PERL) $< --docdir $(REFDOCDIR) --basename $* psqlscanslash.c: FLEXFLAGS = -Cfe -p -p psqlscanslash.c: FLEX_NO_BACKUP=yes diff --git a/src/bin/psql/create_help.pl b/src/bin/psql/create_help.pl index 1a9836cbcc0..ba9a49cff04 100644 --- a/src/bin/psql/create_help.pl +++ b/src/bin/psql/create_help.pl @@ -21,21 +21,24 @@ use strict; use warnings; +use Getopt::Long; -my $docdir = $ARGV[0] or die "$0: missing required argument: docdir\n"; -my $hfile = $ARGV[1] . '.h' - or die "$0: missing required argument: output file\n"; -my $cfile = $ARGV[1] . '.c'; +my $docdir = ''; +my $outdir = '.'; +my $depfile = ''; +my $hfilebasename = ''; -my $hfilebasename; -if ($hfile =~ m!.*/([^/]+)$!) -{ - $hfilebasename = $1; -} -else -{ - $hfilebasename = $hfile; -} +GetOptions( + 'docdir=s' => \$docdir, + 'outdir=s' => \$outdir, + 'basename=s' => \$hfilebasename, + 'depfile=s' => \$depfile,) or die "$0: wrong arguments"; + +$docdir or die "$0: missing required argument: docdir\n"; +$hfilebasename or die "$0: missing required argument: basename\n"; + +my $hfile = $hfilebasename . '.h'; +my $cfile = $hfilebasename . '.c'; my $define = $hfilebasename; $define =~ tr/a-z/A-Z/; @@ -43,11 +46,18 @@ $define =~ s/\W/_/g; opendir(DIR, $docdir) or die "$0: could not open documentation source dir '$docdir': $!\n"; -open(my $hfile_handle, '>', $hfile) +open(my $hfile_handle, '>', "$outdir/$hfile") or die "$0: could not open output file '$hfile': $!\n"; -open(my $cfile_handle, '>', $cfile) +open(my $cfile_handle, '>', "$outdir/$cfile") or die "$0: could not open output file '$cfile': $!\n"; +my $depfile_handle; +if ($depfile) +{ + open($depfile_handle, '>', $depfile) + or die "$0: could not open output file '$depfile': $!\n"; +} + print $hfile_handle "/* * *** Do not change this file by hand. It is automatically * *** generated from the DocBook documentation. @@ -98,6 +108,9 @@ foreach my $file (sort readdir DIR) my ($cmdid, @cmdnames, $cmddesc, $cmdsynopsis); $file =~ /\.sgml$/ or next; + print $depfile_handle "$outdir/$cfile $outdir/$hfile: $docdir/$file\n" + if ($depfile); + open(my $fh, '<', "$docdir/$file") or next; my $filecontent = join('', <$fh>); close $fh; @@ -216,4 +229,5 @@ print $hfile_handle " close $cfile_handle; close $hfile_handle; +close $depfile_handle if ($depfile); closedir DIR; diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm index f2427008df6..840f251343c 100644 --- a/src/tools/msvc/Solution.pm +++ b/src/tools/msvc/Solution.pm @@ -692,9 +692,8 @@ sub GenerateFiles if (IsNewer('src/bin/psql/sql_help.h', 'src/bin/psql/create_help.pl')) { print "Generating sql_help.h...\n"; - chdir('src/bin/psql'); - system("perl create_help.pl ../../../doc/src/sgml/ref sql_help"); - chdir('../../..'); + my $psql = 'src/bin/psql'; + system("perl $psql/create_help.pl --docdir doc/src/sgml/ref --outdir $psql --basename sql_help"); } if (IsNewer('src/common/kwlist_d.h', 'src/include/parser/kwlist.h')) [parent: a91242b1bcb3]