Skip to content

Commit 0826ac8

Browse files
committed
Improve setup of environment values for commands in MSVC's vcregress.pl
The current setup assumes that commands for lz4, zstd and gzip always exist by default if not enforced by a user's environment. However, vcpkg, as one example, installs libraries but no binaries, so this default setup to assume that a command should always be present would cause failures. This commit improves the detection of such external commands as follows: * If a ENV value is available, trust the environment/user and use it. * If a ENV value is not available, check its execution by looking in the current PATH, by launching a simple "$command --version" (that should be portable enough). ** On execution failure, ignore ENV{command}. ** On execution success, set ENV{command} = "$command". Note that this new rule applies to gzip, lz4 and zstd but not tar that we assume will always exist. Those commands are set up in the environment only when using bincheck and taptest. The CI includes all those commands and I have checked that their setup is correct there. I have also tested this change in a MSVC environment where we have none of those commands. While on it, remove the references to lz4 from the documentation and vcregress.pl in ~v13. --with-lz4 has been added in v14~ so there is no point to have this information in these older branches. Reported-by: Andrew Dunstan Reviewed-by: Andrew Dunstan Discussion: https://postgr.es/m/14402151-376b-a57a-6d0c-10ad12608e12@dunslane.net Backpatch-through: 10
1 parent c90c165 commit 0826ac8

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

src/tools/msvc/vcregress.pl

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use File::Copy;
1515
use File::Find ();
1616
use File::Path qw(rmtree);
17+
use File::Spec qw(devnull);
1718

1819
use FindBin;
1920
use lib $FindBin::RealBin;
@@ -30,13 +31,14 @@
3031
do './src/tools/msvc/config_default.pl';
3132
do './src/tools/msvc/config.pl' if (-f 'src/tools/msvc/config.pl');
3233

34+
my $devnull = File::Spec->devnull;
35+
3336
# These values are defaults that can be overridden by the calling environment
34-
# (see buildenv.pl processing below).
37+
# (see buildenv.pl processing below). We assume that the ones listed here
38+
# always exist by default. Other values may optionally be set for bincheck
39+
# or taptest, see set_command_env() below.
3540
# c.f. src/Makefile.global.in and configure.ac
36-
$ENV{GZIP_PROGRAM} ||= 'gzip';
37-
$ENV{LZ4} ||= 'lz4';
3841
$ENV{TAR} ||= 'tar';
39-
$ENV{ZSTD} ||= 'zstd';
4042

4143
# buildenv.pl is for specifying the build environment settings
4244
# it should contain lines like:
@@ -119,6 +121,34 @@
119121

120122
########################################################################
121123

124+
# Helper function for set_command_env, to set one environment command.
125+
sub set_single_env
126+
{
127+
my $envname = shift;
128+
my $envdefault = shift;
129+
130+
# If a command is defined by the environment, just use it.
131+
return if (defined($ENV{$envname}));
132+
133+
# Nothing is defined, so attempt to assign a default. The command
134+
# may not be in the current environment, hence check if it can be
135+
# executed.
136+
my $rc = system("$envdefault --version >$devnull 2>&1");
137+
138+
# Set the environment to the default if it exists, else leave it.
139+
$ENV{$envname} = $envdefault if $rc == 0;
140+
return;
141+
}
142+
143+
# Set environment values for various command types. These can be used
144+
# in the TAP tests.
145+
sub set_command_env
146+
{
147+
set_single_env('GZIP_PROGRAM', 'gzip');
148+
set_single_env('LZ4', 'lz4');
149+
set_single_env('ZSTD', 'zstd');
150+
}
151+
122152
sub installcheck_internal
123153
{
124154
my ($schedule, @EXTRA_REGRESS_OPTS) = @_;
@@ -276,6 +306,8 @@ sub bincheck
276306
{
277307
InstallTemp();
278308

309+
set_command_env();
310+
279311
my $mstat = 0;
280312

281313
# Find out all the existing TAP tests by looking for t/ directories
@@ -310,6 +342,9 @@ sub taptest
310342
push(@args, "$topdir/$dir");
311343

312344
InstallTemp();
345+
346+
set_command_env();
347+
313348
my $status = tap_check(@args);
314349
exit $status if $status;
315350
return;

0 commit comments

Comments
 (0)