[Scons-users] Generating a source file that changes

Francis Bolduc fbolduc at gmail.com
Mon Oct 29 21:29:35 EDT 2012


There is a trick to add a dependency on the content of the file, rather
than just the fact that it exists.

The idea is that SCons will track dependencies between builder sources and
targets. So if you create a builder that takes a string as a source, you'll
effectively create a dependency between the string and the generated file.
So if the file is changed or the string changes, the file will be
regenerated.

Here is such a builder:

def ValueFileBuilder(env, target, source):
'''
Ensure that target file contains source value.
If source value changes, target file is rebuilt.
Use this to specify dependency between source value and target file.
'''
f = file(str(target[0]), 'wb')
f.write(source[0].get_contents())
f.close()

env['BUILDERS']['ValueFile'] = env.Builder(action =
env.Action(ValueFileBuilder))

Then you use it thus:

app = env.Program('Ca3DE/Cafu',
Glob("Ca3DE/*.cpp") + env.ValueFile('Ca3DE/auto-gen/**Ap
pCafu_GenList.cpp', generateCode))

I hope this helps.

--
Francis Bolduc, B.Sc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://four.pairlist.net/pipermail/scons-users/attachments/20121029/04cb5a6e/attachment.htm>


More information about the Scons-users mailing list