Skip to content

Commit

Permalink
script: add lib-build.sh for common high level funcs and no main
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
phlogistonjohn committed Feb 7, 2023
1 parent 5f92f54 commit 29d9a82
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
27 changes: 27 additions & 0 deletions src/script/lib-build.sh
Original file line number Diff line number Diff line change
@@ -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" ]
}
11 changes: 7 additions & 4 deletions src/script/run-make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 29d9a82

Please sign in to comment.