From c42774a1edf2d9404febd393cf8e2deb27793db3 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 10 Dec 2025 18:04:28 +0100 Subject: [PATCH 1/2] Only clean CMake artifacts in-tree Don't recurse into every subdirectory: that also removed files from out-of-tree builds that the user may have placed into subdirectories. With make as the build tool, the cleanup is mostly recoverable, but with ninja as the build tool, you have to manually run `cmake` again after running `all.sh`. Instead, look for things to clean only in directories managed by git. This also has the benefit of not touching `**/Makefile` if there hasn't been an in-tree CMake build. Fixes https://github.com/Mbed-TLS/mbedtls-framework/issues/252 Signed-off-by: Gilles Peskine --- scripts/all-core.sh | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/scripts/all-core.sh b/scripts/all-core.sh index a9070a8e20..208506aa4e 100644 --- a/scripts/all-core.sh +++ b/scripts/all-core.sh @@ -378,25 +378,24 @@ cleanup() command $MAKE_COMMAND clean fi - # Remove CMake artefacts - find . -name .git -prune -o \ - -iname CMakeFiles -exec rm -rf {} \+ -o \ - \( -iname cmake_install.cmake -o \ - -iname CTestTestfile.cmake -o \ - -iname CMakeCache.txt -o \ - -path './cmake/*.cmake' \) -exec rm -f {} \+ - # Remove Makefiles generated by in-tree CMake builds - # (Not all files will exist in all branches, but that's OK.) - rm -f 3rdparty/Makefile 3rdparty/*/Makefile - rm -f pkgconfig/Makefile framework/Makefile - rm -f include/Makefile programs/!(fuzz)/Makefile - rm -f tf-psa-crypto/Makefile tf-psa-crypto/include/Makefile - rm -f tf-psa-crypto/core/Makefile tf-psa-crypto/drivers/Makefile - rm -f tf-psa-crypto/tests/Makefile - rm -f tf-psa-crypto/drivers/everest/Makefile - rm -f tf-psa-crypto/drivers/p256-m/Makefile - rm -f tf-psa-crypto/drivers/builtin/Makefile - rm -f tf-psa-crypto/drivers/builtin/src/Makefile + # Remove files left over by an in-tree CMake build. + # Take care to only hit in-tree builds, not out-of-tree builds in + # subdirectories. + # Remove **/Makefile only if it looks like it was created by an in-tree + # CMake build. + local cmake_dirs=($(git ls-files --recurse-submodules \ + 'CMakeLists.txt' '**/CMakeLists.txt' | + sed -e 's![^/]*$!!')) + for d in "${cmake_dirs[@]}"; do + if [ -d "$d/CMakeFiles" ]; then + rm -rf "$d/CMakeFiles" \ + "$d/cmake_install.cmake" \ + "$d/CTestTestfile.cmake" \ + "$d/CMakeCache.txt" \ + "$d/Makefile" + rm -rf "$d/cmake"/*.cmake + fi + done # Remove any artifacts from the component_test_cmake_as_subdirectory test. rm -rf programs/test/cmake_subproject/build From f8c699713c8241ace9d84a65f55f696ea542994c Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 10 Dec 2025 20:05:07 +0100 Subject: [PATCH 2/2] CMake artifacts cleanup: fix the new code on Ubuntu 16.04 Signed-off-by: Gilles Peskine --- scripts/all-core.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/all-core.sh b/scripts/all-core.sh index 208506aa4e..903d09c9e7 100644 --- a/scripts/all-core.sh +++ b/scripts/all-core.sh @@ -369,6 +369,19 @@ Tool path options: EOF } +# list_git_files PATTERN... +# List files known to git, matching pattern. +# Equivalent to `git ls-files --recurse-submodules PATTERN...`, but +# works with older Git (especially on Ubuntu 16.04) that understand +# submodules but not `git ls-files --recurse-submodules`. +list_git_files () +{ + git ls-files -- "$@" + for d in $(git submodule status --recursive | awk '{print $2}'); do + git ls-files "$@" | sed "s!^!$d/!" + done +} + # Cleanup before/after running a component. # Remove built files as well as the cmake cache/config. # Does not remove generated source files. @@ -383,8 +396,7 @@ cleanup() # subdirectories. # Remove **/Makefile only if it looks like it was created by an in-tree # CMake build. - local cmake_dirs=($(git ls-files --recurse-submodules \ - 'CMakeLists.txt' '**/CMakeLists.txt' | + local cmake_dirs=($(list_git_files 'CMakeLists.txt' '**/CMakeLists.txt' | sed -e 's![^/]*$!!')) for d in "${cmake_dirs[@]}"; do if [ -d "$d/CMakeFiles" ]; then