tags:

views:

270

answers:

1

Is there any way to cause scons to force-build all targets when the Sconstruct file itself changes?

(reasoning being that if I change a build setting, I can't rely on a previously built file to be consistent with the new build settings)

+2  A: 

If you need to add the SConstruct as a dependency of one of your targets then either you are doing it wrong or there is a bug in SCons.

For example if we are talking about the compilation flags. Say you want to change from -O0 to -O2. In the simplest case, you would have:

env = Environment(CCFLAGS = '-O0')
env.Program(target = 'foo', source = 'foo.c')

You run scons, it compiles foo.c to foo.o and creates foo(.exe) from that. And if you change this to:

env = Environment(CCFLAGS = '-O2')
env.Program(target = 'foo', source = 'foo.c')

then scons will rebuild all the targets that are defined in env. This is because the command line is an implicit dependency for a target. So changing the CCFLAGS will change the dependency value, which will rebuild the "foo" target.

Maybe your real question is more like "Why does scons not rebuild my targets even though I have changed the command line options?". Either way you perhaps need to think in terms of the real dependencies involved rather than adding an artificial one to try and force a rebuild.

rq
The change in -O level happens to be exactly what I am dealing with. Didn't realize scons is supposed to rebuild... not sure how it does that.
Jason S
I believe in the .sconsign.dblite cache file it stores the command line from last time as part of the hash.
rq
Huh, I just tried changing the -O level on a new project I set up, and it does rebuild properly. Not sure what was wrong with my other project.
Jason S