Skip to content

Commit de6eec1

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 8ed13fb commit de6eec1

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

doc/src/sgml/install-windows.sgml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -512,15 +512,6 @@ $ENV{PERL5LIB}=$ENV{PERL5LIB} . ';c:\IPC-Run-0.94\lib';
512512
</para></listitem>
513513
</varlistentry>
514514

515-
<varlistentry>
516-
<term><varname>LZ4</varname></term>
517-
<listitem><para>
518-
Path to a <application>lz4</application> command. The default is
519-
<literal>lz4</literal>, that would be the command found in
520-
<varname>PATH</varname>.
521-
</para></listitem>
522-
</varlistentry>
523-
524515
<varlistentry>
525516
<term><varname>TAR</varname></term>
526517
<listitem><para>

src/tools/msvc/vcregress.pl

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
do './src/tools/msvc/config_default.pl';
2727
do './src/tools/msvc/config.pl' if (-f 'src/tools/msvc/config.pl');
2828

29+
my $devnull = File::Spec->devnull;
30+
2931
# These values are defaults that can be overridden by the calling environment
30-
# (see buildenv.pl processing below).
32+
# (see buildenv.pl processing below). We assume that the ones listed here
33+
# always exist by default. Other values may optionally be set for bincheck
34+
# or taptest, see set_command_env() below.
3135
# c.f. src/Makefile.global.in and configure.ac
32-
$ENV{GZIP_PROGRAM} ||= 'gzip';
33-
$ENV{LZ4} ||= 'lz4';
3436
$ENV{TAR} ||= 'tar';
3537

3638
# buildenv.pl is for specifying the build environment settings
@@ -114,6 +116,32 @@
114116

115117
########################################################################
116118

119+
# Helper function for set_command_env, to set one environment command.
120+
sub set_single_env
121+
{
122+
my $envname = shift;
123+
my $envdefault = shift;
124+
125+
# If a command is defined by the environment, just use it.
126+
return if (defined($ENV{$envname}));
127+
128+
# Nothing is defined, so attempt to assign a default. The command
129+
# may not be in the current environment, hence check if it can be
130+
# executed.
131+
my $rc = system("$envdefault --version >$devnull 2>&1");
132+
133+
# Set the environment to the default if it exists, else leave it.
134+
$ENV{$envname} = $envdefault if $rc == 0;
135+
return;
136+
}
137+
138+
# Set environment values for various command types. These can be used
139+
# in the TAP tests.
140+
sub set_command_env
141+
{
142+
set_single_env('GZIP_PROGRAM', 'gzip');
143+
}
144+
117145
sub installcheck_internal
118146
{
119147
my ($schedule, @EXTRA_REGRESS_OPTS) = @_;
@@ -242,6 +270,8 @@ sub bincheck
242270
{
243271
InstallTemp();
244272

273+
set_command_env();
274+
245275
my $mstat = 0;
246276

247277
# Find out all the existing TAP tests by looking for t/ directories
@@ -275,6 +305,9 @@ sub taptest
275305
push(@args, "$topdir/$dir");
276306

277307
InstallTemp();
308+
309+
set_command_env();
310+
278311
my $status = tap_check(@args);
279312
exit $status if $status;
280313
return;

0 commit comments

Comments
 (0)