diff --git a/ci/.shellcheckrc b/ci/.shellcheckrc index 3ee2a1e6e..0260dcca3 100644 --- a/ci/.shellcheckrc +++ b/ci/.shellcheckrc @@ -1,3 +1,7 @@ +# Disable the "variable appears unused" warning caused by the use of getopts +# with an obligatory (but unused) variable name in the main function. +disable=SC2034 + # Disable all the "quote to prevent globbing or word splitting" advice. # We need word splitting for well-known variables like MAKEFLAGS and CFLAGS. disable=SC2086,SC2206 diff --git a/ci/ci_lint_ci.sh b/ci/ci_lint_ci.sh index fa45c5473..13a9d21d6 100755 --- a/ci/ci_lint_ci.sh +++ b/ci/ci_lint_ci.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -e -# Copyright (c) 2019-2023 Cosmin Truta. +# Copyright (c) 2019-2024 Cosmin Truta. # # Use, modification and distribution are subject # to the Boost Software License, Version 1.0. @@ -58,11 +58,22 @@ function ci_lint_ci_scripts_license { } } +function usage { + echo "usage: $CI_SCRIPT_NAME" + exit 0 +} + function main { - [[ $# -eq 0 ]] || { - ci_info "usage: $CI_SCRIPT_NAME" - ci_err "unexpected command argument: '$1'" - } + local opt + while getopts ":" opt + do + # This ain't a while-loop. It only pretends to be. + [[ $1 == -[?h]* || $1 == --help ]] && usage + ci_err "unknown option: '$1'" + done + shift $((OPTIND - 1)) + # And... go! + [[ $# -eq 0 ]] || ci_err "unexpected argument: '$1'" ci_lint_ci_config_files ci_lint_ci_scripts ci_lint_ci_scripts_license diff --git a/ci/ci_verify_cmake.sh b/ci/ci_verify_cmake.sh index b46e9c6bf..06c46a0ba 100755 --- a/ci/ci_verify_cmake.sh +++ b/ci/ci_verify_cmake.sh @@ -169,12 +169,25 @@ function ci_build { ci_info "## END OF BUILD ##" } +function usage { + echo "usage: $CI_SCRIPT_NAME" + exit 0 +} + function main { + local opt + while getopts ":" opt + do + # This ain't a while-loop. It only pretends to be. + [[ $1 == -[?h]* || $1 == --help ]] && usage + ci_err "unknown option: '$1'" + done + shift $((OPTIND - 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_info "note: this program accepts environment options only" + ci_err "unexpected argument: '$1'" } ci_cleanup_old_build ci_build diff --git a/ci/ci_verify_configure.sh b/ci/ci_verify_configure.sh index fa7e82e65..94abda794 100755 --- a/ci/ci_verify_configure.sh +++ b/ci/ci_verify_configure.sh @@ -122,12 +122,26 @@ function ci_build { ci_info "## END OF BUILD ##" } +function usage { + echo "usage: $CI_SCRIPT_NAME" + exit 0 +} + function main { + local opt + while getopts ":" opt + do + # This ain't a while-loop. It only pretends to be. + [[ $1 == -[?h]* || $1 == --help ]] && usage + ci_err "unknown option: '$1'" + done + shift $((OPTIND - 1)) + # And... go! 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_info "note: this program accepts environment options only" + ci_err "unexpected argument: '$1'" } ci_cleanup_old_build ci_build diff --git a/ci/ci_verify_makefiles.sh b/ci/ci_verify_makefiles.sh index 79b97a383..95a64bb21 100755 --- a/ci/ci_verify_makefiles.sh +++ b/ci/ci_verify_makefiles.sh @@ -137,12 +137,26 @@ function ci_build { ci_info "## END OF BUILD ##" } +function usage { + echo "usage: $CI_SCRIPT_NAME" + exit 0 +} + function main { + local opt + while getopts ":" opt + do + # This ain't a while-loop. It only pretends to be. + [[ $1 == -[?h]* || $1 == --help ]] && usage + ci_err "unknown option: '$1'" + done + shift $((OPTIND - 1)) + # And... go! 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_info "note: this program accepts environment options only" + ci_err "unexpected argument: '$1'" } ci_cleanup_old_build ci_build diff --git a/ci/lib/ci.lib.sh b/ci/lib/ci.lib.sh index fc3e1b653..8700f3161 100644 --- a/ci/lib/ci.lib.sh +++ b/ci/lib/ci.lib.sh @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2023 Cosmin Truta. +# Copyright (c) 2019-2024 Cosmin Truta. # # Use, modification and distribution are subject # to the Boost Software License, Version 1.0. @@ -73,7 +73,7 @@ function ci_spawn { "$@" } -# Ensure that the initialization is correct. +# Ensure that the internal initialization is correct. [[ $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 ]] || @@ -82,3 +82,11 @@ function ci_spawn { 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" + +# Ensure that the user initialization is correct. +[[ ${CI_NO_TEST:-0} == [01] ]] || + ci_err "bad boolean option: \$CI_NO_TEST: '$CI_NO_TEST'" +[[ ${CI_NO_INSTALL:-0} == [01] ]] || + ci_err "bad boolean option: \$CI_NO_INSTALL: '$CI_NO_INSTALL'" +[[ ${CI_NO_CLEAN:-0} == [01] ]] || + ci_err "bad boolean option: \$CI_NO_CLEAN: '$CI_NO_CLEAN'"