This is an automated email from the ASF dual-hosted git repository.

alexey pushed a commit to branch branch-1.17.x
in repository https://gitbox.apache.org/repos/asf/kudu.git

commit e9fea9907fa98e368bb1b7cdd0ca6fc976122aa9
Author: Alexey Serbin <ale...@apache.org>
AuthorDate: Tue May 2 13:23:59 2023 -0700

    [build-support] fix build on CentOS/RHEL
    
    This pach fixes building Kudu on CentOS/RHEL.  7747a7c01 introduced
    an update on build_support/enable_devtoolset.sh script that has broken
    the build.
    
    In addition, it turns out the lsb_release utility might not be available
    at some Linux distributions, e.g. CentOS/RHEL 9 [1].  This patch updates
    the enable_devtoolset.sh script accordingly.
    
    This is a follow-up to 7747a7c0149d6e8f894ad3216c54db9f27b3d372.
    
    [1] https://bugzilla.redhat.com/show_bug.cgi?id=1964381
    
    Change-Id: Ia8069c09bc5be174b40b7b9cff856af4ad54652a
    Reviewed-on: http://gerrit.cloudera.org:8080/19833
    Tested-by: Alexey Serbin <ale...@apache.org>
    Reviewed-by: Abhishek Chennaka <achenn...@cloudera.com>
    (cherry picked from commit 58e42b476abd4234f6a83f765253b2b7779a9046)
    Reviewed-on: http://gerrit.cloudera.org:8080/20334
    Reviewed-by: Yingchun Lai <laiyingc...@apache.org>
    Tested-by: Kudu Jenkins
---
 build-support/enable_devtoolset.sh | 119 +++++++++++++++++++++++++------------
 1 file changed, 80 insertions(+), 39 deletions(-)

diff --git a/build-support/enable_devtoolset.sh 
b/build-support/enable_devtoolset.sh
index ef86daf9a..715a32ea0 100755
--- a/build-support/enable_devtoolset.sh
+++ b/build-support/enable_devtoolset.sh
@@ -34,46 +34,39 @@ set -e
 
 ROOT=$(cd $(dirname "$BASH_SOURCE") ; pwd)
 
-if [[ "$OSTYPE" =~ ^linux ]]; then
-  if ! lsb_release -irs > /dev/null 2>&1; then
-    echo "ERROR: could not retrieve Linux distribution info; "
-    echo "       make sure the 'lsb_release' utility is present in PATH"
-    exit 1
-  fi
+custom_run_at_rhel() {
+  # Enable devtoolset-8 and invoke the inner script, which may do some
+  # additional customization within the devtoolset.
+  scl enable devtoolset-8 "$ROOT/enable_devtoolset_inner.sh $*"
+}
 
