Add ./configure check for "lz4" command
authorMichael Paquier <[email protected]>
Mon, 14 Feb 2022 01:40:34 +0000 (10:40 +0900)
committerMichael Paquier <[email protected]>
Mon, 14 Feb 2022 01:40:34 +0000 (10:40 +0900)
Some environments may compile with --with-lz4 while the command "lz4"
goes missing, causing two failures in the TAP tests of pg_verifybackup
(008_untar.pl and 010_client_untar.pl) as the code assumed that the
command always existed with a hardcoded value in src/Makefile.global.
Rather than this method, this adds a ./configure check based on
PGAC_PATH_PROGS() to find automatically the command and get an absolute
path to it.

Both tests need to be adjusted for the case where the command does not
exist, actually, as Makefile.global would set now LZ4 to an empty value
in this case.  The TAP tests of pg_receivewal already do that.

Per report from buildfarm member copperhead, as an effect of dab2984.
The origin of the failure is actually babbbb5 that did not centralize
the check for the existence of a "lz4" command at ./configure to shave a
few cycles.  Note that one just needs to tweak an environment to move
"lz4" out of the way to reproduce the problem, which is what I did to
test this change.

Per discussion with Robert Haas, Tom Lane, Andres Freund and myself.

Discussion: https://postgr.es/m/[email protected]

configure
configure.ac
src/Makefile.global.in
src/bin/pg_verifybackup/t/008_untar.pl
src/bin/pg_verifybackup/t/010_client_untar.pl

index 0d52af552939488d0c6759f94c5d604b659c9f82..93055556585a0328aea01fd09b67e2c4b8fb903a 100755 (executable)
--- a/configure
+++ b/configure
@@ -650,6 +650,7 @@ CFLAGS_ARMV8_CRC32C
 CFLAGS_SSE42
 have_win32_dbghelp
 LIBOBJS
+LZ4
 UUID_LIBS
 LDAP_LIBS_BE
 LDAP_LIBS_FE
 
 fi
 
+if test -z "$LZ4"; then
+  for ac_prog in lz4
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_LZ4+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $LZ4 in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_LZ4="$LZ4" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_LZ4="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+LZ4=$ac_cv_path_LZ4
+if test -n "$LZ4"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LZ4" >&5
+$as_echo "$LZ4" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  test -n "$LZ4" && break
+done
+
+else
+  # Report the value of LZ4 in configure's output in all cases.
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for LZ4" >&5
+$as_echo_n "checking for LZ4... " >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LZ4" >&5
+$as_echo "$LZ4" >&6; }
+fi
+
 if test "$with_lz4" = yes; then
   for ac_header in lz4.h
 do :
index 2afc822b12815dfc2366d02484bdc8d5decfa772..16167329fca9c779c8dabf2b770f896a18c4654d 100644 (file)
@@ -1485,6 +1485,7 @@ failure.  It is possible the compiler isn't looking in the proper directory.
 Use --without-zlib to disable zlib support.])])
 fi
 
+PGAC_PATH_PROGS(LZ4, lz4)
 if test "$with_lz4" = yes; then
   AC_CHECK_HEADERS(lz4.h, [], [AC_MSG_ERROR([lz4.h header file is required for LZ4])])
 fi
index 05c54b27defc731ace4b9b6631fdd21c5dea1f52..9dcd54fcbd5a95de1921befd69e7183d0b1a29a5 100644 (file)
@@ -350,7 +350,7 @@ XGETTEXT = @XGETTEXT@
 
 GZIP   = gzip
 BZIP2  = bzip2
-LZ4    = lz4
+LZ4    = @LZ4@
 
 DOWNLOAD = wget -O $@ --no-use-server-timestamps
 #DOWNLOAD = curl -o $@
index 03f98966bddd3280b1991aa4324e51d87fd780b6..6927ca4c74cc9530165142be5422080b34383fd5 100644 (file)
@@ -54,8 +54,9 @@ for my $tc (@test_configuration)
        skip "$method compression not supported by this build", 3
            if ! $tc->{'enabled'};
        skip "no decompressor available for $method", 3
-           if exists $tc->{'decompress_program'} &&
-           !defined $tc->{'decompress_program'};
+         if exists $tc->{'decompress_program'}
+         && (!defined $tc->{'decompress_program'}
+           || $tc->{'decompress_program'} eq '');
 
        # Take a server-side backup.
        my @backup = (
index 159a4f86df01b7a72c5dbd0623defc4a2a6affff..36165293908fcba41f4b1d13c8824404d94ee204 100644 (file)
@@ -53,8 +53,9 @@ for my $tc (@test_configuration)
        skip "$method compression not supported by this build", 3
            if ! $tc->{'enabled'};
        skip "no decompressor available for $method", 3
-           if exists $tc->{'decompress_program'} &&
-           !defined $tc->{'decompress_program'};
+         if exists $tc->{'decompress_program'}
+         && (!defined $tc->{'decompress_program'}
+           || $tc->{'decompress_program'} eq '');
 
        # Take a client-side backup.
        my @backup      = (