From 28a2ad02e39ea773ae56aee9c3f855261303ebfe Mon Sep 17 00:00:00 2001 From: Andrew Featherstone Date: Tue, 29 Jul 2014 22:05:47 +0100 Subject: Corrects handling of appending dictionaries to CPPDEFINES. Amended a test case to demonstrate the issue. --- src/engine/SCons/Environment.py | 35 ++++++++++++++++--- test/CPPDEFINES/append.py | 75 ++++++++++++++++++++--------------------- 2 files changed, 68 insertions(+), 42 deletions(-) diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index d178f49..6c665df 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -1206,7 +1206,13 @@ class Base(SubstitutionEnvironment): # based on what we think the value looks like. if SCons.Util.is_List(val): if key == 'CPPDEFINES': - orig = orig.items() + tmp = [] + for (k, v) in orig.iteritems(): + if v is not None: + tmp.append((k, v)) + else: + tmp.append((k,)) + orig = tmp orig += val self._dict[key] = orig else: @@ -1286,8 +1292,15 @@ class Base(SubstitutionEnvironment): else: tmp.append((i,)) val = tmp + # Construct a list of (key, value) tuples. if SCons.Util.is_Dict(dk): - dk = dk.items() + tmp = [] + for (k, v) in dk.iteritems(): + if v is not None: + tmp.append((k, v)) + else: + tmp.append((k,)) + dk = tmp elif SCons.Util.is_String(dk): dk = [(dk,)] else: @@ -1327,8 +1340,15 @@ class Base(SubstitutionEnvironment): else: tmp.append((i,)) dk = tmp + # Construct a list of (key, value) tuples. if SCons.Util.is_Dict(val): - val = val.items() + tmp = [] + for (k, v) in val.iteritems(): + if v is not None: + tmp.append((k, v)) + else: + tmp.append((k,)) + val = tmp elif SCons.Util.is_String(val): val = [(val,)] if delete_existing: @@ -1351,7 +1371,14 @@ class Base(SubstitutionEnvironment): if SCons.Util.is_String(dk): dk = [dk] elif SCons.Util.is_Dict(dk): - dk = dk.items() + tmp = [] + for (k, v) in dk.iteritems(): + if v is not None: + tmp.append((k, v)) + else: + tmp.append((k,)) + dk = tmp + #dk = dk.items() if SCons.Util.is_String(val): if val in dk: val = [] diff --git a/test/CPPDEFINES/append.py b/test/CPPDEFINES/append.py index 2dacd8a..6e69d09 100644 --- a/test/CPPDEFINES/append.py +++ b/test/CPPDEFINES/append.py @@ -47,18 +47,17 @@ print env_1738_2.subst('$_CPPDEFFLAGS') env_2300_1 = Environment(CPPDEFINES = 'foo', CPPDEFPREFIX='-D') env_2300_1.Append(CPPDEFINES='bar') print env_2300_1.subst('$_CPPDEFFLAGS') -#env_2300_1.Object('test_2300_1', 'main.c') env_2300_2 = Environment(CPPDEFINES = ['foo'], CPPDEFPREFIX='-D') # note the list env_2300_2.Append(CPPDEFINES='bar') print env_2300_2.subst('$_CPPDEFFLAGS') -#env_2300_2.Object('test_2300_2', 'main.c') # http://scons.tigris.org/issues/show_bug.cgi?id=1152 +# http://scons.tigris.org/issues/show_bug.cgi?id=2900 cases=[('string', 'FOO'), ('list', ['NAME1', 'NAME2']), ('list-of-2lists', [('NAME1','VAL1'), ['NAME2','VAL2']]), - ('dict', {'NAME1' : 'VAL1', 'NAME2' : 'VAL2'}) + ('dict', {'NAME1' : 'VAL1', 'NAME2' : 'VAL2', 'NAME3' : None}) ] for (t1, c1) in cases: @@ -107,13 +106,13 @@ AppendUnique: result=[('FOO',), ('NAME1', 'VAL1'), ('NAME2', 'VAL2')] final=-DFOO -DNAME1=VAL1 -DNAME2=VAL2 ==== Testing CPPDEFINES, appending a dict to a string - orig = FOO, append = {'NAME2': 'VAL2', 'NAME1': 'VAL1'} + orig = FOO, append = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'} Append: - result=['FOO', {'NAME2': 'VAL2', 'NAME1': 'VAL1'}] - final=-DFOO -DNAME2=VAL2 -DNAME1=VAL1 + result=['FOO', {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}] + final=-DFOO -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 AppendUnique: - result=['FOO', ('NAME2', 'VAL2'), ('NAME1', 'VAL1')] - final=-DFOO -DNAME2=VAL2 -DNAME1=VAL1 + result=['FOO', ('NAME2', 'VAL2'), 'NAME3', ('NAME1', 'VAL1')] + final=-DFOO -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 ==== Testing CPPDEFINES, appending a string to a list orig = ['NAME1', 'NAME2'], append = FOO Append: @@ -139,13 +138,13 @@ AppendUnique: result=[('NAME1',), ('NAME2',), ('NAME1', 'VAL1'), ('NAME2', 'VAL2')] final=-DNAME1 -DNAME2 -DNAME1=VAL1 -DNAME2=VAL2 ==== Testing CPPDEFINES, appending a dict to a list - orig = ['NAME1', 'NAME2'], append = {'NAME2': 'VAL2', 'NAME1': 'VAL1'} + orig = ['NAME1', 'NAME2'], append = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'} Append: - result=['NAME1', 'NAME2', {'NAME2': 'VAL2', 'NAME1': 'VAL1'}] - final=-DNAME1 -DNAME2 -DNAME2=VAL2 -DNAME1=VAL1 + result=['NAME1', 'NAME2', {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}] + final=-DNAME1 -DNAME2 -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 AppendUnique: - result=[('NAME1',), ('NAME2',), ('NAME2', 'VAL2'), ('NAME1', 'VAL1')] - final=-DNAME1 -DNAME2 -DNAME2=VAL2 -DNAME1=VAL1 + result=[('NAME1',), ('NAME2',), ('NAME2', 'VAL2'), ('NAME3',), ('NAME1', 'VAL1')] + final=-DNAME1 -DNAME2 -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 ==== Testing CPPDEFINES, appending a string to a list-of-2lists orig = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']], append = FOO Append: @@ -171,45 +170,45 @@ AppendUnique: result=[('NAME1', 'VAL1'), ('NAME2', 'VAL2')] final=-DNAME1=VAL1 -DNAME2=VAL2 ==== Testing CPPDEFINES, appending a dict to a list-of-2lists - orig = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']], append = {'NAME2': 'VAL2', 'NAME1': 'VAL1'} + orig = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']], append = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'} Append: - result=[('NAME1', 'VAL1'), ['NAME2', 'VAL2'], {'NAME2': 'VAL2', 'NAME1': 'VAL1'}] - final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME2=VAL2 -DNAME1=VAL1 + result=[('NAME1', 'VAL1'), ['NAME2', 'VAL2'], {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}] + final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 AppendUnique: - result=[('NAME2', 'VAL2'), ('NAME1', 'VAL1')] - final=-DNAME2=VAL2 -DNAME1=VAL1 + result=[('NAME2', 'VAL2'), ('NAME3',), ('NAME1', 'VAL1')] + final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 ==== Testing CPPDEFINES, appending a string to a dict - orig = {'NAME2': 'VAL2', 'NAME1': 'VAL1'}, append = FOO + orig = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}, append = FOO Append: - result={'FOO': None, 'NAME2': 'VAL2', 'NAME1': 'VAL1'} - final=-DFOO -DNAME1=VAL1 -DNAME2=VAL2 + result={'FOO': None, 'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'} + final=-DFOO -DNAME1=VAL1 -DNAME2=VAL2 -DNAME3 AppendUnique: - result=[('NAME2', 'VAL2'), ('NAME1', 'VAL1'), 'FOO'] - final=-DNAME2=VAL2 -DNAME1=VAL1 -DFOO + result=[('NAME2', 'VAL2'), ('NAME3',), ('NAME1', 'VAL1'), 'FOO'] + final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 -DFOO ==== Testing CPPDEFINES, appending a list to a dict - orig = {'NAME2': 'VAL2', 'NAME1': 'VAL1'}, append = ['NAME1', 'NAME2'] + orig = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}, append = ['NAME1', 'NAME2'] Append: - result=[('NAME2', 'VAL2'), ('NAME1', 'VAL1'), 'NAME1', 'NAME2'] - final=-DNAME2=VAL2 -DNAME1=VAL1 -DNAME1 -DNAME2 + result=[('NAME2', 'VAL2'), ('NAME3',), ('NAME1', 'VAL1'), 'NAME1', 'NAME2'] + final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 -DNAME1 -DNAME2 AppendUnique: - result=[('NAME2', 'VAL2'), ('NAME1', 'VAL1'), ('NAME1',), ('NAME2',)] - final=-DNAME2=VAL2 -DNAME1=VAL1 -DNAME1 -DNAME2 + result=[('NAME2', 'VAL2'), ('NAME3',), ('NAME1', 'VAL1'), ('NAME1',), ('NAME2',)] + final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 -DNAME1 -DNAME2 ==== Testing CPPDEFINES, appending a list-of-2lists to a dict - orig = {'NAME2': 'VAL2', 'NAME1': 'VAL1'}, append = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + orig = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}, append = [('NAME1', 'VAL1'), ['NAME2', 'VAL2']] Append: - result=[('NAME2', 'VAL2'), ('NAME1', 'VAL1'), ('NAME1', 'VAL1'), ['NAME2', 'VAL2']] - final=-DNAME2=VAL2 -DNAME1=VAL1 -DNAME1=VAL1 -DNAME2=VAL2 + result=[('NAME2', 'VAL2'), ('NAME3',), ('NAME1', 'VAL1'), ('NAME1', 'VAL1'), ['NAME2', 'VAL2']] + final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 -DNAME1=VAL1 -DNAME2=VAL2 AppendUnique: - result=[('NAME2', 'VAL2'), ('NAME1', 'VAL1')] - final=-DNAME2=VAL2 -DNAME1=VAL1 + result=[('NAME2', 'VAL2'), ('NAME3',), ('NAME1', 'VAL1')] + final=-DNAME2=VAL2 -DNAME3 -DNAME1=VAL1 ==== Testing CPPDEFINES, appending a dict to a dict - orig = {'NAME2': 'VAL2', 'NAME1': 'VAL1'}, append = {'NAME2': 'VAL2', 'NAME1': 'VAL1'} + orig = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'}, append = {'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'} Append: - result={'NAME2': 'VAL2', 'NAME1': 'VAL1'} - final=-DNAME1=VAL1 -DNAME2=VAL2 + result={'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'} + final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME3 AppendUnique: - result={'NAME2': 'VAL2', 'NAME1': 'VAL1'} - final=-DNAME1=VAL1 -DNAME2=VAL2 + result={'NAME2': 'VAL2', 'NAME3': None, 'NAME1': 'VAL1'} + final=-DNAME1=VAL1 -DNAME2=VAL2 -DNAME3 """ build_output="scons: `.' is up to date.\n" -- cgit v0.12 From 31b8874144cf5df3b7a7fa296579534a628db8f8 Mon Sep 17 00:00:00 2001 From: Andrew Featherstone Date: Tue, 29 Jul 2014 22:18:52 +0100 Subject: Remove commented out code. --- src/engine/SCons/Environment.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index 6c665df..9a54501 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -1378,7 +1378,6 @@ class Base(SubstitutionEnvironment): else: tmp.append((k,)) dk = tmp - #dk = dk.items() if SCons.Util.is_String(val): if val in dk: val = [] -- cgit v0.12