[Scons-users] Generating a source file that changes

Carsten Fuchs carsten.fuchs at cafu.de
Mon Oct 29 06:59:32 EDT 2012


Hi all,

I use a SCons script like this to generate a source file:


List = sorted([p for p in os.listdir("plugins/") if os.path.exists("plugins/" + p + "/SConscript")])

def generateCode(target, source, env):
with open(str(target[0]), 'w') as f:
for p in List:
f.write("// ...\n");

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


It works very well, but what generateCode() writes into f can sometimes (rarely) change (as
shown above as a result of someone adding another plugin into the "plugins" directory).

However, SCons doesn't seem to realize this: Once the auto-generated file exists, generateCode()
is not called again, unless the file is deleted manually.

What's the proper way to fix this?

(As I use the MD5-timestamp decider, I was considering calling generateCode() manually in the
SConstruct file, so that it is forcibly re-written each time SCons is run, quasi like using the
AlwaysBuild() function. But, as so often, this feels like a hack, and I was wondering if there
was a more SCons-ish way to do this?)

Best regards,
Carsten



--
Cafu - the open-source Game and Graphics Engine
for multiplayer, cross-platform, real-time 3D Action
Learn more at http://www.cafu.de


More information about the Scons-users mailing list