]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
script: reorganize build scripts
authorJohn Mulligan <jmulligan@redhat.com>
Mon, 31 Oct 2022 14:54:53 +0000 (10:54 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Tue, 18 Feb 2025 22:58:08 +0000 (17:58 -0500)
In preparation for running builds and tests in containers, make some
organizational changes to the run-make-*.sh scripts.

Original version of the patch can be found at https://github.com/ceph/ceph/pull/46071

Original-version-by: Ernesto Puerta <epuertat@redhat.com>
Co-authored-by: Ernesto Puerta <epuertat@redhat.com>
Co-authored-by: John Mulligan <jmulligan@redhat.com>
Signed-off-by: Ernesto Puerta <epuertat@redhat.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
(cherry picked from commit 70bf755f9e62e4bb373e5082876a37b2a89abbc9)

run-make-check.sh
src/script/run-make.sh

index 096e3c6c8e1cd000c65aa637af1fe242cb449793..0ebe2b5de6bdf70f9c2d1e24cad4bb1db7373f82 100755 (executable)
@@ -22,10 +22,6 @@ source src/script/run-make.sh
 
 set -e
 
-function in_jenkins() {
-    test -n "$JENKINS_HOME"
-}
-
 function run() {
     # to prevent OSD EMFILE death on tests, make sure ulimit >= 1024
     $DRY_RUN ulimit -n $(ulimit -Hn)
@@ -75,43 +71,13 @@ function main() {
     fi
     # uses run-make.sh to install-deps
     FOR_MAKE_CHECK=1 prepare
-    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
-    # Init defaults after deps are installed.
-    local cmake_opts
-    cmake_opts+=" -DCMAKE_CXX_COMPILER=$cxx_compiler -DCMAKE_C_COMPILER=$c_compiler"
-    cmake_opts+=" -DCMAKE_CXX_FLAGS_DEBUG=-Werror"
-    cmake_opts+=" -DENABLE_GIT_VERSION=OFF"
-    cmake_opts+=" -DWITH_GTEST_PARALLEL=ON"
-    cmake_opts+=" -DWITH_FIO=ON"
-    cmake_opts+=" -DWITH_CEPHFS_SHELL=ON"
-    cmake_opts+=" -DWITH_GRAFANA=ON"
-    cmake_opts+=" -DWITH_SPDK=ON"
-    cmake_opts+=" -DWITH_RBD_MIRROR=ON"
-    if [ $WITH_SEASTAR ]; then
-        cmake_opts+=" -DWITH_SEASTAR=ON"
-    fi
-    if [ $WITH_ZBD ]; then
-        cmake_opts+=" -DWITH_ZBD=ON"
-    fi
-    if [ $WITH_RBD_RWL ]; then
-        cmake_opts+=" -DWITH_RBD_RWL=ON"
-    fi
-    cmake_opts+=" -DWITH_RBD_SSD_CACHE=ON"
-    in_jenkins && echo "CI_DEBUG: Our cmake_opts are: $cmake_opts
-                        CI_DEBUG: Running ./configure"
-    configure "$cmake_opts" "$@"
+    configure "$@"
     in_jenkins && echo "CI_DEBUG: Running 'build tests'"
     build tests
     echo "make check: successful build on $(git rev-parse HEAD)"
     FOR_MAKE_CHECK=1 run
 }
 
-main "$@"
+if [ "$0" = "$BASH_SOURCE" ]; then
+    main "$@"
+fi
index 683272666a9d92fa54822a81b4af6f2f41ff2397..c746cf752b7e8fe0acddd21ee021d4bf26329431 100755 (executable)
@@ -67,7 +67,11 @@ function do_install() {
     pkgs=$@
     shift
     ret=0
-    $DRY_RUN sudo $install_cmd $pkgs || ret=$?
+    SUDO=""
+    if [ "$EUID" -ne 0 ]; then
+        SUDO="sudo"
+    fi
+    $DRY_RUN $SUDO $install_cmd $pkgs || ret=$?
     if test $ret -eq 0 ; then
         return
     fi
@@ -75,9 +79,9 @@ function do_install() {
     if [[ $install_cmd == *"apt-get"* ]]; then
         if test $ret -eq 100 ; then
             # dpkg was interrupted
-            $DRY_RUN sudo dpkg --configure -a
-            in_jenkins && echo "CI_DEBUG: Running 'sudo $install_cmd $pkgs'"
-            $DRY_RUN sudo $install_cmd $pkgs
+            $DRY_RUN $SUDO dpkg --configure -a
+            in_jenkins && echo "CI_DEBUG: Running '$SUDO $install_cmd $pkgs'"
+            $DRY_RUN $SUDO $install_cmd $pkgs
         else
             return $ret
         fi
@@ -88,11 +92,7 @@ function prepare() {
     local which_pkg="which"
     source /etc/os-release
     if test -f /etc/redhat-release ; then
-        if ! type bc > /dev/null 2>&1 ; then
-            echo "Please install bc and re-run." 
-            exit 1
-        fi
-        if test "$(echo "$VERSION_ID >= 22" | bc)" -ne 0; then
+        if [ "$VERSION_ID" -ge "22" ]; then
             install_cmd="dnf -y install"
         else
             install_cmd="yum install -y"
@@ -104,14 +104,14 @@ function prepare() {
         which_pkg="debianutils"
     fi
 
-    if ! type sudo > /dev/null 2>&1 ; then
+    if [ "$EUID" -ne 0 ] && ! type sudo > /dev/null 2>&1 ; then
         echo "Please install sudo and re-run. This script assumes it is running"
-        echo "as a normal user with the ability to run commands as root via sudo." 
+        echo "as a normal user with the ability to run commands as root via sudo."
         exit 1
     fi
     if [ -n "$install_cmd" ]; then
         in_jenkins && echo "CI_DEBUG: Running '$install_cmd ccache $which_pkg clang'"
-        do_install "$install_cmd" ccache $which_pkg clang
+        do_install "$install_cmd" ccache git $which_pkg clang
     else
         echo "WARNING: Don't know how to install packages" >&2
         echo "This probably means distribution $ID is not supported by run-make-check.sh" >&2
@@ -127,7 +127,9 @@ function prepare() {
         $DRY_RUN source ./install-deps.sh || return 1
         trap clean_up_after_myself EXIT
     fi
+}
 
+function configure() {
     cat <<EOM
 Note that the binaries produced by this script do not contain correct time
 and git version information, which may make them unsuitable for debugging
@@ -148,12 +150,44 @@ EOM
         ccache -p | grep max_size
     fi
     $DRY_RUN ccache -sz # Reset the ccache statistics and show the current configuration
-}
 
-function configure() {
-    local cmake_build_opts=$(detect_ceph_dev_pkgs)
+    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
+    local cmake_opts
+    cmake_opts+=" -DCMAKE_CXX_COMPILER=$cxx_compiler -DCMAKE_C_COMPILER=$c_compiler"
+    cmake_opts+=" -DCMAKE_CXX_FLAGS_DEBUG=-Werror"
+    cmake_opts+=" -DENABLE_GIT_VERSION=OFF"
+    cmake_opts+=" -DWITH_GTEST_PARALLEL=ON"
+    cmake_opts+=" -DWITH_FIO=ON"
+    cmake_opts+=" -DWITH_CEPHFS_SHELL=ON"
+    cmake_opts+=" -DWITH_GRAFANA=ON"
+    cmake_opts+=" -DWITH_SPDK=ON"
+    cmake_opts+=" -DWITH_RBD_MIRROR=ON"
+    if [ $WITH_SEASTAR ]; then
+        cmake_opts+=" -DWITH_SEASTAR=ON"
+    fi
+    if [ $WITH_ZBD ]; then
+        cmake_opts+=" -DWITH_ZBD=ON"
+    fi
+    if [ $WITH_RBD_RWL ]; then
+        cmake_opts+=" -DWITH_RBD_RWL=ON"
+    fi
+    cmake_opts+=" -DWITH_RBD_SSD_CACHE=ON"
+
+    cmake_opts+=$(detect_ceph_dev_pkgs)
+
+    in_jenkins && echo "CI_DEBUG: Our cmake_opts are: $cmake_opts
+                        CI_DEBUG: Running ./configure"
     in_jenkins && echo "CI_DEBUG: Running do_cmake.sh"
-    $DRY_RUN ./do_cmake.sh $cmake_build_opts $@ || return 1
+
+    $DRY_RUN ./do_cmake.sh $cmake_opts $@ || return 1
 }
 
 function build() {