NOTE This is a follow on from my previous question.
My thinking is I'm misunderstanding one of the more fundamental aspects of how SCons works but here's an illustrative subset of my problem:
I have an SConscript file containing (essentially):
def IncrementBuildNumber(env, target, source):
#write some #define's to 'target' file using vanilla python code
return None
someProg = env.Program('SomeProg', source_list)
buildNumber = env.Builder(action = IncrementBuildNumber)
buildNumber_h = buildNumber(env, env.GetBuildPath('BuildNumber.h'), [])
env.Depends(someProg, buildNumber_h)
So basically I'm making a Builder
which calls a Python function which writes some C++ code to the target
file. This builder is invoked with my BuildNumber.h
file that my source code #include
's where needed.
The final Depends()
call is an attempt to trigger the builder every time SomeProg
is rebuilt.
This approach almost works. On first build everything works correctly, BuildNumber.h
is generated with the correct build number.
An immediate rebuild correctly deems everything up-to-date and doesn't re-invoke the IncrementBuildNumber
builder.
However, the problem is, when I update a .cpp
file which indirectly depends on BuildNumber.h
. It does a rebuild of the changed source file but I'm guessing deems the Builder's target as up-to-date and decides not to invoke it.
How can I get SCons to 'need' to invoke my builder (or command or whatever it needs to be) whenever the things that depend on it need re-building?
I'm feeling pretty close to a solution but just missing some final piece of knowledge into how SCons works.
I may need to note here that I am using a VARIANT_DIR
so I can delete files if needed...
Also I've tried AlwaysBuild()
but you guessed it, it always Increments even when someProg is up-to-date.