From 8120345c890a94c81966238494f5c082d952280e Mon Sep 17 00:00:00 2001 From: Cosmin Truta Date: Sun, 11 Feb 2024 15:24:03 +0200 Subject: [PATCH] ci: Update (again) the ci_verify_*.sh scripts; update .shellcheckrc Apply stylistic improvements and remove a shellcheck exclusion. --- ci/.shellcheckrc | 4 -- ci/ci_verify_cmake.sh | 74 ++++++++++++++++++-------------- ci/ci_verify_configure.sh | 4 +- ci/ci_verify_makefiles.sh | 90 +++++++++++++++++++++++---------------- ci/ci_verify_version.sh | 6 +-- 5 files changed, 99 insertions(+), 79 deletions(-) diff --git a/ci/.shellcheckrc b/ci/.shellcheckrc index 051d55155..3c035d60c 100644 --- a/ci/.shellcheckrc +++ b/ci/.shellcheckrc @@ -9,7 +9,3 @@ 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 - -# Disable the "possible misspelling" warnings that might be flagged, e.g., -# inside function ci_trace_build. -disable=SC2153 diff --git a/ci/ci_verify_cmake.sh b/ci/ci_verify_cmake.sh index 05f140227..0985d5f84 100755 --- a/ci/ci_verify_cmake.sh +++ b/ci/ci_verify_cmake.sh @@ -97,40 +97,23 @@ function ci_cleanup_old_build { function ci_build { ci_info "## START OF BUILD ##" - ci_spawn "$(command -v "$CI_CMAKE")" --version - ci_spawn "$(command -v "$CI_CTEST")" --version + # Adjust the CI environment variables, as needed. + CI_CMAKE="$(command -v "$CI_CMAKE")" || ci_err "bad or missing \$CI_CMAKE" + ci_spawn "$CI_CMAKE" --version + CI_CTEST="$(command -v "$CI_CTEST")" || ci_err "bad or missing \$CI_CTEST" + ci_spawn "$CI_CTEST" --version [[ $CI_CMAKE_GENERATOR == *"Ninja"* ]] && { - ci_spawn "$(command -v ninja)" --version - } - # Initialize ALL_CC_FLAGS as a string. - local ALL_CC_FLAGS="$CI_CC_FLAGS" - [[ $CI_SANITIZERS ]] && { - ALL_CC_FLAGS="-fsanitize=$CI_SANITIZERS $ALL_CC_FLAGS" - } - # Initialize ALL_CMAKE_VARS, ALL_CMAKE_BUILD_FLAGS and ALL_CTEST_FLAGS as arrays. - local ALL_CMAKE_VARS=() - [[ $CI_CMAKE_TOOLCHAIN_FILE ]] && { - ALL_CMAKE_VARS+=(-DCMAKE_TOOLCHAIN_FILE="$CI_CMAKE_TOOLCHAIN_FILE") - } - [[ $CI_CC ]] && { - ALL_CMAKE_VARS+=(-DCMAKE_C_COMPILER="$CI_CC") - } - [[ $ALL_CC_FLAGS ]] && { - ALL_CMAKE_VARS+=(-DCMAKE_C_FLAGS="$ALL_CC_FLAGS") + CI_NINJA="$(command -v ninja)" || ci_err "bad or missing ninja, no pun intended" + ci_spawn "$CI_NINJA" --version } [[ $CI_AR ]] && { - # Use the full path of CI_AR to work around a CMake error. - ALL_CMAKE_VARS+=(-DCMAKE_AR="$(command -v "$CI_AR")") + # Use the full path of CI_AR to work around a mysterious CMake error. + CI_AR="$(command -v "$CI_AR")" || ci_err "bad or missing \$CI_AR" } [[ $CI_RANLIB ]] && { - # Use the full path of CI_RANLIB to work around a CMake error. - ALL_CMAKE_VARS+=(-DCMAKE_RANLIB="$(command -v "$CI_RANLIB")") + # Use the full path of CI_RANLIB to work around a mysterious CMake error. + CI_RANLIB="$(command -v "$CI_RANLIB")" || ci_err "bad or missing \$CI_RANLIB" } - ALL_CMAKE_VARS+=(-DCMAKE_BUILD_TYPE="$CI_CMAKE_BUILD_TYPE") - ALL_CMAKE_VARS+=(-DCMAKE_VERBOSE_MAKEFILE=ON) - ALL_CMAKE_VARS+=($CI_CMAKE_VARS) - local ALL_CMAKE_BUILD_FLAGS=($CI_CMAKE_BUILD_FLAGS) - local ALL_CTEST_FLAGS=($CI_CTEST_FLAGS) # Export the CMake environment variables. [[ $CI_CMAKE_GENERATOR ]] && { ci_spawn export CMAKE_GENERATOR="$CI_CMAKE_GENERATOR" @@ -138,6 +121,31 @@ function ci_build { [[ $CI_CMAKE_GENERATOR_PLATFORM ]] && { ci_spawn export CMAKE_GENERATOR_PLATFORM="$CI_CMAKE_GENERATOR_PLATFORM" } + # Initialize and populate the local arrays. + local all_cmake_vars=() + local all_cmake_build_flags=() + local all_ctest_flags=() + [[ $CI_CMAKE_TOOLCHAIN_FILE ]] && { + all_cmake_vars+=(-DCMAKE_TOOLCHAIN_FILE="$CI_CMAKE_TOOLCHAIN_FILE") + } + [[ $CI_CC ]] && { + all_cmake_vars+=(-DCMAKE_C_COMPILER="$CI_CC") + } + [[ $CI_CC_FLAGS || $CI_SANITIZERS ]] && { + [[ $CI_SANITIZERS ]] && CI_CC_FLAGS+="${CI_CC_FLAGS:+" "}-fsanitize=$CI_SANITIZERS" + all_cmake_vars+=(-DCMAKE_C_FLAGS="$CI_CC_FLAGS") + } + [[ $CI_AR ]] && { + all_cmake_vars+=(-DCMAKE_AR="$CI_AR") + } + [[ $CI_RANLIB ]] && { + all_cmake_vars+=(-DCMAKE_RANLIB="$CI_RANLIB") + } + all_cmake_vars+=(-DCMAKE_BUILD_TYPE="$CI_CMAKE_BUILD_TYPE") + all_cmake_vars+=(-DCMAKE_VERBOSE_MAKEFILE=ON) + all_cmake_vars+=($CI_CMAKE_VARS) + all_cmake_build_flags+=($CI_CMAKE_BUILD_FLAGS) + all_ctest_flags+=($CI_CTEST_FLAGS) # And... build! # Use $CI_BUILD_TO_SRC_RELDIR and $CI_BUILD_TO_INSTALL_RELDIR # instead of $CI_SRC_DIR and $CI_INSTALL_DIR from this point onwards. @@ -152,30 +160,30 @@ function ci_build { } # Spawn "cmake ...". ci_spawn "$CI_CMAKE" -DCMAKE_INSTALL_PREFIX="$CI_BUILD_TO_INSTALL_RELDIR" \ - "${ALL_CMAKE_VARS[@]}" \ + "${all_cmake_vars[@]}" \ "$CI_BUILD_TO_SRC_RELDIR" # Spawn "cmake --build ...". ci_spawn "$CI_CMAKE" --build . \ --config "$CI_CMAKE_BUILD_TYPE" \ - "${ALL_CMAKE_BUILD_FLAGS[@]}" + "${all_cmake_build_flags[@]}" ci_expr $((CI_NO_TEST)) || { # Spawn "ctest" if testing is not disabled. ci_spawn "$CI_CTEST" --build-config "$CI_CMAKE_BUILD_TYPE" \ - "${ALL_CTEST_FLAGS[@]}" + "${all_ctest_flags[@]}" } 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 \ - "${ALL_CMAKE_BUILD_FLAGS[@]}" + "${all_cmake_build_flags[@]}" } 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 \ - "${ALL_CMAKE_BUILD_FLAGS[@]}" + "${all_cmake_build_flags[@]}" } ci_info "## END OF BUILD ##" } diff --git a/ci/ci_verify_configure.sh b/ci/ci_verify_configure.sh index 8d124dea3..0a2bd807a 100755 --- a/ci/ci_verify_configure.sh +++ b/ci/ci_verify_configure.sh @@ -107,8 +107,8 @@ function ci_build { [[ $CI_LD ]] && ci_spawn export LD="$CI_LD" [[ $CI_LD_FLAGS ]] && ci_spawn export LDFLAGS="$CI_LD_FLAGS" [[ $CI_SANITIZERS ]] && { - ci_spawn export CFLAGS="-fsanitize=$CI_SANITIZERS ${CFLAGS:-"-O2"}" - ci_spawn export LDFLAGS="-fsanitize=$CI_SANITIZERS $LDFLAGS" + ci_spawn export CFLAGS="${CFLAGS:-"-O2"} -fsanitize=$CI_SANITIZERS" + ci_spawn export LDFLAGS="${LDFLAGS}${LDFLAGS:+" "}-fsanitize=$CI_SANITIZERS" } # And... build! ci_spawn mkdir -p "$CI_BUILD_DIR" diff --git a/ci/ci_verify_makefiles.sh b/ci/ci_verify_makefiles.sh index 9667d5366..97369baa9 100755 --- a/ci/ci_verify_makefiles.sh +++ b/ci/ci_verify_makefiles.sh @@ -79,61 +79,77 @@ function ci_cleanup_old_build { # Fortunately, for a clean makefiles-based build, it should be # sufficient to remove the old object files only. ci_info "## START OF PRE-BUILD CLEANUP ##" - local MY_FILE + local my_file find "$CI_SRC_DIR" -maxdepth 1 \( -iname "*.o" -o -iname "*.obj" \) | - while IFS="" read -r MY_FILE + while IFS="" read -r my_file do - ci_spawn rm -fr "$MY_FILE" + ci_spawn rm -fr "$my_file" done ci_info "## END OF PRE-BUILD CLEANUP ##" } function ci_build { ci_info "## START OF BUILD ##" - # Initialize ALL_CC_FLAGS and ALL_LD_FLAGS as strings. - local ALL_CC_FLAGS="$CI_CC_FLAGS" - local ALL_LD_FLAGS="$CI_LD_FLAGS" - [[ $CI_SANITIZERS ]] && { - ALL_CC_FLAGS="-fsanitize=$CI_SANITIZERS ${ALL_CC_FLAGS:-"-O2"}" - ALL_LD_FLAGS="-fsanitize=$CI_SANITIZERS $ALL_LD_FLAGS" + # Initialize and populate the local arrays. + local all_make_flags=() + local all_make_vars=() + [[ $CI_MAKE_FLAGS ]] && { + all_make_flags+=($CI_MAKE_FLAGS) } - # Initialize ALL_MAKE_FLAGS and ALL_MAKE_VARS as arrays. - local ALL_MAKE_FLAGS=($CI_MAKE_FLAGS) - local ALL_MAKE_VARS=() - [[ $CI_CC ]] && ALL_MAKE_VARS+=(CC="$CI_CC") - [[ $ALL_CC_FLAGS ]] && ALL_MAKE_VARS+=(CFLAGS="$ALL_CC_FLAGS") - [[ $CI_CPP ]] && ALL_MAKE_VARS+=(CPP="$CI_CPP") - [[ $CI_CPP_FLAGS ]] && ALL_MAKE_VARS+=(CPPFLAGS="$CI_CPP_FLAGS") - [[ $CI_AR ]] && ALL_MAKE_VARS+=( - AR="${CI_AR:-ar}" - AR_RC="${CI_AR:-ar} rc" - ) - [[ $CI_RANLIB ]] && ALL_MAKE_VARS+=(RANLIB="$CI_RANLIB") - [[ $CI_LD ]] && ALL_MAKE_VARS+=(LD="$CI_LD") - [[ $ALL_LD_FLAGS ]] && ALL_MAKE_VARS+=(LDFLAGS="$ALL_LD_FLAGS") - [[ $CI_LIBS ]] && ALL_MAKE_VARS+=(LIBS="$CI_LIBS") - ALL_MAKE_VARS+=($CI_MAKE_VARS) + [[ $CI_CC ]] && { + all_make_vars+=(CC="$CI_CC") + } + [[ $CI_CC_FLAGS || $CI_SANITIZERS ]] && { + [[ $CI_SANITIZERS ]] && CI_CC_FLAGS="${CI_CC_FLAGS:-"-O2"} -fsanitize=$CI_SANITIZERS" + all_make_vars+=(CFLAGS="$CI_CC_FLAGS") + } + [[ $CI_CPP ]] && { + all_make_vars+=(CPP="$CI_CPP") + } + [[ $CI_CPP_FLAGS ]] && { + all_make_vars+=(CPPFLAGS="$CI_CPP_FLAGS") + } + [[ $CI_AR ]] && { + all_make_vars+=( + AR="${CI_AR:-ar}" + AR_RC="${CI_AR:-ar} rc" + ) + } + [[ $CI_RANLIB ]] && { + all_make_vars+=(RANLIB="$CI_RANLIB") + } + [[ $CI_LD ]] && { + all_make_vars+=(LD="$CI_LD") + } + [[ $CI_LD_FLAGS || $CI_SANITIZERS ]] && { + [[ $CI_SANITIZERS ]] && CI_LD_FLAGS+="${CI_LD_FLAGS:+" "}-fsanitize=$CI_SANITIZERS" + all_make_vars+=(LDFLAGS="$CI_LD_FLAGS") + } + [[ $CI_LIBS ]] && { + all_make_vars+=(LIBS="$CI_LIBS") + } + all_make_vars+=($CI_MAKE_VARS) # And... build! - local MY_MAKEFILE - for MY_MAKEFILE in $CI_MAKEFILES + local my_makefile + for my_makefile in $CI_MAKEFILES do - ci_info "using makefile: $MY_MAKEFILE" + ci_info "using makefile: $my_makefile" # Spawn "make". - ci_spawn "$CI_MAKE" -f "$MY_MAKEFILE" \ - "${ALL_MAKE_FLAGS[@]}" \ - "${ALL_MAKE_VARS[@]}" + ci_spawn "$CI_MAKE" -f "$my_makefile" \ + "${all_make_flags[@]}" \ + "${all_make_vars[@]}" 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[@]}" \ + ci_spawn "$CI_MAKE" -f "$my_makefile" \ + "${all_make_flags[@]}" \ + "${all_make_vars[@]}" \ test } ci_expr $((CI_NO_CLEAN)) || { # Spawn "make clean" if cleaning is not disabled. - ci_spawn "$CI_MAKE" -f "$MY_MAKEFILE" \ - "${ALL_MAKE_FLAGS[@]}" \ - "${ALL_MAKE_VARS[@]}" \ + ci_spawn "$CI_MAKE" -f "$my_makefile" \ + "${all_make_flags[@]}" \ + "${all_make_vars[@]}" \ clean } done diff --git a/ci/ci_verify_version.sh b/ci/ci_verify_version.sh index 0a0f877f0..8199d7935 100755 --- a/ci/ci_verify_version.sh +++ b/ci/ci_verify_version.sh @@ -20,7 +20,10 @@ function ci_init_shellify { function ci_run_shellify { ci_info "shellifying:" "$@" + local my_result "$BASH" "$CI_SCRIPT_DIR/ci_shellify.sh" "$@" + echo "$my_result" | "$BASH" --posix || ci_err "bad shellify output" + echo "$my_result" } function ci_verify_version { @@ -29,13 +32,10 @@ function ci_verify_version { ci_init_shellify my_env_libpng_ver="$(ci_run_shellify png.h)" echo "$my_env_libpng_ver" - echo "$my_env_libpng_ver" | "$BASH" --posix || ci_err "bad shellify output" my_env_autoconf_ver="$(ci_run_shellify configure.ac)" echo "$my_env_autoconf_ver" - echo "$my_env_autoconf_ver" | "$BASH" --posix || ci_err "bad shellify output" my_env_cmake_ver="$(ci_run_shellify CMakeLists.txt)" echo "$my_env_cmake_ver" - echo "$my_env_cmake_ver" | "$BASH" --posix || ci_err "bad shellify output" ci_info "## VERIFYING: png.h version definitions ##" eval "$my_env_libpng_ver" local my_expect="${PNG_LIBPNG_VER_MAJOR}.${PNG_LIBPNG_VER_MINOR}.${PNG_LIBPNG_VER_RELEASE}"