Skip to content

Commit

Permalink
[build-support] fix build on CentOS/RHEL
Browse files Browse the repository at this point in the history
This pach fixes building Kudu on CentOS/RHEL.  7747a7c 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 7747a7c.

[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 <alexey@apache.org>
Reviewed-by: Abhishek Chennaka <achennaka@cloudera.com>
(cherry picked from commit 58e42b4)
Reviewed-on: http://gerrit.cloudera.org:8080/20334
Reviewed-by: Yingchun Lai <laiyingchun@apache.org>
Tested-by: Kudu Jenkins
  • Loading branch information
alexeyserbin committed Aug 9, 2023
1 parent b3fe319 commit e9fea99
Showing 1 changed file with 80 additions and 39 deletions.
119 changes: 80 additions & 39 deletions build-support/enable_devtoolset.sh
Expand Up @@ -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
Expand All @@ -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

0 comments on commit e9fea99

Please sign in to comment.