Skip to content

Commit c42774a

Browse files
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 #252 Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
1 parent 4d6e2cd commit c42774a

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

scripts/all-core.sh

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -378,25 +378,24 @@ cleanup()
378378
command $MAKE_COMMAND clean
379379
fi
380380
381-
# Remove CMake artefacts
382-
find . -name .git -prune -o \
383-
-iname CMakeFiles -exec rm -rf {} \+ -o \
384-
\( -iname cmake_install.cmake -o \
385-
-iname CTestTestfile.cmake -o \
386-
-iname CMakeCache.txt -o \
387-
-path './cmake/*.cmake' \) -exec rm -f {} \+
388-
# Remove Makefiles generated by in-tree CMake builds
389-
# (Not all files will exist in all branches, but that's OK.)
390-
rm -f 3rdparty/Makefile 3rdparty/*/Makefile
391-
rm -f pkgconfig/Makefile framework/Makefile
392-
rm -f include/Makefile programs/!(fuzz)/Makefile
393-
rm -f tf-psa-crypto/Makefile tf-psa-crypto/include/Makefile
394-
rm -f tf-psa-crypto/core/Makefile tf-psa-crypto/drivers/Makefile
395-
rm -f tf-psa-crypto/tests/Makefile
396-
rm -f tf-psa-crypto/drivers/everest/Makefile
397-
rm -f tf-psa-crypto/drivers/p256-m/Makefile
398-
rm -f tf-psa-crypto/drivers/builtin/Makefile
399-
rm -f tf-psa-crypto/drivers/builtin/src/Makefile
381+
# Remove files left over by an in-tree CMake build.
382+
# Take care to only hit in-tree builds, not out-of-tree builds in
383+
# subdirectories.
384+
# Remove **/Makefile only if it looks like it was created by an in-tree
385+
# CMake build.
386+
local cmake_dirs=($(git ls-files --recurse-submodules \
387+
'CMakeLists.txt' '**/CMakeLists.txt' |
388+
sed -e 's![^/]*$!!'))
389+
for d in "${cmake_dirs[@]}"; do
390+
if [ -d "$d/CMakeFiles" ]; then
391+
rm -rf "$d/CMakeFiles" \
392+
"$d/cmake_install.cmake" \
393+
"$d/CTestTestfile.cmake" \
394+
"$d/CMakeCache.txt" \
395+
"$d/Makefile"
396+
rm -rf "$d/cmake"/*.cmake
397+
fi
398+
done
400399
401400
# Remove any artifacts from the component_test_cmake_as_subdirectory test.
402401
rm -rf programs/test/cmake_subproject/build

0 commit comments

Comments
 (0)