ci: Allow the user to force an in-tree cleanup before verification

Introduce the environment option CI_FORCE:
 * ci_verify_configure.sh is known to fail if an existing build
   configuration is found in the top-level directory.
   Setting CI_FORCE=1 will run `make distclean` before verification.
 * ci_verify_makefiles.sh cannot be reliably executed if random
   object files are found in the top-level directory.
   Setting CI_FORCE=1 will run `rm *.o *.obj` before verification.
 * ci_verify_cmake.sh is not known at this time to fail for similar
   reasons; but if it does, we will use CI_FORCE to trigger any
   necessary pre-build cleanup.
This commit is contained in:
Cosmin Truta 2024-02-17 11:56:35 +02:00
parent 0fa3c0f698
commit 72c4520d3c
4 changed files with 44 additions and 14 deletions

View File

@ -69,6 +69,7 @@ function ci_trace_build {
ci_info "environment option: \$CI_AR: '$CI_AR'"
ci_info "environment option: \$CI_RANLIB: '$CI_RANLIB'"
ci_info "environment option: \$CI_SANITIZERS: '$CI_SANITIZERS'"
ci_info "environment option: \$CI_FORCE: '$CI_FORCE'"
ci_info "environment option: \$CI_NO_TEST: '$CI_NO_TEST'"
ci_info "environment option: \$CI_NO_INSTALL: '$CI_NO_INSTALL'"
ci_info "environment option: \$CI_NO_CLEAN: '$CI_NO_CLEAN'"

View File

@ -57,6 +57,7 @@ function ci_trace_build {
ci_info "environment option: \$CI_LD: '$CI_LD'"
ci_info "environment option: \$CI_LD_FLAGS: '$CI_LD_FLAGS'"
ci_info "environment option: \$CI_SANITIZERS: '$CI_SANITIZERS'"
ci_info "environment option: \$CI_FORCE: '$CI_FORCE'"
ci_info "environment option: \$CI_NO_TEST: '$CI_NO_TEST'"
ci_info "environment option: \$CI_NO_INSTALL: '$CI_NO_INSTALL'"
ci_info "environment option: \$CI_NO_CLEAN: '$CI_NO_CLEAN'"
@ -80,18 +81,29 @@ function ci_trace_build {
}
function ci_cleanup_old_build {
ci_info "## START OF PRE-BUILD CHECKUP ##"
ci_spawn test '!' -f "$CI_SRC_DIR/config.status" || {
# Warn the user, but do not delete their files.
ci_warn "unexpected build configuration file: '$CI_SRC_DIR/config.status'"
ci_warn "the configure script might fail"
}
ci_info "## END OF PRE-BUILD CHECKUP ##"
ci_info "## START OF PRE-BUILD CLEANUP ##"
[[ ! -e $CI_BUILD_DIR && ! -e $CI_INSTALL_DIR ]] || {
ci_spawn rm -fr "$CI_BUILD_DIR"
ci_spawn rm -fr "$CI_INSTALL_DIR"
}
[[ ! -e "$CI_SRC_DIR/config.status" ]] || {
ci_warn "unexpected build configuration file: '$CI_SRC_DIR/config.status'"
if ci_expr $((CI_FORCE))
then
# Delete the old config and (possibly) the old build.
ci_info "note: forcing an in-tree build cleanup"
if [[ -f $CI_SRC_DIR/Makefile ]]
then
ci_spawn make -C "$CI_SRC_DIR" distclean
else
ci_spawn rm -fr "$CI_SRC_DIR"/config.{log,status}
fi
else
# Alert the user, but do not delete their files.
ci_warn "the configure script might fail"
ci_info "hint: consider using the option \$CI_FORCE=1"
fi
}
ci_info "## END OF PRE-BUILD CLEANUP ##"
}

View File

@ -50,6 +50,7 @@ function ci_trace_build {
ci_info "environment option: \$CI_LD_FLAGS: '$CI_LD_FLAGS'"
ci_info "environment option: \$CI_LIBS: '$CI_LIBS'"
ci_info "environment option: \$CI_SANITIZERS: '$CI_SANITIZERS'"
ci_info "environment option: \$CI_FORCE: '$CI_FORCE'"
ci_info "environment option: \$CI_NO_TEST: '$CI_NO_TEST'"
ci_info "environment option: \$CI_NO_CLEAN: '$CI_NO_CLEAN'"
ci_info "executable: \$CI_MAKE: $(command -V "$CI_MAKE")"
@ -79,13 +80,26 @@ 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
find "$CI_SRC_DIR" -maxdepth 1 \( -iname "*.o" -o -iname "*.obj" \) |
while IFS="" read -r my_file
do
ci_spawn rm -fr "$my_file"
done
ci_info "## END OF PRE-BUILD CLEANUP ##"
local find_args=(-maxdepth 1 \( -iname "*.o" -o -iname "*.obj" \))
[[ ! $(find "$CI_SRC_DIR" "${find_args[@]}" | head -n1) ]] || {
ci_warn "unexpected build found in '$CI_SRC_DIR'"
if ci_expr $((CI_FORCE))
then
# Delete the old build.
local my_file
find "$CI_SRC_DIR" "${find_args[@]}" |
while IFS="" read -r my_file
do
ci_spawn rm -fr "$my_file"
done
ci_info "## END OF PRE-BUILD CLEANUP ##"
else
# Alert the user, but do not delete their existing files,
# and do not mess up their existing build.
ci_info "hint: consider using the option \$CI_FORCE=1"
ci_err "unable to continue"
fi
}
}
function ci_build {

View File

@ -88,6 +88,9 @@ function ci_spawn {
}
# Ensure that the user initialization is correct.
[[ ${CI_FORCE:-0} == [01] ]] || {
ci_err "bad boolean option: \$CI_FORCE: '$CI_FORCE'"
}
[[ ${CI_NO_TEST:-0} == [01] ]] || {
ci_err "bad boolean option: \$CI_NO_TEST: '$CI_NO_TEST'"
}