]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
script: add discover_compiler function to lib-build.sh
authorJohn Mulligan <jmulligan@redhat.com>
Tue, 1 Nov 2022 18:51:57 +0000 (14:51 -0400)
committerKamoltat Sirivadhna <ksirivad@redhat.com>
Fri, 10 Oct 2025 18:26:44 +0000 (18:26 +0000)
The discover_compiler function is an abstraction over the current
compiler detection code in run-make.sh. It is intended to be flexible
enough to work on {centos,rhel} systems, but currently is just an
updated version of the logic from run-make.sh. The intent is that this
function will grow and become useful for other scripts used for
building (possibly do_cmake.sh for example).

Signed-off-by: John Mulligan <jmulligan@redhat.com>
(cherry picked from commit 561bf4ea9b4dd8f6710a959c5bd38eb4085a9d52)
(cherry picked from commit 8dae1c161c4d3bc3a1ef3cd48de0da9a89e44e65)

src/script/lib-build.sh

index 052df9e28606702120d456413ffc03874739188e..59471b4a8e8add0e751eaacb14a0d855ba0d4399 100644 (file)
@@ -31,8 +31,16 @@ function ci_debug() {
         echo "CI_DEBUG: $*"
     fi
 }
-<<<<<<< HEAD
-=======
+
+function wrap_sudo() {
+    # set or unset the SUDO env var so that scripts already running
+    # as root do not call into sudo to escalate privs
+    if test $(id -u) != 0 ; then
+        SUDO=sudo
+    else
+        SUDO=""
+    fi
+}
 
 # get_processors returns 1/2 the value of the value returned by
 # the nproc program OR the value of the environment variable NPROC
@@ -51,6 +59,14 @@ function get_processors() {
     fi
 }
 
+# has_build_dir returns true if a build directory exists and can be used
+# for builds. has_build_dir is designed to interoperate with do_cmake.sh
+# and uses the same BUILD_DIR environment variable. It checks for the
+# directory relative to the current working directory.
+function has_build_dir() {
+    ( cd "${BUILD_DIR:=build}" && [[ -f build.ninja || -f Makefile ]] )
+}
+
 # discover_compiler takes one argument, purpose, which may be used
 # to adjust the results for a specific need. It sets three environment
 # variables `discovered_c_compiler`, `discovered_cxx_compiler` and
@@ -73,10 +89,18 @@ function discover_compiler() {
             break
         fi
     done
+    # but if this is {centos,rhel} we need gcc-toolset
+    if [ -f "/opt/rh/gcc-toolset-11/enable" ]; then
+        ci_debug "Detected SCL gcc-toolset-11 environment file"
+        compiler_env="/opt/rh/gcc-toolset-11/enable"
+        # shellcheck disable=SC1090
+        cxx_compiler="$(. ${compiler_env} && command -v g++)"
+        # shellcheck disable=SC1090
+        c_compiler="$(. ${compiler_env} && command -v gcc)"
+    fi
 
     export discovered_c_compiler="${c_compiler}"
     export discovered_cxx_compiler="${cxx_compiler}"
     export discovered_compiler_env="${compiler_env}"
     return 0
-}
->>>>>>> 8dae1c161c4 (script: add discover_compiler function to lib-build.sh)
+}
\ No newline at end of file