values.update(args)
# put the variables in the environment:
- for key in values.keys():
- env[key] = values[key]
+ # (don't copy over variables that are not declared
+ # as options)
+ for option in self.options:
+ try:
+ env[option.key] = values[option.key]
+ except KeyError:
+ pass
# Call the convert functions:
for option in self.options:
try:
env[option.key] = option.converter(value)
except ValueError, x:
- raise SCons.Errors.UserError, 'Error converting option: %s\n%s'%(options.key, x)
+ raise SCons.Errors.UserError, 'Error converting option: %s\n%s'%(option.key, x)
# Finally validate the values:
help_text = ""
for option in self.options:
- help_text = help_text + '\n%s: %s\n default: %s\n actual: %s\n'%(option.key, option.help, option.default, env.subst('${%s}'%option.key))
+ help_text = help_text + '\n%s: %s\n default: %s\n'%(option.key, option.help, option.default)
+ if env.has_key(option.key):
+ help_text = help_text + ' actual: %s\n'%env.subst('${%s}'%option.key)
+ else:
+ help_text = help_text + ' actual: None\n'
return help_text
opts.Add('CC',
'The C compiler')
+opts.Add('UNSPECIFIED',
+ 'An option with no value')
+
def test_tool(env, platform):
if env['RELEASE_BUILD']:
env['CCFLAGS'] = env['CCFLAGS'] + ' -O'
print env['CC']
print env['CCFLAGS']
+# unspecified options should not be set:
+assert not env.has_key('UNSPECIFIED')
+
+# undeclared options should be ignored:
+assert not env.has_key('UNDECLARED')
+
+# calling Update() should not effect options that
+# are not declared on the options object:
+r = env['RELEASE_BUILD']
+opts = Options()
+opts.Update(env)
+assert env['RELEASE_BUILD'] == r
+
Default(env.Alias('dummy'))
""")
test.run(arguments='"CC=not_a_c_compiler"')
check(['0', '1', 'not_a_c_compiler', ccflags + ' -g'])
+test.run(arguments='"UNDECLARED=foo"')
+check(['0', '1', cc, ccflags + ' -g'])
+
+test.run(arguments='"CCFLAGS=--taco"')
+check(['0', '1', cc, ccflags + ' -g'])
+
test.write('custom.py', """
DEBUG_BUILD=0
RELEASE_BUILD=1
default: None
actual: %s
+UNSPECIFIED: An option with no value
+ default: None
+ actual: None
+
Use scons -H for help about command-line options.
"""%cc)