ci: Update (again) the ci_verify_*.sh scripts; update .shellcheckrc

Apply stylistic improvements and remove a shellcheck exclusion.
This commit is contained in:
Cosmin Truta 2024-02-11 15:24:03 +02:00
parent 7a6148290f
commit 8120345c89
5 changed files with 99 additions and 79 deletions

View File

@ -9,7 +9,3 @@ disable=SC2034
# Disable all the "quote to prevent globbing or word splitting" advice. # Disable all the "quote to prevent globbing or word splitting" advice.
# We need word splitting for well-known variables like MAKEFLAGS and CFLAGS. # We need word splitting for well-known variables like MAKEFLAGS and CFLAGS.
disable=SC2086,SC2206 disable=SC2086,SC2206
# Disable the "possible misspelling" warnings that might be flagged, e.g.,
# inside function ci_trace_build.
disable=SC2153

View File

@ -97,40 +97,23 @@ function ci_cleanup_old_build {
function ci_build { function ci_build {
ci_info "## START OF BUILD ##" ci_info "## START OF BUILD ##"
ci_spawn "$(command -v "$CI_CMAKE")" --version # Adjust the CI environment variables, as needed.
ci_spawn "$(command -v "$CI_CTEST")" --version 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_CMAKE_GENERATOR == *"Ninja"* ]] && {
ci_spawn "$(command -v ninja)" --version CI_NINJA="$(command -v ninja)" || ci_err "bad or missing ninja, no pun intended"
} ci_spawn "$CI_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_AR ]] && { [[ $CI_AR ]] && {
# Use the full path of CI_AR to work around a CMake error. # Use the full path of CI_AR to work around a mysterious CMake error.
ALL_CMAKE_VARS+=(-DCMAKE_AR="$(command -v "$CI_AR")") CI_AR="$(command -v "$CI_AR")" || ci_err "bad or missing \$CI_AR"
} }
[[ $CI_RANLIB ]] && { [[ $CI_RANLIB ]] && {
# Use the full path of CI_RANLIB to work around a CMake error. # Use the full path of CI_RANLIB to work around a mysterious CMake error.
ALL_CMAKE_VARS+=(-DCMAKE_RANLIB="$(command -v "$CI_RANLIB")") 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. # Export the CMake environment variables.
[[ $CI_CMAKE_GENERATOR ]] && { [[ $CI_CMAKE_GENERATOR ]] && {
ci_spawn export CMAKE_GENERATOR="$CI_CMAKE_GENERATOR" ci_spawn export CMAKE_GENERATOR="$CI_CMAKE_GENERATOR"
@ -138,6 +121,31 @@ function ci_build {
[[ $CI_CMAKE_GENERATOR_PLATFORM ]] && { [[ $CI_CMAKE_GENERATOR_PLATFORM ]] && {
ci_spawn export CMAKE_GENERATOR_PLATFORM="$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! # And... build!
# Use $CI_BUILD_TO_SRC_RELDIR and $CI_BUILD_TO_INSTALL_RELDIR # 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. # instead of $CI_SRC_DIR and $CI_INSTALL_DIR from this point onwards.
@ -152,30 +160,30 @@ function ci_build {
} }
# Spawn "cmake ...". # Spawn "cmake ...".
ci_spawn "$CI_CMAKE" -DCMAKE_INSTALL_PREFIX="$CI_BUILD_TO_INSTALL_RELDIR" \ ci_spawn "$CI_CMAKE" -DCMAKE_INSTALL_PREFIX="$CI_BUILD_TO_INSTALL_RELDIR" \
"${ALL_CMAKE_VARS[@]}" \ "${all_cmake_vars[@]}" \
"$CI_BUILD_TO_SRC_RELDIR" "$CI_BUILD_TO_SRC_RELDIR"
# Spawn "cmake --build ...". # Spawn "cmake --build ...".
ci_spawn "$CI_CMAKE" --build . \ ci_spawn "$CI_CMAKE" --build . \
--config "$CI_CMAKE_BUILD_TYPE" \ --config "$CI_CMAKE_BUILD_TYPE" \
"${ALL_CMAKE_BUILD_FLAGS[@]}" "${all_cmake_build_flags[@]}"
ci_expr $((CI_NO_TEST)) || { ci_expr $((CI_NO_TEST)) || {
# Spawn "ctest" if testing is not disabled. # 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[@]}" "${all_ctest_flags[@]}"
} }
ci_expr $((CI_NO_INSTALL)) || { ci_expr $((CI_NO_INSTALL)) || {
# Spawn "cmake --build ... --target install" if installation is not disabled. # Spawn "cmake --build ... --target install" if installation is not disabled.
ci_spawn "$CI_CMAKE" --build . \ ci_spawn "$CI_CMAKE" --build . \
--config "$CI_CMAKE_BUILD_TYPE" \ --config "$CI_CMAKE_BUILD_TYPE" \
--target install \ --target install \
"${ALL_CMAKE_BUILD_FLAGS[@]}" "${all_cmake_build_flags[@]}"
} }
ci_expr $((CI_NO_CLEAN)) || { ci_expr $((CI_NO_CLEAN)) || {
# Spawn "make --build ... --target clean" if cleaning is not disabled. # Spawn "make --build ... --target clean" if cleaning is not disabled.
ci_spawn "$CI_CMAKE" --build . \ ci_spawn "$CI_CMAKE" --build . \
--config "$CI_CMAKE_BUILD_TYPE" \ --config "$CI_CMAKE_BUILD_TYPE" \
--target clean \ --target clean \
"${ALL_CMAKE_BUILD_FLAGS[@]}" "${all_cmake_build_flags[@]}"
} }
ci_info "## END OF BUILD ##" ci_info "## END OF BUILD ##"
} }

View File

@ -107,8 +107,8 @@ function ci_build {
[[ $CI_LD ]] && ci_spawn export LD="$CI_LD" [[ $CI_LD ]] && ci_spawn export LD="$CI_LD"
[[ $CI_LD_FLAGS ]] && ci_spawn export LDFLAGS="$CI_LD_FLAGS" [[ $CI_LD_FLAGS ]] && ci_spawn export LDFLAGS="$CI_LD_FLAGS"
[[ $CI_SANITIZERS ]] && { [[ $CI_SANITIZERS ]] && {
ci_spawn export CFLAGS="-fsanitize=$CI_SANITIZERS ${CFLAGS:-"-O2"}" ci_spawn export CFLAGS="${CFLAGS:-"-O2"} -fsanitize=$CI_SANITIZERS"
ci_spawn export LDFLAGS="-fsanitize=$CI_SANITIZERS $LDFLAGS" ci_spawn export LDFLAGS="${LDFLAGS}${LDFLAGS:+" "}-fsanitize=$CI_SANITIZERS"
} }
# And... build! # And... build!
ci_spawn mkdir -p "$CI_BUILD_DIR" ci_spawn mkdir -p "$CI_BUILD_DIR"

View File

@ -79,61 +79,77 @@ function ci_cleanup_old_build {
# Fortunately, for a clean makefiles-based build, it should be # Fortunately, for a clean makefiles-based build, it should be
# sufficient to remove the old object files only. # sufficient to remove the old object files only.
ci_info "## START OF PRE-BUILD CLEANUP ##" ci_info "## START OF PRE-BUILD CLEANUP ##"
local MY_FILE local my_file
find "$CI_SRC_DIR" -maxdepth 1 \( -iname "*.o" -o -iname "*.obj" \) | find "$CI_SRC_DIR" -maxdepth 1 \( -iname "*.o" -o -iname "*.obj" \) |
while IFS="" read -r MY_FILE while IFS="" read -r my_file
do do
ci_spawn rm -fr "$MY_FILE" ci_spawn rm -fr "$my_file"
done done
ci_info "## END OF PRE-BUILD CLEANUP ##" ci_info "## END OF PRE-BUILD CLEANUP ##"
} }
function ci_build { function ci_build {
ci_info "## START OF BUILD ##" ci_info "## START OF BUILD ##"
# Initialize ALL_CC_FLAGS and ALL_LD_FLAGS as strings. # Initialize and populate the local arrays.
local ALL_CC_FLAGS="$CI_CC_FLAGS" local all_make_flags=()
local ALL_LD_FLAGS="$CI_LD_FLAGS" local all_make_vars=()
[[ $CI_SANITIZERS ]] && { [[ $CI_MAKE_FLAGS ]] && {
ALL_CC_FLAGS="-fsanitize=$CI_SANITIZERS ${ALL_CC_FLAGS:-"-O2"}" all_make_flags+=($CI_MAKE_FLAGS)
ALL_LD_FLAGS="-fsanitize=$CI_SANITIZERS $ALL_LD_FLAGS"
} }
# Initialize ALL_MAKE_FLAGS and ALL_MAKE_VARS as arrays. [[ $CI_CC ]] && {
local ALL_MAKE_FLAGS=($CI_MAKE_FLAGS) all_make_vars+=(CC="$CI_CC")
local ALL_MAKE_VARS=() }
[[ $CI_CC ]] && ALL_MAKE_VARS+=(CC="$CI_CC") [[ $CI_CC_FLAGS || $CI_SANITIZERS ]] && {
[[ $ALL_CC_FLAGS ]] && ALL_MAKE_VARS+=(CFLAGS="$ALL_CC_FLAGS") [[ $CI_SANITIZERS ]] && CI_CC_FLAGS="${CI_CC_FLAGS:-"-O2"} -fsanitize=$CI_SANITIZERS"
[[ $CI_CPP ]] && ALL_MAKE_VARS+=(CPP="$CI_CPP") all_make_vars+=(CFLAGS="$CI_CC_FLAGS")
[[ $CI_CPP_FLAGS ]] && ALL_MAKE_VARS+=(CPPFLAGS="$CI_CPP_FLAGS") }
[[ $CI_AR ]] && ALL_MAKE_VARS+=( [[ $CI_CPP ]] && {
AR="${CI_AR:-ar}" all_make_vars+=(CPP="$CI_CPP")
AR_RC="${CI_AR:-ar} rc" }
) [[ $CI_CPP_FLAGS ]] && {
[[ $CI_RANLIB ]] && ALL_MAKE_VARS+=(RANLIB="$CI_RANLIB") all_make_vars+=(CPPFLAGS="$CI_CPP_FLAGS")
[[ $CI_LD ]] && ALL_MAKE_VARS+=(LD="$CI_LD") }
[[ $ALL_LD_FLAGS ]] && ALL_MAKE_VARS+=(LDFLAGS="$ALL_LD_FLAGS") [[ $CI_AR ]] && {
[[ $CI_LIBS ]] && ALL_MAKE_VARS+=(LIBS="$CI_LIBS") all_make_vars+=(
ALL_MAKE_VARS+=($CI_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! # And... build!
local MY_MAKEFILE local my_makefile
for MY_MAKEFILE in $CI_MAKEFILES for my_makefile in $CI_MAKEFILES
do do
ci_info "using makefile: $MY_MAKEFILE" ci_info "using makefile: $my_makefile"
# Spawn "make". # Spawn "make".
ci_spawn "$CI_MAKE" -f "$MY_MAKEFILE" \ ci_spawn "$CI_MAKE" -f "$my_makefile" \
"${ALL_MAKE_FLAGS[@]}" \ "${all_make_flags[@]}" \
"${ALL_MAKE_VARS[@]}" "${all_make_vars[@]}"
ci_expr $((CI_NO_TEST)) || { ci_expr $((CI_NO_TEST)) || {
# Spawn "make test" if testing is not disabled. # Spawn "make test" if testing is not disabled.
ci_spawn "$CI_MAKE" -f "$MY_MAKEFILE" \ ci_spawn "$CI_MAKE" -f "$my_makefile" \
"${ALL_MAKE_FLAGS[@]}" \ "${all_make_flags[@]}" \
"${ALL_MAKE_VARS[@]}" \ "${all_make_vars[@]}" \
test test
} }
ci_expr $((CI_NO_CLEAN)) || { ci_expr $((CI_NO_CLEAN)) || {
# Spawn "make clean" if cleaning is not disabled. # Spawn "make clean" if cleaning is not disabled.
ci_spawn "$CI_MAKE" -f "$MY_MAKEFILE" \ ci_spawn "$CI_MAKE" -f "$my_makefile" \
"${ALL_MAKE_FLAGS[@]}" \ "${all_make_flags[@]}" \
"${ALL_MAKE_VARS[@]}" \ "${all_make_vars[@]}" \
clean clean
} }
done done

View File

@ -20,7 +20,10 @@ function ci_init_shellify {
function ci_run_shellify { function ci_run_shellify {
ci_info "shellifying:" "$@" ci_info "shellifying:" "$@"
local my_result
"$BASH" "$CI_SCRIPT_DIR/ci_shellify.sh" "$@" "$BASH" "$CI_SCRIPT_DIR/ci_shellify.sh" "$@"
echo "$my_result" | "$BASH" --posix || ci_err "bad shellify output"
echo "$my_result"
} }
function ci_verify_version { function ci_verify_version {
@ -29,13 +32,10 @@ function ci_verify_version {
ci_init_shellify ci_init_shellify
my_env_libpng_ver="$(ci_run_shellify png.h)" my_env_libpng_ver="$(ci_run_shellify png.h)"
echo "$my_env_libpng_ver" 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)" my_env_autoconf_ver="$(ci_run_shellify configure.ac)"
echo "$my_env_autoconf_ver" 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)" my_env_cmake_ver="$(ci_run_shellify CMakeLists.txt)"
echo "$my_env_cmake_ver" echo "$my_env_cmake_ver"
echo "$my_env_cmake_ver" | "$BASH" --posix || ci_err "bad shellify output"
ci_info "## VERIFYING: png.h version definitions ##" ci_info "## VERIFYING: png.h version definitions ##"
eval "$my_env_libpng_ver" eval "$my_env_libpng_ver"
local my_expect="${PNG_LIBPNG_VER_MAJOR}.${PNG_LIBPNG_VER_MINOR}.${PNG_LIBPNG_VER_RELEASE}" local my_expect="${PNG_LIBPNG_VER_MAJOR}.${PNG_LIBPNG_VER_MINOR}.${PNG_LIBPNG_VER_RELEASE}"