Improve setup of environment values for commands in MSVC's vcregress.pl
authorMichael Paquier <[email protected]>
Wed, 11 May 2022 01:22:44 +0000 (10:22 +0900)
committerMichael Paquier <[email protected]>
Wed, 11 May 2022 01:22:44 +0000 (10:22 +0900)
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

doc/src/sgml/install-windows.sgml
src/tools/msvc/vcregress.pl

index 2ad81fc3886cf89ead92feab6b7b19fa49ede32b..473f7fe17508763c0083a42a93d63c5dff1a7f6e 100644 (file)
@@ -500,15 +500,6 @@ $ENV{PERL5LIB}=$ENV{PERL5LIB} . ';c:\IPC-Run-0.94\lib';
      </para></listitem>
     </varlistentry>
 
-    <varlistentry>
-     <term><varname>LZ4</varname></term>
-     <listitem><para>
-      Path to a <application>lz4</application> command. The default is
-      <literal>lz4</literal>, that would be the command found in
-      <varname>PATH</varname>.
-     </para></listitem>
-    </varlistentry>
-
     <varlistentry>
      <term><varname>TAR</varname></term>
      <listitem><para>
index 8edad20a144cd2b5f394defafc0c9909dd480a71..29251e681e17e10fe0c05b955f5c6026d1cc7a55 100644 (file)
@@ -26,11 +26,13 @@ my $tmp_installdir = "$topdir/tmp_install";
 do './src/tools/msvc/config_default.pl';
 do './src/tools/msvc/config.pl' if (-f 'src/tools/msvc/config.pl');
 
+my $devnull = File::Spec->devnull;
+
 # These values are defaults that can be overridden by the calling environment
-# (see buildenv.pl processing below).
+# (see buildenv.pl processing below).  We assume that the ones listed here
+# always exist by default.  Other values may optionally be set for bincheck
+# or taptest, see set_command_env() below.
 # c.f. src/Makefile.global.in and configure.ac
-$ENV{GZIP_PROGRAM} ||= 'gzip';
-$ENV{LZ4} ||= 'lz4';
 $ENV{TAR} ||= 'tar';
 
 # buildenv.pl is for specifying the build environment settings
@@ -114,6 +116,32 @@ exit 0;
 
 ########################################################################
 
+# Helper function for set_command_env, to set one environment command.
+sub set_single_env
+{
+   my $envname    = shift;
+   my $envdefault = shift;
+
+   # If a command is defined by the environment, just use it.
+   return if (defined($ENV{$envname}));
+
+   # Nothing is defined, so attempt to assign a default.  The command
+   # may not be in the current environment, hence check if it can be
+   # executed.
+   my $rc = system("$envdefault --version >$devnull 2>&1");
+
+   # Set the environment to the default if it exists, else leave it.
+   $ENV{$envname} = $envdefault if $rc == 0;
+   return;
+}
+
+# Set environment values for various command types.  These can be used
+# in the TAP tests.
+sub set_command_env
+{
+   set_single_env('GZIP_PROGRAM', 'gzip');
+}
+
 sub installcheck_internal
 {
    my ($schedule, @EXTRA_REGRESS_OPTS) = @_;
@@ -235,6 +263,8 @@ sub bincheck
 {
    InstallTemp();
 
+   set_command_env();
+
    my $mstat = 0;
 
    # Find out all the existing TAP tests by looking for t/ directories
@@ -267,6 +297,9 @@ sub taptest
    push(@args, "$topdir/$dir");
 
    InstallTemp();
+
+   set_command_env();
+
    my $status = tap_check(@args);
    exit $status if $status;
 }