SCons and dependencies for python function generating source
Posted
by
elmo
on Stack Overflow
See other posts from Stack Overflow
or by elmo
Published on 2012-11-29T17:02:14Z
Indexed on
2012/11/29
17:03 UTC
Read the original article
Hit count: 167
I have an input file data
, a python function parse
and a template
.
What I am trying to do is use parse
function to get dictionary out of data
and use that to replace fields in template
.
Now to make this a bit more generic (I perform the same action in few places) I have defined a custom function to do so.
Below is definition of custom builder and values
is a dictionary with { 'name': (data_file, parse_function) }
(you don't really need to read through this, I simply put it here for completeness).
def TOOL_ADD_FILL_TEMPLATE(env):
def FillTemplate(env, output, template, values):
out = output[0]
subs = {}
for name, (node, process) in values.iteritems():
def Process(env, target, source):
with open( env.GetBuildPath(target[0]), 'w') as out:
out.write( process( source[0] ) )
builder = env.Builder( action = Process )
subs[name] = builder( env, env.GetBuildPath(output[0])+'_'+name+'_processed.cpp', node )[0]
def Fill(env, target, source):
values = dict( (name, n.get_contents()) for name, n in subs.iteritems() )
contents = template[0].get_contents().format( **values )
open( env.GetBuildPath(target[0]), 'w').write( contents )
builder = env.Builder( action = Fill )
builder( env, output[0], template + subs.values() )
return output
env.Append(BUILDERS = {'FillTemplate': FillTemplate})
It works fine when it comes to checking if data
or template
changed. If it did it rebuilds the output. It even works if I edit process
function directly.
However if my process
function looks like this:
def process( node ):
return subprocess(node)
and I edit subprocess
the change goes unnoticed. Is there any way to get correct builds without making process
functions being always invoked?
© Stack Overflow or respective owner