diff options
author | William Deegan <bill@baddogconsulting.com> | 2017-08-07 22:45:39 (GMT) |
---|---|---|
committer | William Deegan <bill@baddogconsulting.com> | 2017-08-07 22:45:39 (GMT) |
commit | 8ca7e7567aa44a8c0f74d00e78503cd94a8794b0 (patch) | |
tree | 74a1221558c955a1fa6beedb16b295e3e300dde3 /src | |
parent | 4936d53c1f92e522f147e846ea0860421098ffea (diff) | |
parent | 98c4c1c7b820bbb42384584bc0d95c7849f71503 (diff) | |
download | SCons-8ca7e7567aa44a8c0f74d00e78503cd94a8794b0.zip SCons-8ca7e7567aa44a8c0f74d00e78503cd94a8794b0.tar.gz SCons-8ca7e7567aa44a8c0f74d00e78503cd94a8794b0.tar.bz2 |
Merged in thosrtanner/trt-scons-sig-suppress (pull request #390)
Diffstat (limited to 'src')
-rw-r--r-- | src/CHANGES.txt | 4 | ||||
-rw-r--r-- | src/engine/SCons/ActionTests.py | 6 | ||||
-rw-r--r-- | src/engine/SCons/Subst.py | 29 | ||||
-rw-r--r-- | src/engine/SCons/SubstTests.py | 25 |
4 files changed, 53 insertions, 11 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt index ab6797a..fd41a75 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -88,6 +88,7 @@ may cause rebuilds. In no case should rebuilds not happen. - Fixed PCHPDBFLAGS causing a deprecation warning on MSVC v8 and later when using PCHs and PDBs together. + From Richard West: - Added nested / namespace tool support - Added a small fix to the python3 tool loader when loading a tool as a package @@ -104,6 +105,9 @@ may cause rebuilds. In no case should rebuilds not happen. tools, must now include the ar tool to get this builder as is required for other compiler tools. - Add clang and clang++ tools based on Paweł Tomulik's work. + + From Tom Tanner: + - Allow nested $( ... $) sections RELEASE 2.5.1 - Mon, 03 Nov 2016 13:37:42 -0400 diff --git a/src/engine/SCons/ActionTests.py b/src/engine/SCons/ActionTests.py index 9d856c9..2398c10 100644 --- a/src/engine/SCons/ActionTests.py +++ b/src/engine/SCons/ActionTests.py @@ -1241,8 +1241,8 @@ class CommandActionTestCase(unittest.TestCase): (env["foo"], env["bar"]) # The number 1 is there to make sure all args get converted to strings. - a = SCons.Action.CommandAction(["|", "$(", "$foo", "|", "$bar", - "$)", "|", "$baz", 1]) + a = SCons.Action.CommandAction(["|", "$(", "$foo", "|", "$(", "$bar", + "$)", "stuff", "$)", "|", "$baz", 1]) c = a.get_contents(target=[], source=[], env=Environment(foo = 'FFF', bar = 'BBB', baz = CmdGen)) @@ -1257,7 +1257,7 @@ class CommandActionTestCase(unittest.TestCase): c = a.get_contents(target=DummyNode('ttt'), source = DummyNode('sss'), env=SpecialEnvironment(foo = 'GGG', bar = 'CCC', baz = 'ZZZ')) - assert c == b'subst_target_source: | $( $foo | $bar $) | $baz 1', c + assert c == b'subst_target_source: | $( $foo | $( $bar $) stuff $) | $baz 1', c # We've discussed using the real target and source names in a # CommandAction's signature contents. This would have have the diff --git a/src/engine/SCons/Subst.py b/src/engine/SCons/Subst.py index 9aa4bbc..a68b54d 100644 --- a/src/engine/SCons/Subst.py +++ b/src/engine/SCons/Subst.py @@ -338,24 +338,28 @@ SUBST_RAW = 1 SUBST_SIG = 2 _rm = re.compile(r'\$[()]') -_remove = re.compile(r'\$\([^\$]*(\$[^\)][^\$]*)*\$\)') +_rm_split = re.compile(r'(\$[()])') # Indexed by the SUBST_* constants above. -_regex_remove = [ _rm, None, _remove ] +_regex_remove = [ _rm, None, _rm_split ] def _rm_list(list): return [l for l in list if not l in ('$(', '$)')] def _remove_list(list): result = [] - do_append = result.append + depth = 0 for l in list: if l == '$(': - do_append = lambda x: None + depth += 1 elif l == '$)': - do_append = result.append - else: - do_append(l) + depth -= 1 + if depth < 0: + break + elif depth == 0: + result.append(l) + if depth != 0: + return None return result # Indexed by the SUBST_* constants above. @@ -562,12 +566,19 @@ def scons_subst(strSubst, env, mode=SUBST_RAW, target=None, source=None, gvars={ except KeyError: pass + res = result if is_String(result): # Remove $(-$) pairs and any stuff in between, # if that's appropriate. remove = _regex_remove[mode] if remove: - result = remove.sub('', result) + if mode == SUBST_SIG: + result = _list_remove[mode](remove.split(result)) + if result is None: + raise SCons.Errors.UserError("Unbalanced $(/$) in: " + res) + result = ' '.join(result) + else: + result = remove.sub('', result) if mode != SUBST_RAW: # Compress strings of white space characters into # a single space. @@ -576,6 +587,8 @@ def scons_subst(strSubst, env, mode=SUBST_RAW, target=None, source=None, gvars={ remove = _list_remove[mode] if remove: result = remove(result) + if result is None: + raise SCons.Errors.UserError("Unbalanced $(/$) in: " + str(res)) return result diff --git a/src/engine/SCons/SubstTests.py b/src/engine/SCons/SubstTests.py index c11f247..6604128 100644 --- a/src/engine/SCons/SubstTests.py +++ b/src/engine/SCons/SubstTests.py @@ -183,6 +183,9 @@ class SubstTestCase(unittest.TestCase): 'HHH' : 'III', 'FFFIII' : 'BADNEWS', + 'THING1' : "$(STUFF$)", + 'THING2' : "$THING1", + 'LITERAL' : TestLiteral("$XXX"), # Test that we can expand to and return a function. @@ -405,6 +408,11 @@ class scons_subst_TestCase(SubstTestCase): "test", "test", + "test $( $THING2 $)", + "test $( $(STUFF$) $)", + "test STUFF", + "test", + "$AAA ${AAA}A $BBBB $BBB", "a aA b", "a aA b", @@ -544,6 +552,23 @@ class scons_subst_TestCase(SubstTestCase): else: raise AssertionError("did not catch expected UserError") + def test_subst_balance_errors(self): + """Test scons_subst(): handling syntax errors""" + env = DummyEnv(self.loc) + try: + scons_subst('$(', env, mode=SUBST_SIG) + except SCons.Errors.UserError as e: + assert str(e) == "Unbalanced $(/$) in: $(", str(e) + else: + raise AssertionError("did not catch expected UserError") + + try: + scons_subst('$)', env, mode=SUBST_SIG) + except SCons.Errors.UserError as e: + assert str(e) == "Unbalanced $(/$) in: $)", str(e) + else: + raise AssertionError("did not catch expected UserError") + def test_subst_type_errors(self): """Test scons_subst(): handling type errors""" env = DummyEnv(self.loc) |