[Scons-users] Generating a source file that changes

Francis Bolduc fbolduc at gmail.com
Tue Oct 30 08:47:17 EDT 2012


I completely forgot the Value builder (built-in into SCons). Sorry
about that. Here is a working example:

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 = Environment()

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

sourceCode = '''
#include <iostream>
int main(int argc, char ** argv)
{
std::cout << "Hello world!" << std::endl;
}
'''

env.Program(env.ValueFile('my.cpp', env.Value(sourceCode)))


More information about the Scons-users mailing list