What is the correct SCONS method to update the contents of a file that is part of the assembly?
I use SCONS to create a fairly large project. But for a simple question, suppose it looks like this:
env.Program("foo", ["foo.c", "version.c"])
Under certain conditions of the assembly, it is necessary to update the contents of one of the CPP files in the assembly using the new information - the actual version information. In the above example, I will need to change the contents of "version.c". I thought I could do it pretty nicely with the following example:
env.Command(target="version.c", source=[], action=PythonFunctionToUpdateContents)
env.Program("foo", ["foo.c", "version.c"])
PythonFunctionToUpdateContents will use target [0] as the file name, open it, find specific text, change it, write the changes back to the same file. Unfortunately, the above example does not work. SCONS automatically deletes the target file before creating it, so my "version.c" file was deleted before it could be updated.
I tried setting the target and source to the same file in the env.Command () call, but this just creates a dependency loop.
I know that I can solve this problem by creating the SCONS ENTIRE version.c file, but this does not work, since version.c contains a lot of other code that can be changed as part of normal development.
source
share