mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
ci: Update the support for cross-build verifications; refactor
Rename `CI_HOST_ARCH` and `CI_HOST_SYSTEM`, to `CI_BUILD_ARCH` and `CI_BUILD_SYSTEM`, following the nomenclature used by GNU Autotools. Unfortunately, the word "host" has confusingly opposite meanings in CMake (and Bazel, etc.) vs. Autotools (and Meson, etc.) Remove `CI_TARGET_TRIPLET` and `CI_TARGET_ABI` (for now). Introduce the function `ci_expr` as a fast and easy equivalent of `expr >/dev/null`. Rephrase the assertions using an implementation pattern that is more expressive, yet (arguably) just as readable. Remove `ci_assert`. Modify the main functions to display more useful information in case of usage error.
This commit is contained in:
@@ -30,16 +30,6 @@ CI_BUILD_ARCH="${CI_BUILD_ARCH:-"$(uname -m | tr 'A-Z/\.-' 'a-z____')"}"
|
||||
CI_BUILD_SYSTEM="${CI_BUILD_SYSTEM:-"$(uname -s | tr 'A-Z/\.-' 'a-z____')"}"
|
||||
|
||||
# Initialize the global constants CI_TARGET_{...} for the target platform.
|
||||
if [[ $CI_TARGET_ARCH && $CI_TARGET_SYSTEM && $CI_TARGET_ABI ]]
|
||||
then
|
||||
CI_TARGET_TRIPLET="${CI_TARGET_TRIPLET:-$CI_TARGET_ARCH-$CI_TARGET_SYSTEM-$CI_TARGET_ABI}"
|
||||
elif [[ $CI_TARGET_TRIPLET ]]
|
||||
then
|
||||
CI_TARGET_ARCH="${CI_TARGET_ARCH:-${CI_TARGET_TRIPLET%%-*}}"
|
||||
CI_TARGET_DOUBLET_IMPL="${CI_TARGET_TRIPLET#*-}"
|
||||
CI_TARGET_SYSTEM="${CI_TARGET_SYSTEM:-${CI_TARGET_DOUBLET_IMPL%%-*}}"
|
||||
CI_TARGET_ABI="${CI_TARGET_ABI:-${CI_TARGET_DOUBLET_IMPL#*-}}"
|
||||
fi
|
||||
CI_TARGET_ARCH="${CI_TARGET_ARCH:-"$CI_BUILD_ARCH"}"
|
||||
CI_TARGET_SYSTEM="${CI_TARGET_SYSTEM:-"$CI_BUILD_SYSTEM"}"
|
||||
|
||||
@@ -63,16 +53,17 @@ function ci_err_internal {
|
||||
exit 134
|
||||
}
|
||||
|
||||
function ci_assert {
|
||||
# Use the "test" built-in command instead of the "[[ ]]" syntax,
|
||||
# to ensure the a-priori expansion of all assertion arguments.
|
||||
# (Consistently, both "ci_assert" and "test" have a command-like behavior.)
|
||||
[[ $# -ge 2 ]] ||
|
||||
ci_err_internal "failed: ci_assert: bad or missing operands"
|
||||
local label="$1"
|
||||
shift
|
||||
test "$@" ||
|
||||
ci_err_internal "failed: $label:" test "$@"
|
||||
function ci_expr {
|
||||
if [[ ${*:-0} == [0-9] ]]
|
||||
then
|
||||
# This is the same as in the else-branch below, albeit much faster
|
||||
# for our intended use cases.
|
||||
return $((!$1))
|
||||
else
|
||||
# The funny-looking compound command "... && return $? || return $?"
|
||||
# allows the execution to continue uninterrupted under "set -e".
|
||||
expr >/dev/null "$@" && return $? || return $?
|
||||
fi
|
||||
}
|
||||
|
||||
function ci_spawn {
|
||||
@@ -83,20 +74,11 @@ function ci_spawn {
|
||||
}
|
||||
|
||||
# Ensure that the initialization is correct.
|
||||
ci_assert "checking CI_TOPLEVEL_DIR" \
|
||||
"$CI_TOPLEVEL_DIR/ci/lib/ci.lib.sh" -ef "${BASH_SOURCE[0]}"
|
||||
ci_assert "checking CI_SCRIPT_DIR and CI_SCRIPT_NAME" \
|
||||
"$CI_SCRIPT_DIR/$CI_SCRIPT_NAME" -ef "$0"
|
||||
ci_assert "checking CI_BUILD_ARCH and CI_BUILD_SYSTEM" \
|
||||
-n "$CI_BUILD_ARCH" -a -n "$CI_BUILD_SYSTEM"
|
||||
ci_assert "checking CI_TARGET_ARCH and CI_TARGET_SYSTEM" \
|
||||
-n "$CI_TARGET_ARCH" -a -n "$CI_TARGET_SYSTEM"
|
||||
ci_assert "checking CI_TARGET_TRIPLET" \
|
||||
x"$CI_TARGET_TRIPLET" = x"" -o \
|
||||
x"$CI_TARGET_TRIPLET" = x"$CI_TARGET_ARCH-$CI_TARGET_SYSTEM-$CI_TARGET_ABI"
|
||||
ci_assert "checking if CI_NO_TEST is boolean" \
|
||||
$((CI_NO_TEST)) -eq $((!!CI_NO_TEST))
|
||||
ci_assert "checking if CI_NO_INSTALL is boolean" \
|
||||
$((CI_NO_INSTALL)) -eq $((!!CI_NO_INSTALL))
|
||||
ci_assert "checking if CI_NO_CLEAN is boolean" \
|
||||
$((CI_NO_CLEAN)) -eq $((!!CI_NO_CLEAN))
|
||||
[[ $CI_TOPLEVEL_DIR/ci/lib/ci.lib.sh -ef ${BASH_SOURCE[0]} ]] ||
|
||||
ci_err_internal "bad or missing \$CI_TOPLEVEL_DIR"
|
||||
[[ $CI_SCRIPT_DIR/$CI_SCRIPT_NAME -ef $0 ]] ||
|
||||
ci_err_internal "bad or missing \$CI_SCRIPT_DIR/\$CI_SCRIPT_NAME"
|
||||
[[ $CI_BUILD_ARCH && $CI_BUILD_SYSTEM ]] ||
|
||||
ci_err_internal "missing \$CI_BUILD_ARCH or \$CI_BUILD_SYSTEM"
|
||||
[[ $CI_TARGET_ARCH && $CI_TARGET_SYSTEM ]] ||
|
||||
ci_err_internal "missing \$CI_TARGET_ARCH or \$CI_TARGET_SYSTEM"
|
||||
|
||||
Reference in New Issue
Block a user