From: John Mulligan Date: Mon, 31 Oct 2022 17:50:56 +0000 (-0400) Subject: script: add lib-build.sh for common high level funcs and no main X-Git-Tag: testing/56408~36^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0343bee86511ef01eb9dbb78cbe51482cc7864d7;p=ceph-ci.git script: add lib-build.sh for common high level funcs and no main 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 (cherry picked from commit 29d9a827e7396dcdc51b124f3e40e3144fa9ccb9) --- diff --git a/src/script/lib-build.sh b/src/script/lib-build.sh new file mode 100644 index 00000000000..21da09eb62d --- /dev/null +++ b/src/script/lib-build.sh @@ -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" ] +} diff --git a/src/script/run-make.sh b/src/script/run-make.sh index 4b9a17b7906..77bf57d6d96 100755 --- a/src/script/run-make.sh +++ b/src/script/run-make.sh @@ -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 }