From 82bf497dd03f97f66f0026d9fea51b24af0af67b Mon Sep 17 00:00:00 2001 From: Steven Knight Date: Sun, 13 Oct 2002 12:52:05 +0000 Subject: Make undeclared options be ignored. (Anthony Roach) --- src/engine/SCons/Options.py | 17 +++++++++++++---- src/engine/SCons/OptionsTests.py | 2 ++ test/Options.py | 26 ++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/engine/SCons/Options.py b/src/engine/SCons/Options.py index becee14..7e70118 100644 --- a/src/engine/SCons/Options.py +++ b/src/engine/SCons/Options.py @@ -93,8 +93,13 @@ class Options: 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: @@ -103,7 +108,7 @@ class 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: @@ -122,7 +127,11 @@ class Options: 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 diff --git a/src/engine/SCons/OptionsTests.py b/src/engine/SCons/OptionsTests.py index ec9e42f..730c87d 100644 --- a/src/engine/SCons/OptionsTests.py +++ b/src/engine/SCons/OptionsTests.py @@ -38,6 +38,8 @@ class Environment: self.dict[key] = value def __getitem__(self, key): return self.dict[key] + def has_key(self, key): + return self.dict.has_key(key) def check(key,value): diff --git a/test/Options.py b/test/Options.py index b431d88..2ecdd57 100644 --- a/test/Options.py +++ b/test/Options.py @@ -55,6 +55,9 @@ opts.Add('DEBUG_BUILD', 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' @@ -71,6 +74,19 @@ print env['DEBUG_BUILD'] 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')) """) @@ -91,6 +107,12 @@ check(['1', '0', cc, ccflags + ' -O']) 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 @@ -119,6 +141,10 @@ CC: The C compiler default: None actual: %s +UNSPECIFIED: An option with no value + default: None + actual: None + Use scons -H for help about command-line options. """%cc) -- cgit v0.12