4

When I generate an out of tree Ninja build using CMake, it would be useful to be able to remove the intermediate build products (i.e. object files and static libraries), in order to save disk space on our CI server. Is there a way to do this?

1 Answer 1

5

It is possible to clean by rule with Ninja, but knowing which rules generate intermediates is not possible with Ninja alone; instead we must resort to shell scripts:

grep "^rule.*\(_COMPILER_\|_STATIC_LIBRARY_\)" rules.ninja | \
    cut -d' ' -f2 | xargs -n1 ninja -t clean -r

This greps the rules.ninja file for those rules that generate object files and static libraries, then invokes ninja -t clean -r <rule> on each in order to do the actual cleaning. The equivalent functionality on Windows is achieved with:

FOR /f "tokens=2" %%R IN ('findstr "_COMPILER_ _STATIC_LIBRARY_" rules.ninja') DO (
    ninja -t clean -r %%~R
)

It's a hack for sure, but it saves us a substantial amount of disk space, so worth documenting, I thought.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.