summaryrefslogtreecommitdiffstats
path: root/src/engine
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/SCons/Options/OptionsTests.py31
-rw-r--r--src/engine/SCons/Options/__init__.py8
2 files changed, 33 insertions, 6 deletions
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