Search code examples
c++buildscons

Scons set s directory as NoClean


I'm using scons as my build system of c++.

There's a sub directory that contains a static library.

I've tried to set:

NoClean("${PATH_TO_DIR}")

But the files in this directory are still removed by scons -c.

Is there a way to prevent this command from removing all files generated in this directory?


Solution

  • The flag -c works more or less like this:

    1. List all the files that could be built by this call of scons if the flag was not there.
    2. Add to the list relevant files marked to be cleaned with Clean().
    3. Delete from the list the files marked with NoClean() (non-recursively).
    4. Remove all the files that are remaining on the list from the filesystem.

    SCons is very focused on files and it doesn't work that well with directories. Usually, it just creates them automatically whenever they are needed and for the rest of the time it pretends they doesn't exist and it is all a flat file-system. It doesn't even delete automatically created directories so your NoClean() is double-ineffective :-) (You would need to call Clean() on the directory for SCons to be able to remove it during cleaning.)

    I think your only option is to call NoClean() for every file that you create in this directory. (If you have the list/set of those files lying somewhere, you can just call NoClean() once, passing the list to it.)