diff --git a/ci/ci_lint_ci.sh b/ci/ci_lint_ci.sh index ce3793d4a..fa45c5473 100755 --- a/ci/ci_lint_ci.sh +++ b/ci/ci_lint_ci.sh @@ -60,8 +60,8 @@ function ci_lint_ci_scripts_license { function main { [[ $# -eq 0 ]] || { - ci_info "note: this program accepts environment options only" - ci_err "unsupported command argument: '$1'" + ci_info "usage: $CI_SCRIPT_NAME" + ci_err "unexpected command argument: '$1'" } ci_lint_ci_config_files ci_lint_ci_scripts diff --git a/ci/ci_verify_cmake.sh b/ci/ci_verify_cmake.sh index 55967354a..a3f737983 100755 --- a/ci/ci_verify_cmake.sh +++ b/ci/ci_verify_cmake.sh @@ -39,19 +39,18 @@ function ci_init_build { [[ $TEMP && ( $Temp || $temp ) ]] && unset TEMP [[ $TMP && ( $Tmp || $tmp ) ]] && unset TMP # Ensure that CI_CMAKE_GENERATOR_PLATFORM is initialized for this generator. - ci_assert "checking CI_CMAKE_GENERATOR_PLATFORM" \ - -n "$CI_CMAKE_GENERATOR_PLATFORM" + [[ $CI_CMAKE_GENERATOR_PLATFORM ]] || + ci_err_internal "missing \$CI_CMAKE_GENERATOR_PLATFORM" fi } function ci_trace_build { ci_info "## START OF CONFIGURATION ##" - ci_info "host arch: $CI_HOST_ARCH" - ci_info "host system: $CI_HOST_SYSTEM" - [[ "$CI_TARGET_SYSTEM.$CI_TARGET_ARCH" != "$CI_HOST_SYSTEM.$CI_HOST_ARCH" ]] && { + ci_info "build arch: $CI_BUILD_ARCH" + ci_info "build system: $CI_BUILD_SYSTEM" + [[ "$CI_TARGET_SYSTEM.$CI_TARGET_ARCH" != "$CI_BUILD_SYSTEM.$CI_BUILD_ARCH" ]] && { ci_info "target arch: $CI_TARGET_ARCH" ci_info "target system: $CI_TARGET_SYSTEM" - ci_info "target ABI: $CI_TARGET_ABI" } ci_info "source directory: $CI_SRC_DIR" ci_info "build directory: $CI_BUILD_DIR" @@ -122,8 +121,6 @@ function ci_build { } ALL_CMAKE_VARS+=(-DCMAKE_BUILD_TYPE="$CI_CMAKE_BUILD_TYPE") ALL_CMAKE_VARS+=(-DCMAKE_VERBOSE_MAKEFILE=ON) - [[ $((CI_NO_TEST)) -ne 0 ]] && - ALL_CMAKE_VARS+=(-DPNG_TESTS=OFF) ALL_CMAKE_VARS+=($CI_CMAKE_VARS) local ALL_CMAKE_BUILD_FLAGS=($CI_CMAKE_BUILD_FLAGS) local ALL_CTEST_FLAGS=($CI_CTEST_FLAGS) @@ -137,48 +134,48 @@ function ci_build { # instead of $CI_SRC_DIR and $CI_INSTALL_DIR from this point onwards. ci_spawn mkdir -p "$CI_BUILD_DIR" ci_spawn cd "$CI_BUILD_DIR" - ci_assert "checking CI_BUILD_TO_SRC_RELDIR" \ - "$CI_SRC_DIR" -ef "$CI_BUILD_TO_SRC_RELDIR" + [[ $CI_BUILD_TO_SRC_RELDIR -ef $CI_SRC_DIR ]] || + ci_err_internal "bad or missing \$CI_BUILD_TO_SRC_RELDIR" ci_spawn mkdir -p "$CI_INSTALL_DIR" - ci_assert "checking CI_BUILD_TO_INSTALL_RELDIR" \ - "$CI_INSTALL_DIR" -ef "$CI_BUILD_TO_INSTALL_RELDIR" + [[ $CI_BUILD_TO_INSTALL_RELDIR -ef $CI_INSTALL_DIR ]] || + ci_err_internal "bad or missing \$CI_BUILD_TO_INSTALL_RELDIR" # Spawn "cmake ...". ci_spawn "$CI_CMAKE" -DCMAKE_INSTALL_PREFIX="$CI_BUILD_TO_INSTALL_RELDIR" \ "${ALL_CMAKE_VARS[@]}" \ "$CI_BUILD_TO_SRC_RELDIR" # Spawn "cmake --build ...". ci_spawn "$CI_CMAKE" --build . \ - --config "$CI_CMAKE_BUILD_TYPE" \ + --config="$CI_CMAKE_BUILD_TYPE" \ "${ALL_CMAKE_BUILD_FLAGS[@]}" - [[ $((CI_NO_TEST)) -ne 0 ]] || { + ci_expr $((CI_NO_TEST)) || { # Spawn "ctest" if testing is not disabled. - ci_spawn "$CI_CTEST" --build-config "$CI_CMAKE_BUILD_TYPE" \ + ci_spawn "$CI_CTEST" --build-config="$CI_CMAKE_BUILD_TYPE" \ "${ALL_CTEST_FLAGS[@]}" } - [[ $((CI_NO_INSTALL)) -ne 0 ]] || { - # Spawn "cmake --build ... --target install" if installation is not disabled. + ci_expr $((CI_NO_INSTALL)) || { + # Spawn "cmake --build ... --target=install" if installation is not disabled. ci_spawn "$CI_CMAKE" --build . \ - --config "$CI_CMAKE_BUILD_TYPE" \ - --target install \ + --config="$CI_CMAKE_BUILD_TYPE" \ + --target=install \ "${ALL_CMAKE_BUILD_FLAGS[@]}" } - [[ $((CI_NO_CLEAN)) -ne 0 ]] || { - # Spawn "make --build ... --target clean" if cleaning is not disabled. + ci_expr $((CI_NO_CLEAN)) || { + # Spawn "make --build ... --target=clean" if cleaning is not disabled. ci_spawn "$CI_CMAKE" --build . \ - --config "$CI_CMAKE_BUILD_TYPE" \ - --target clean \ + --config="$CI_CMAKE_BUILD_TYPE" \ + --target=clean \ "${ALL_CMAKE_BUILD_FLAGS[@]}" } ci_info "## END OF BUILD ##" } function main { - [[ $# -eq 0 ]] || { - ci_info "note: this program accepts environment options only" - ci_err "unsupported command argument: '$1'" - } ci_init_build ci_trace_build + [[ $# -eq 0 ]] || { + ci_info "note: this program accepts environment options only (see above)" + ci_err "unexpected command argument: '$1'" + } ci_cleanup_old_build ci_build } diff --git a/ci/ci_verify_configure.sh b/ci/ci_verify_configure.sh index 9e0d77780..fa7e82e65 100755 --- a/ci/ci_verify_configure.sh +++ b/ci/ci_verify_configure.sh @@ -22,7 +22,7 @@ CI_INSTALL_DIR="$CI_OUT_DIR/ci_verify_configure.$CI_TARGET_SYSTEM.$CI_TARGET_ARC function ci_init_build { # Ensure that the mandatory variables are initialized. CI_MAKE="${CI_MAKE:-make}" - [[ "$CI_TARGET_SYSTEM.$CI_TARGET_ARCH" != "$CI_HOST_SYSTEM.$CI_HOST_ARCH" ]] || { + [[ "$CI_TARGET_SYSTEM.$CI_TARGET_ARCH" != "$CI_BUILD_SYSTEM.$CI_BUILD_ARCH" ]] || { # For native builds, set CI_CC to "cc" by default if the cc command is available. # The configure script defaults CC to "gcc", which is not always a good idea. [[ -x $(command -v cc) ]] && CI_CC="${CI_CC:-cc}" @@ -36,12 +36,11 @@ function ci_init_build { function ci_trace_build { ci_info "## START OF CONFIGURATION ##" - ci_info "host arch: $CI_HOST_ARCH" - ci_info "host system: $CI_HOST_SYSTEM" - [[ "$CI_TARGET_SYSTEM.$CI_TARGET_ARCH" != "$CI_HOST_SYSTEM.$CI_HOST_ARCH" ]] && { + ci_info "build arch: $CI_BUILD_ARCH" + ci_info "build system: $CI_BUILD_SYSTEM" + [[ "$CI_TARGET_SYSTEM.$CI_TARGET_ARCH" != "$CI_BUILD_SYSTEM.$CI_BUILD_ARCH" ]] && { ci_info "target arch: $CI_TARGET_ARCH" ci_info "target system: $CI_TARGET_SYSTEM" - ci_info "target ABI: $CI_TARGET_ABI" } ci_info "source directory: $CI_SRC_DIR" ci_info "build directory: $CI_BUILD_DIR" @@ -107,15 +106,15 @@ function ci_build { ci_spawn "$CI_SRC_DIR/configure" --prefix="$CI_INSTALL_DIR" $CI_CONFIGURE_FLAGS # Spawn "make". ci_spawn "$CI_MAKE" $CI_MAKE_FLAGS - [[ $((CI_NO_TEST)) -ne 0 ]] || { + ci_expr $((CI_NO_TEST)) || { # Spawn "make test" if testing is not disabled. ci_spawn "$CI_MAKE" $CI_MAKE_FLAGS test } - [[ $((CI_NO_INSTALL)) -ne 0 ]] || { + ci_expr $((CI_NO_INSTALL)) || { # Spawn "make install" if installation is not disabled. ci_spawn "$CI_MAKE" $CI_MAKE_FLAGS install } - [[ $((CI_NO_CLEAN)) -ne 0 ]] || { + ci_expr $((CI_NO_CLEAN)) || { # Spawn "make clean" and "make distclean" if cleaning is not disabled. ci_spawn "$CI_MAKE" $CI_MAKE_FLAGS clean ci_spawn "$CI_MAKE" $CI_MAKE_FLAGS distclean @@ -124,12 +123,12 @@ function ci_build { } function main { - [[ $# -eq 0 ]] || { - ci_info "note: this program accepts environment options only" - ci_err "unsupported command argument: '$1'" - } ci_init_build ci_trace_build + [[ $# -eq 0 ]] || { + ci_info "note: this program accepts environment options only (see above)" + ci_err "unexpected command argument: '$1'" + } ci_cleanup_old_build ci_build } diff --git a/ci/ci_verify_makefiles.sh b/ci/ci_verify_makefiles.sh index ef6d7838b..79b97a383 100755 --- a/ci/ci_verify_makefiles.sh +++ b/ci/ci_verify_makefiles.sh @@ -31,12 +31,11 @@ function ci_init_build { function ci_trace_build { ci_info "## START OF CONFIGURATION ##" - ci_info "host arch: $CI_HOST_ARCH" - ci_info "host system: $CI_HOST_SYSTEM" - [[ "$CI_TARGET_SYSTEM.$CI_TARGET_ARCH" != "$CI_HOST_SYSTEM.$CI_HOST_ARCH" ]] && { + ci_info "build arch: $CI_BUILD_ARCH" + ci_info "build system: $CI_BUILD_SYSTEM" + [[ "$CI_TARGET_SYSTEM.$CI_TARGET_ARCH" != "$CI_BUILD_SYSTEM.$CI_BUILD_ARCH" ]] && { ci_info "target arch: $CI_TARGET_ARCH" ci_info "target system: $CI_TARGET_SYSTEM" - ci_info "target ABI: $CI_TARGET_ABI" } ci_info "source directory: $CI_SRC_DIR" ci_info "environment option: \$CI_MAKEFILES: '$CI_MAKEFILES'" @@ -120,14 +119,14 @@ function ci_build { ci_spawn "$CI_MAKE" -f "$MY_MAKEFILE" \ "${ALL_MAKE_FLAGS[@]}" \ "${ALL_MAKE_VARS[@]}" - [[ $((CI_NO_TEST)) -ne 0 ]] || { + ci_expr $((CI_NO_TEST)) || { # Spawn "make test" if testing is not disabled. ci_spawn "$CI_MAKE" -f "$MY_MAKEFILE" \ "${ALL_MAKE_FLAGS[@]}" \ "${ALL_MAKE_VARS[@]}" \ test } - [[ $((CI_NO_CLEAN)) -ne 0 ]] || { + ci_expr $((CI_NO_CLEAN)) || { # Spawn "make clean" if cleaning is not disabled. ci_spawn "$CI_MAKE" -f "$MY_MAKEFILE" \ "${ALL_MAKE_FLAGS[@]}" \ @@ -139,12 +138,12 @@ function ci_build { } function main { - [[ $# -eq 0 ]] || { - ci_info "note: this program accepts environment options only" - ci_err "unsupported command argument: '$1'" - } ci_init_build ci_trace_build + [[ $# -eq 0 ]] || { + ci_info "note: this program accepts environment options only (see above)" + ci_err "unexpected command argument: '$1'" + } ci_cleanup_old_build ci_build } diff --git a/ci/lib/ci.lib.sh b/ci/lib/ci.lib.sh index 29ab53ab8..fc3e1b653 100644 --- a/ci/lib/ci.lib.sh +++ b/ci/lib/ci.lib.sh @@ -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"