]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
script: add lib-build.sh for common high level funcs and no main
authorJohn Mulligan <jmulligan@redhat.com>
Mon, 31 Oct 2022 17:50:56 +0000 (13:50 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Tue, 18 Feb 2025 22:58:08 +0000 (17:58 -0500)
The intention of this file is collect some of the most basic or common
shell functions used across the various build scripts.
I would also like to ensure that functions added here are validated
using `shellcheck`. Currently, there's no automation for this, just
the honor system, but eventually we can start automating validating
this and other scripts with shellcheck.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
(cherry picked from commit 29d9a827e7396dcdc51b124f3e40e3144fa9ccb9)

src/script/lib-build.sh [new file with mode: 0644]
src/script/run-make.sh

diff --git a/src/script/lib-build.sh b/src/script/lib-build.sh
new file mode 100644 (file)
index 0000000..21da09e
--- /dev/null
@@ -0,0 +1,27 @@
+#!/usr/bin/env bash
+#
+# lib-build.sh - A library of build and test bash shell functions.
+#
+# There should be few, or none, globals in this file beyond function
+# definitions.
+#
+# This script should be `shellcheck`ed. Please run shellcheck when
+# making changes to this script and use ignore comments
+# (ref: https://www.shellcheck.net/wiki/Ignore ) to explicitly mark
+# where a line is intentionally ignoring a typical rule.
+#
+#  This library is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License, or (at your option) any later version.
+#
+
+# The following global only exists to help detect if lib-build has already been
+# sourced. This is only needed because the scripts that are being migrated are
+# often sourcing (as opposed to exec'ing one another).
+# shellcheck disable=SC2034
+_SOURCED_LIB_BUILD=1
+
+function in_jenkins() {
+    [ -n "$JENKINS_HOME" ]
+}
index 4b9a17b79069575713df364006da2469c6b38f6a..77bf57d6d96208b2fe6f1e4fd6f3b68fcc9cd8ee 100755 (executable)
@@ -2,15 +2,18 @@
 
 set -e
 
+if ! [ "${_SOURCED_LIB_BUILD}" = 1 ]; then
+    SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+    CEPH_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
+    . "${CEPH_ROOT}/src/script/lib-build.sh" || exit 2
+fi
+
+
 trap clean_up_after_myself EXIT
 
 ORIGINAL_CCACHE_CONF="$HOME/.ccache/ccache.conf"
 SAVED_CCACHE_CONF="$HOME/.run-make-check-saved-ccache-conf"
 
-function in_jenkins() {
-    test -n "$JENKINS_HOME"
-}
-
 function save_ccache_conf() {
     test -f $ORIGINAL_CCACHE_CONF && cp $ORIGINAL_CCACHE_CONF $SAVED_CCACHE_CONF || true
 }