How can I get the Variables.save to save all variables, and not just the one specified by the user. I want to make sure that future runs of scons use exactly the same setup.
How can I get the Variables.save to save all variables, and not just the
Share
Sadly there is no way to do this using core SCons functions. The decision on whether to save a variable value or not is hard-wired into Save, and only values that are not the defaults can be saved.
However, you can save all variables by abusing the not-well-documented “converter” function. It ain’t pretty, but does the job.
When you call
Variables.Save(), it calls each variable’s converter function and checks the result to see if it is the same as the default (input) value. If you return something that is not the input value when called fromSavethen all values are stored in the cache file. Elsewhere you need the converter to return the input value as-is, or it would use incorrect variable values.Here the function
save_allis the hack. It uses the stack trace to check if it is called from within Save. If it is, then it returns a tampered value, otherwise it returns the input value unchanged. You can check the result of this example in the cache file “config.py”.