summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGary Oberbrunner <garyo@oberbrunner.com>2009-04-14 10:51:00 (GMT)
committerGary Oberbrunner <garyo@oberbrunner.com>2009-04-14 10:51:00 (GMT)
commit51cff874f72bc4afe2eb60a928472dc1669eab88 (patch)
tree76521351251ce2cd5e13b5157d2fabb24ec4b231
parenta1e8d845f6d0b6f2bb86f7347fbdf1ba4a777bc4 (diff)
downloadSCons-51cff874f72bc4afe2eb60a928472dc1669eab88.zip
SCons-51cff874f72bc4afe2eb60a928472dc1669eab88.tar.gz
SCons-51cff874f72bc4afe2eb60a928472dc1669eab88.tar.bz2
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
-rw-r--r--src/engine/SCons/Variables/VariablesTests.py106
-rw-r--r--src/engine/SCons/Variables/__init__.py8
2 files changed, 113 insertions, 1 deletions
diff --git a/src/engine/SCons/Variables/VariablesTests.py b/src/engine/SCons/Variables/VariablesTests.py
index 7f49692..69ef9fe 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 805471a..f203677 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: