diff options
Diffstat (limited to 'src/engine/SCons/Options')
-rw-r--r-- | src/engine/SCons/Options/OptionsTests.py | 32 | ||||
-rw-r--r-- | src/engine/SCons/Options/__init__.py | 36 |
2 files changed, 60 insertions, 8 deletions
diff --git a/src/engine/SCons/Options/OptionsTests.py b/src/engine/SCons/Options/OptionsTests.py index 95bd1cd..5ec9d7a 100644 --- a/src/engine/SCons/Options/OptionsTests.py +++ b/src/engine/SCons/Options/OptionsTests.py @@ -516,9 +516,37 @@ B 42 54 b - alpha test ['B'] assert text == expectAlpha, text - + +class UnknownOptionsTestCase(unittest.TestCase): + + def test_unknown(self): + """Test the UnknownOptions() method""" + opts = SCons.Options.Options() + opts.Add('ANSWER', + 'THE answer to THE question', + "42") + + args = { + 'ANSWER' : 'answer', + 'UNKNOWN' : 'unknown', + } + + env = Environment() + opts.Update(env, args) + + r = opts.UnknownOptions() + assert r == {'UNKNOWN' : 'unknown'}, r + assert env['ANSWER'] == 'answer', env['ANSWER'] + + + if __name__ == "__main__": - suite = unittest.makeSuite(OptionsTestCase, 'test_') + suite = unittest.TestSuite() + tclasses = [ OptionsTestCase, + UnknownOptionsTestCase ] + for tclass in tclasses: + names = unittest.getTestCaseNames(tclass, 'test_') + suite.addTests(map(tclass, names)) if not unittest.TextTestRunner().run(suite).wasSuccessful(): sys.exit(1) diff --git a/src/engine/SCons/Options/__init__.py b/src/engine/SCons/Options/__init__.py index e2ad80f..3dc7772 100644 --- a/src/engine/SCons/Options/__init__.py +++ b/src/engine/SCons/Options/__init__.py @@ -29,8 +29,11 @@ customizable variables to an SCons build. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" +import SCons.compat + import os.path import string +import sys import SCons.Errors import SCons.Util @@ -64,6 +67,7 @@ class Options: else: files = [] self.files = files + self.unknown = {} # create the singleton instance if is_global: @@ -158,16 +162,29 @@ class Options: # next set the value specified in the options file for filename in self.files: if os.path.exists(filename): - execfile(filename, values) - - # finally set the values specified on the command line + dir = os.path.split(os.path.abspath(filename))[0] + if dir: + sys.path.insert(0, dir) + try: + values['__name__'] = filename + execfile(filename, {}, values) + finally: + if dir: + del sys.path[0] + del values['__name__'] + + # set the values specified on the command line if args is None: args = self.args for arg, value in args.items(): - for option in self.options: - if arg in option.aliases + [ option.key ]: - values[option.key]=value + added = False + for option in self.options: + if arg in option.aliases + [ option.key ]: + values[option.key] = value + added = True + if not added: + self.unknown[arg] = value # put the variables in the environment: # (don't copy over variables that are not declared as options) @@ -195,6 +212,13 @@ class Options: if option.validator and values.has_key(option.key): option.validator(option.key, env.subst('${%s}'%option.key), env) + def UnknownOptions(self): + """ + Returns any options in the specified arguments lists that + were not known, declared options in this object. + """ + return self.unknown + def Save(self, filename, env): """ Saves all the options in the given file. This file can |