From: stevenknight Date: Sat, 13 Aug 2005 22:02:54 +0000 (+0000) Subject: Fix conversion and comparison of Boolean values. (Craig Scott) X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=0404e2623b98d1af54eb0a27bab0f3748bc38bc1;p=scons.git Fix conversion and comparison of Boolean values. (Craig Scott) git-svn-id: http://scons.tigris.org/svn/scons/trunk@1332 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 9d2e2351..1696d7f1 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -44,8 +44,6 @@ RELEASE 0.97 - XXX - Allow access to both TARGET and SOURCE in $*PATH expansions. - - Allow SConscript files to modify BUILD_TARGETS. - From Timothee Besset: - Add support for Objective C/C++ .m and .mm file suffixes (for @@ -580,6 +578,12 @@ RELEASE 0.97 - XXX - Have the Fortran module emitter look for Fortan modules to be created relative to $FORTRANMODDIR, not the top-level directory. + - When saving Options to a file, run default values through the + converter before comparing them with the set values. This correctly + suppresses Boolean Option values from getting written to the saved + file when they're one of the many synonyms for a default True or + False value. + From Jeff Squyres: - Documentation changes: Use $CPPDEFINES instead of $CCFLAGS in man diff --git a/src/engine/SCons/Options/OptionsTests.py b/src/engine/SCons/Options/OptionsTests.py index 96f2e2b2..b908568d 100644 --- a/src/engine/SCons/Options/OptionsTests.py +++ b/src/engine/SCons/Options/OptionsTests.py @@ -320,6 +320,11 @@ class OptionsTestCase(unittest.TestCase): test = TestSCons.TestSCons() cache_file = test.workpath('cached.options') opts = SCons.Options.Options() + + def bool_converter(val): + if val in [1, 'y']: val = 1 + if val in [0, 'n']: val = 0 + return val # test saving out empty file opts.Add('OPT_VAL', @@ -331,16 +336,34 @@ class OptionsTestCase(unittest.TestCase): default='foo') opts.Add('OPT_VAL_3', default=1) + opts.Add('OPT_BOOL_0', + default='n', + converter=bool_converter) + opts.Add('OPT_BOOL_1', + default='y', + converter=bool_converter) + opts.Add('OPT_BOOL_2', + default=0, + converter=bool_converter) env = Environment() opts.Update(env, {'OPT_VAL_3' : 2}) - assert env['OPT_VAL'] == 21 - assert env['OPT_VAL_2'] == 'foo' - assert env['OPT_VAL_3'] == 2 + assert env['OPT_VAL'] == 21, env['OPT_VAL'] + assert env['OPT_VAL_2'] == 'foo', env['OPT_VAL_2'] + assert env['OPT_VAL_3'] == 2, env['OPT_VAL_3'] + assert env['OPT_BOOL_0'] == 0, env['OPT_BOOL_0'] + assert env['OPT_BOOL_1'] == 1, env['OPT_BOOL_1'] + assert env['OPT_BOOL_2'] == '0', env['OPT_BOOL_2'] + env['OPT_VAL_2'] = 'bar' + env['OPT_BOOL_0'] = 0 + env['OPT_BOOL_1'] = 1 + env['OPT_BOOL_2'] = 2 + opts.Save(cache_file, env) checkSave(cache_file, { 'OPT_VAL_2' : 'bar', - 'OPT_VAL_3' : 2 }) + 'OPT_VAL_3' : 2, + 'OPT_BOOL_2' : 2}) # Test against some old bugs class Foo: diff --git a/src/engine/SCons/Options/__init__.py b/src/engine/SCons/Options/__init__.py index f5f1b8db..73339859 100644 --- a/src/engine/SCons/Options/__init__.py +++ b/src/engine/SCons/Options/__init__.py @@ -197,8 +197,12 @@ class Options: # Convert stuff that has a repr() that # cannot be evaluated into a string value = SCons.Util.to_String(value) - if env.subst('${%s}' % option.key) != \ - env.subst(SCons.Util.to_String(option.default)): + + defaultVal = env.subst(SCons.Util.to_String(option.default)) + if option.converter: + defaultVal = option.converter(defaultVal) + + if str(env.subst('${%s}' % option.key)) != str(defaultVal): fh.write('%s = %s\n' % (option.key, repr(value))) except KeyError: pass