diff --git a/ci/ci_verify_cmake.sh b/ci/ci_verify_cmake.sh index e3fd529dc..9fe634026 100755 --- a/ci/ci_verify_cmake.sh +++ b/ci/ci_verify_cmake.sh @@ -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'" diff --git a/ci/ci_verify_configure.sh b/ci/ci_verify_configure.sh index d73e80c26..141c7a283 100755 --- a/ci/ci_verify_configure.sh +++ b/ci/ci_verify_configure.sh @@ -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 ##" } diff --git a/ci/ci_verify_makefiles.sh b/ci/ci_verify_makefiles.sh index 5b9217ad2..e0681b4d8 100755 --- a/ci/ci_verify_makefiles.sh +++ b/ci/ci_verify_makefiles.sh @@ -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 { diff --git a/ci/lib/ci.lib.sh b/ci/lib/ci.lib.sh index 813cc09c5..03e866b5c 100644 --- a/ci/lib/ci.lib.sh +++ b/ci/lib/ci.lib.sh @@ -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'" }