From 568f53a9d8734f8dc28f2a9c8fe86ef5267df0af Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Mon, 12 Jul 2021 18:16:01 +0200 Subject: [PATCH] Don't unconditionally restore **/Makefile all.sh restores **/Makefile from git in case the version in the worktree was from doing a cmake in-tree build. Instead of doing this unconditionally, do it only if the toplevel Makefile seems to have been automatically generated (by cmake or otherwise, e.g. by mbedtls-prepare-build). This way all.sh no longer silently wipes changes made to Makefile but not committed yet. Signed-off-by: Gilles Peskine --- tests/scripts/all.sh | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 5c2ab2778d..7db9488eee 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -137,6 +137,8 @@ pre_initialize_variables () { backup_suffix='.all.bak' # Files clobbered by config.py files_to_back_up="$CONFIG_H $CRYPTO_CONFIG_H" + # Files clobbered by in-tree cmake + files_to_back_up="$files_to_back_up Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile" append_outcome=0 MEMORY=0 @@ -282,8 +284,6 @@ cleanup() -iname CMakeCache.txt \) -exec rm -f {} \+ # Recover files overwritten by in-tree CMake builds rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile - git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile - git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile # Remove any artifacts from the component_test_cmake_as_subdirectory test. rm -rf programs/test/cmake_subproject/build @@ -495,6 +495,20 @@ pre_check_git () { fi } +pre_restore_files () { + # If the makefiles have been generated by a framework such as cmake, + # restore them from git. If the makefiles look like modifications from + # the ones checked into git, take care not to modify them. Whatever + # this function leaves behind is what the script will restore before + # each component. + case "$(head -n1 Makefile)" in + *[Gg]enerated*) + git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile + git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile + ;; + esac +} + pre_back_up () { for x in $files_to_back_up; do cp -p "$x" "$x$backup_suffix" @@ -2762,6 +2776,7 @@ pre_initialize_variables pre_parse_command_line "$@" pre_check_git +pre_restore_files pre_back_up build_status=0