-  LSB_INFO="$(lsb_release -irs)"
-  if [[ "$LSB_INFO" =~ 
(CentOS|RedHatEnterpriseServer|OracleServer)[[:space:]]+(6|7)\.[[:digit:]]+ ]]; 
then
-    # Enable devtoolset-8 and invoke the inner script, which may do some
-    # additional customization within the devtoolset.
-    scl enable devtoolset-8 "$ROOT/enable_devtoolset_inner.sh $*"
-  elif [[ "$LSB_INFO" =~ (SUSE)[[:space:]]+1[25]\.[[:digit:]]+ ]]; then
-    # On SLES12 and SLES15, Kudu can be built both by gcc-8 and gcc-7 since
-    # either one supports the C++17 standard. Prefer gcc-8 over gcc-7 if both
-    # compilers are present.
-    GCC_MAJOR_VERSION=
-    if /usr/bin/gcc-8 -v > /dev/null 2>&1 && /usr/bin/g++-8 -v > /dev/null 
2>&1; then
-      GCC_MAJOR_VERSION=8
-    elif /usr/bin/gcc-7 -v > /dev/null 2>&1 && /usr/bin/g++-7 -v > /dev/null 
2>&1; then
-      GCC_MAJOR_VERSION=7
-    fi
+custom_run_at_sles() {
+  # On SLES12 and SLES15, Kudu can be built both by gcc-8 and gcc-7 since
+  # either one supports the C++17 standard. Prefer gcc-8 over gcc-7 if both
+  # compilers are present.
+  local GCC_MAJOR_VERSION=
+  if /usr/bin/gcc-8 -v > /dev/null 2>&1 && /usr/bin/g++-8 -v > /dev/null 2>&1; 
then
+    GCC_MAJOR_VERSION=8
+  elif /usr/bin/gcc-7 -v > /dev/null 2>&1 && /usr/bin/g++-7 -v > /dev/null 
2>&1; then
+    GCC_MAJOR_VERSION=7
+  fi
 
-    if [ -z "$GCC_MAJOR_VERSION" ]; then
-      echo "ERROR: found neither gcc/g++-8 nor gcc/g++-7 in /usr/bin"
-      exit 2
-    fi
+  if [ -z "$GCC_MAJOR_VERSION" ]; then
+    echo "ERROR: found neither gcc/g++-8 nor gcc/g++-7 in /usr/bin"
+    exit 2
+  fi
 
-    # If ccache was on the PATH and CC/CXX have not already been set,
-    # set them to gcc-[7,8] specific ccache helper scripts, enabling ccache.
-    if which ccache > /dev/null 2>&1 && [ ! "$CC" -a ! "$CXX" ]; then
-      export CC="$ROOT/ccache-gcc-$GCC_MAJOR_VERSION/cc"
-      export CXX="$ROOT/ccache-gcc-$GCC_MAJOR_VERSION/c++"
-    fi
+  # If ccache was on the PATH and CC/CXX have not already been set,
+  # set them to gcc-[7,8] specific ccache helper scripts, enabling ccache.
+  if which ccache > /dev/null 2>&1 && [ ! "$CC" -a ! "$CXX" ]; then
+    export CC="$ROOT/ccache-gcc-$GCC_MAJOR_VERSION/cc"
+    export CXX="$ROOT/ccache-gcc-$GCC_MAJOR_VERSION/c++"
+  fi
 
-    # If CC/CXX have not already been set, set them accordingly.
-    if [ ! "$CC" -a ! "$CXX" ]; then
-      export CC="/usr/bin/gcc-$GCC_MAJOR_VERSION"
-      export CXX="/usr/bin/g++-$GCC_MAJOR_VERSION"
-    fi
+  # If CC/CXX have not already been set, set them accordingly.
+  if [ ! "$CC" -a ! "$CXX" ]; then
+    export CC="/usr/bin/gcc-$GCC_MAJOR_VERSION"
+    export CXX="/usr/bin/g++-$GCC_MAJOR_VERSION"
   fi
 
   # TODO(aserbin): patch the protobuf in thirdparty to accept standard CC
@@ -82,7 +75,55 @@ if [[ "$OSTYPE" =~ ^linux ]]; then
   export CC_FOR_BUILD="$CC"
   export CPP_FOR_BUILD="$CC -E"
   export CXXCPP_FOR_BUILD="$CXX -E"
-fi
 
-# Execute the arguments
-$@
+  # Execute the arguments
+  $@
+}
+
+if [[ "$OSTYPE" =~ ^linux ]]; then
+  # It is not practical to require the presence of the 'lsb_release' utility
+  # on RHEL/CentOS/OracleLinux 9, so this script uses /etc/os-release instead
+  # in such case, see https://bugzilla.redhat.com/show_bug.cgi?id=1964381
+  # Overall, it seems /etc/os-release has become a standard de facto:
+  # https://man7.org/linux/man-pages/man5/os-release.5.html
+  #
+  # From the other side, legacy releases such as CentOS/RHEL 6 don't have
+  # /etc/os-release as a part of its 'centos-release' package. So, this
+  # helper script relies on a hybrid approach.
+  #
+  # TODO(aserbin): deprecate the usage of lsb_release and switch to using
+  #                /etc/os-release once support for legacy Linux OS releases
+  #                isn't needed
+  OS_REL_FILE="/etc/os-release"
+
+  if lsb_release -irs > /dev/null 2>&1; then
+    LSB_INFO="$(lsb_release -irs 2>/dev/null)"
+    if [[ "$LSB_INFO" =~ 
(CentOS|RedHatEnterpriseServer|OracleServer)[[:space:]]+(6|7)(\.[[:digit:]]+)* 
]]; then
+      custom_run_at_rhel $@
+    elif [[ "$LSB_INFO" =~ (SUSE)[[:space:]]+1[25](\.[[:digit:]]+)* ]]; then
+      custom_run_at_sles $@
+    else
+      # Run as-is
+      $@
+    fi
+  elif [ -r $OS_REL_FILE ]; then
+    if grep -Eq 'ID=["]?(rhel|centos|ol)["]?' $OS_REL_FILE && \
+        grep -Eq 'VERSION_ID=["]?[6|7]+(\.[[:digit:]])*["]?' $OS_REL_FILE; then
+      custom_run_at_rhel $@
+    elif grep -Eq 'ID=["]?sles["]?' $OS_REL_FILE && \
+        grep -Eq 'VERSION_ID=["]?1[25](\.[[:digit:]])*["]?' $OS_REL_FILE; then
+      custom_run_at_sles $@
+    else
+      # Run as-is
+      $@
+    fi
+  else
+    echo "ERROR: could not retrieve Linux distribution info; "
+    echo "       make sure the 'lsb_release' utility is present in PATH "
+    echo "       or file $OS_REL_FILE exists and readable"
+    exit 1
+  fi
+else
+  # Run as-is
+  $@
+fi

Reply via email to