user2225754
user2225754

Reputation: 13

Scons -c command

Scons -c invokes clean build where it cleans all the objects, .elf files etc. My question is how does scons -c know which directories to find the objects in for deletion? How can I add a new path/folder that also gets cleaned along with other paths?

Thanks,

Upvotes: 0

Views: 513

Answers (1)

dmoody256
dmoody256

Reputation: 583

My question is how does scons -c know which directories to find the objects in for deletion?

It knows about all the targets locations because it built them, and cleaning essentially follows the same rules it used to know where to build the targets as it does to know where the targets are to clean.


How can I add a new path/folder that also gets cleaned along with other paths?

From SCons man page:

-c, --clean, --remove

Clean up by removing all target files for which a construction command is specified. Also remove any files or directories associated to the construction command using the Clean() function. Will not remove any targets specified by the NoClean() function.

Key wording here is that it removes all target files. If you want to clean up directories as well you will need to explicitly use the Clean function:

Clean(targets, files_or_dirs) , env.Clean(targets, files_or_dirs)

This specifies a list of files or directories which should be removed whenever the targets are specified with the -c command line option. The specified targets may be a list or an individual target. Multiple calls to Clean are legal, and create new targets or add files and directories to the clean list for the specified targets.

Multiple files or directories should be specified either as separate arguments to the Clean method, or as a list. Clean will also accept the return value of any of the construction environment Builder methods.

The related NoClean function overrides calling Clean for the same target, and any targets passed to both functions will not be removed by the -c option.

Examples:

Clean('foo', ['bar', 'baz'])
Clean('dist', env.Program('hello', 'hello.c'))
Clean(['foo', 'bar'], 'something_else_to_clean')

In this example, installing the project creates a subdirectory for the documentation. This statement causes the subdirectory to be removed if the project is deinstalled.

Clean(docdir, os.path.join(docdir, projectname))

This will take the targets which should be associated with what files or directories you want cleaned, and then when one of those targets gets cleaned, it will also clean the specified files and directories which may not be targets themselves.

Upvotes: 1

Related Questions