From 4f20506fe04092a9174bfc6dea908c3dfdbaaf1e Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Mon, 18 Jul 2022 12:13:14 -0700 Subject: [PATCH] Add output path arg in generate-lwlocknames.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. Reviewed-by: Peter Eisentraut Discussion: https://postgr.es/m/5e216522-ba3c-f0e6-7f97-5276d0270029@enterprisedb.com --- src/backend/storage/lmgr/generate-lwlocknames.pl | 14 ++++++++++---- src/tools/msvc/Solution.pm | 5 ++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/backend/storage/lmgr/generate-lwlocknames.pl b/src/backend/storage/lmgr/generate-lwlocknames.pl index 4565ff8760e..5fadc4503bf 100644 --- a/src/backend/storage/lmgr/generate-lwlocknames.pl +++ b/src/backend/storage/lmgr/generate-lwlocknames.pl @@ -5,15 +5,21 @@ use strict; use warnings; +use Getopt::Long; + +my $output_path = '.'; my $lastlockidx = -1; my $continue = "\n"; +GetOptions( + 'outdir:s' => \$output_path); + open my $lwlocknames, '<', $ARGV[0] or die; # Include PID in suffix in case parallel make runs this multiple times. -my $htmp = "lwlocknames.h.tmp$$"; -my $ctmp = "lwlocknames.c.tmp$$"; +my $htmp = "$output_path/lwlocknames.h.tmp$$"; +my $ctmp = "$output_path/lwlocknames.c.tmp$$"; open my $h, '>', $htmp or die "Could not open $htmp: $!"; open my $c, '>', $ctmp or die "Could not open $ctmp: $!"; @@ -65,7 +71,7 @@ printf $h "#define NUM_INDIVIDUAL_LWLOCKS %s\n", $lastlockidx + 1; close $h; close $c; -rename($htmp, 'lwlocknames.h') || die "rename: $htmp: $!"; -rename($ctmp, 'lwlocknames.c') || die "rename: $ctmp: $!"; +rename($htmp, "$output_path/lwlocknames.h") || die "rename: $htmp to $output_path/lwlocknames.h: $!"; +rename($ctmp, "$output_path/lwlocknames.c") || die "rename: $ctmp: $!"; close $lwlocknames; diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm index 312f9c3058e..98121c0f5f8 100644 --- a/src/tools/msvc/Solution.pm +++ b/src/tools/msvc/Solution.pm @@ -625,9 +625,8 @@ sub GenerateFiles 'src/backend/storage/lmgr/lwlocknames.txt')) { print "Generating lwlocknames.c and lwlocknames.h...\n"; - chdir('src/backend/storage/lmgr'); - system('perl generate-lwlocknames.pl lwlocknames.txt'); - chdir('../../../..'); + my $lmgr = 'src/backend/storage/lmgr'; + system("perl $lmgr/generate-lwlocknames.pl --outdir $lmgr $lmgr/lwlocknames.txt"); } if (IsNewer( 'src/include/storage/lwlocknames.h',