]> git.apps.os.sepia.ceph.com Git - ceph.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)
committerJohn Mulligan <jmulligan@redhat.com>
Tue, 18 Feb 2025 22:58:08 +0000 (17:58 -0500)
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)

src/script/lib-build.sh
src/script/run-make.sh

index 17c2fe72148c7198565c5c371f340e5084b9cc30..c6ce94b633ad7c0ea1df3bad8aba1f25d30cfecb 100644 (file)
@@ -48,3 +48,32 @@ function get_processors() {
         fi
     fi
 }
+
+# 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
+# `discovered_compiler_env`. The `discovered_compiler_env` variable
+# may be blank. If not, it will contain a file that needs to be sourced
+# prior to using the compiler.
+function discover_compiler() {
+    # nb: currently purpose is not used for detection
+    local purpose="$1"
+    ci_debug "Finding compiler for ${purpose}"
+
+    local compiler_env=""
+    local cxx_compiler=g++
+    local c_compiler=gcc
+    # ubuntu/debian ci builds prefer clang
+    for i in {14..10}; do
+        if type -t "clang-$i" > /dev/null; then
+            cxx_compiler="clang++-$i"
+            c_compiler="clang-$i"
+            break
+        fi
+    done
+
+    export discovered_c_compiler="${c_compiler}"
+    export discovered_cxx_compiler="${cxx_compiler}"
+    export discovered_compiler_env="${compiler_env}"
+    return 0
+}
index 4331e581aa5849a0e5985d4bfd9c3a94748f64ce..8e04e6fc8a46fef9e37a48dc4275ea95addfef6f 100755 (executable)
@@ -89,15 +89,11 @@ EOM
     fi
     $DRY_RUN ccache -sz # Reset the ccache statistics and show the current configuration
 
-    local cxx_compiler=g++
-    local c_compiler=gcc
-    for i in $(seq 14 -1 10); do
-        if type -t clang-$i > /dev/null; then
-            cxx_compiler="clang++-$i"
-            c_compiler="clang-$i"
-            break
-        fi
-    done
+    if ! discover_compiler ci-build ; then
+        ci_debug "Failed to discover a compiler"
+    fi
+    local cxx_compiler="${discovered_cxx_compiler}"
+    local c_compiler="${discovered_c_compiler}"
     local cmake_opts
     cmake_opts+=" -DCMAKE_CXX_COMPILER=$cxx_compiler -DCMAKE_C_COMPILER=$c_compiler"
     cmake_opts+=" -DCMAKE_CXX_FLAGS_DEBUG=-Werror"