From 2dcd08fa8f202ea10f3518b47a0b262f4badf532 Mon Sep 17 00:00:00 2001 From: garyo Date: Tue, 14 Apr 2009 10:51:00 +0000 Subject: [PATCH] Patch submitted by Lukas Erlinghagen. Thanks, Lukas! this patch should fix issue 2362. - Variables that are added via Variables.Add or Variables.AddVariables are now removed from the 'unknown' dict if present - An option's name and its aliases can now actually be provided as a tuple as well as a list - Test cases for using option aliases and for issue 2362 itself are included git-svn-id: http://scons.tigris.org/svn/scons/trunk@4090 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/engine/SCons/Variables/VariablesTests.py | 106 +++++++++++++++++++ src/engine/SCons/Variables/__init__.py | 8 +- 2 files changed, 113 insertions(+), 1 deletion(-) diff --git a/src/engine/SCons/Variables/VariablesTests.py b/src/engine/SCons/Variables/VariablesTests.py index 7f496924..69ef9fe4 100644 --- a/src/engine/SCons/Variables/VariablesTests.py +++ b/src/engine/SCons/Variables/VariablesTests.py @@ -513,6 +513,44 @@ B 42 54 b - alpha test ['B'] """ text = opts.GenerateHelpText(env, sort=cmp) assert text == expectAlpha, text + + def test_Aliases(self): + """Test option aliases""" + # test alias as a tuple + opts = SCons.Variables.Variables() + opts.AddVariables( + (('ANSWER', 'ANSWERALIAS'), + 'THE answer to THE question', + "42"), + ) + + env = Environment() + opts.Update(env, {'ANSWER' : 'answer'}) + + assert env.has_key('ANSWER') + + env = Environment() + opts.Update(env, {'ANSWERALIAS' : 'answer'}) + + assert env.has_key('ANSWER') and not env.has_key('ANSWERALIAS') + + # test alias as a list + opts = SCons.Variables.Variables() + opts.AddVariables( + (['ANSWER', 'ANSWERALIAS'], + 'THE answer to THE question', + "42"), + ) + + env = Environment() + opts.Update(env, {'ANSWER' : 'answer'}) + + assert env.has_key('ANSWER') + + env = Environment() + opts.Update(env, {'ANSWERALIAS' : 'answer'}) + + assert env.has_key('ANSWER') and not env.has_key('ANSWERALIAS') @@ -537,7 +575,75 @@ class UnknownVariablesTestCase(unittest.TestCase): r = opts.UnknownVariables() assert r == {'UNKNOWN' : 'unknown'}, r assert env['ANSWER'] == 'answer', env['ANSWER'] + + def test_AddOptionUpdatesUnknown(self): + """Test updating of the 'unknown' dict""" + opts = SCons.Variables.Variables() + + opts.Add('A', + 'A test variable', + "1") + + args = { + 'A' : 'a', + 'ADDEDLATER' : 'notaddedyet', + } + + env = Environment() + opts.Update(env,args) + + r = opts.UnknownVariables() + assert r == {'ADDEDLATER' : 'notaddedyet'}, r + assert env['A'] == 'a', env['A'] + + opts.Add('ADDEDLATER', + 'An option not present initially', + "1") + + args = { + 'A' : 'a', + 'ADDEDLATER' : 'added', + } + + opts.Update(env, args) + + r = opts.UnknownVariables() + assert len(r) == 0, r + assert env['ADDEDLATER'] == 'added', env['ADDEDLATER'] + def test_AddOptionWithAliasUpdatesUnknown(self): + """Test updating of the 'unknown' dict (with aliases)""" + opts = SCons.Variables.Variables() + + opts.Add('A', + 'A test variable', + "1") + + args = { + 'A' : 'a', + 'ADDEDLATERALIAS' : 'notaddedyet', + } + + env = Environment() + opts.Update(env,args) + + r = opts.UnknownVariables() + assert r == {'ADDEDLATERALIAS' : 'notaddedyet'}, r + assert env['A'] == 'a', env['A'] + + opts.AddVariables( + (('ADDEDLATER', 'ADDEDLATERALIAS'), + 'An option not present initially', + "1"), + ) + + args['ADDEDLATERALIAS'] = 'added' + + opts.Update(env, args) + + r = opts.UnknownVariables() + assert len(r) == 0, r + assert env['ADDEDLATER'] == 'added', env['ADDEDLATER'] if __name__ == "__main__": diff --git a/src/engine/SCons/Variables/__init__.py b/src/engine/SCons/Variables/__init__.py index 805471a6..f203677e 100644 --- a/src/engine/SCons/Variables/__init__.py +++ b/src/engine/SCons/Variables/__init__.py @@ -95,6 +95,12 @@ class Variables: option.converter = converter self.options.append(option) + + # options might be added after the 'unknown' dict has been set up, + # so we remove the key and all its aliases from that dict + for alias in list(option.aliases) + [ option.key ]: + if alias in self.unknown: + del self.unknown[alias] def keys(self): """ @@ -179,7 +185,7 @@ class Variables: for arg, value in args.items(): added = False for option in self.options: - if arg in option.aliases + [ option.key ]: + if arg in list(option.aliases) + [ option.key ]: values[option.key] = value added = True if not added: -- 2.26.2