Reputation: 234354
I would like to add a Variable that will only affect the display of compiler errors, like this:
vars = Variables()
vars.Add(BoolVariable('fatal', 'Stop on first error', True))
# ...
if env['fatal']:
env.MergeFlags(['-Wfatal-errors'])
However, as is, if I run scons fatal=yes
followed by scons fatal=no
, I get a full rebuild, while there is no reason to, since this flag does not matter for already compiled object files.
Does SCons allow this? If so, how?
Upvotes: 1
Views: 146
Reputation: 196
SCons doesn't really allow for what you want to do. Each node that has to be built has a command line action associated with it. MD5 checksums of the command line strings are stored and a rebuild is triggered if these checksums change. If you change the warning flags, the command line for building the object files changes, even if the resulting object files are the same.
If you're really determined, there's always a way to hack around it though. You cold change the way MD5 sums are calculated inside SCons for example. As a proof of concept, I've made SCons ignore the -Wall
flag when considering a rebuild. This was done by changing the method that reports the command line associated with an action by placing the following code at the top of a SConstruct file.
import SCons
import types
SCons.Action.ActionBase.get_contents_orig = SCons.Action.ActionBase.get_contents
def get_contents(self, *args, **kw):
norebuild = ("-Wall",)
cnt = self.get_contents_orig(*args, **kw).split()
cnt_norebuild = " ".join(i for i in cnt if i not in norebuild)
return cnt_norebuild
SCons.Action.ActionBase.get_contents = types.MethodType(
get_contents, None, SCons.Action.ActionBase)
This worked for me with a very simple SConstruct file. It is an extremely poor hack though, and will probably break between different versions or with more complex builds.
So in conclusion, it's possible to do what you're asking for, but highly ill-advised.
Upvotes: 3