summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2005-08-13 22:02:54 (GMT)
committerSteven Knight <knight@baldmt.com>2005-08-13 22:02:54 (GMT)
commita941b68612df943f6addacc59cd1ff3aa47b5907 (patch)
tree8434de90c425cfd8577a605d76cd0d413b2d3426
parent3c4eea886bf6ed264df3e7a521e196eaf6478378 (diff)
downloadSCons-a941b68612df943f6addacc59cd1ff3aa47b5907.zip
SCons-a941b68612df943f6addacc59cd1ff3aa47b5907.tar.gz
SCons-a941b68612df943f6addacc59cd1ff3aa47b5907.tar.bz2
Fix conversion and comparison of Boolean values. (Craig Scott)
-rw-r--r--src/CHANGES.txt8
-rw-r--r--src/engine/SCons/Options/OptionsTests.py31
-rw-r--r--src/engine/SCons/Options/__init__.py8
3 files changed, 39 insertions, 8 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt
index 9d2e235..1696d7f 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 96f2e2b..b908568 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 f5f1b8d..7333985 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