diff options
author | William Deegan <bill@baddogconsulting.com> | 2017-10-01 22:41:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-01 22:41:06 (GMT) |
commit | c3892dc18fbfff134b83710100c73e63abd6ed25 (patch) | |
tree | 4a8006806329a4ca1f1549c0c817f79b88e292ff | |
parent | 0276cfb016096f44f257d8cc58804c1fec7af54b (diff) | |
parent | f7a846e6c44b3ae20f8575c9823fc7cbe6d920d7 (diff) | |
download | SCons-c3892dc18fbfff134b83710100c73e63abd6ed25.zip SCons-c3892dc18fbfff134b83710100c73e63abd6ed25.tar.gz SCons-c3892dc18fbfff134b83710100c73e63abd6ed25.tar.bz2 |
Merge pull request #4 from bdbaddog/fix_subst_escaping_noah
Fix subst escaping Reported by Noah Hoffman echo "$$(abc)" > blah yielded exception
-rw-r--r-- | src/CHANGES.txt | 6 | ||||
-rw-r--r-- | src/engine/SCons/Subst.py | 17 | ||||
-rw-r--r-- | src/engine/SCons/SubstTests.py | 4 |
3 files changed, 25 insertions, 2 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 0e742ec..3b717ff 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -15,6 +15,12 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER - Fixed a regression in scons-3.0.0 where "from __future__ import print_function" was imposed on the scope where SConstruct is executed, breaking existing builds using PY 2.7. + From William Deegan: + - Fix broken subst logic where a string with "$$(abc)" was being treated as "$(abc) and the + logic for removing the signature escapes was then failing because there was no closing "$)". + This was introduced by a pull request to allow recursive variable evaluations to yield a string + such as "$( $( some stuff $) $)". + RELEASE 3.0.0 - Mon, 18 Sep 2017 08:32:04 -0700 NOTE: This is a major release. You should expect that some targets may rebuild when upgrading. diff --git a/src/engine/SCons/Subst.py b/src/engine/SCons/Subst.py index a68b54d..68d247f 100644 --- a/src/engine/SCons/Subst.py +++ b/src/engine/SCons/Subst.py @@ -338,7 +338,10 @@ SUBST_RAW = 1 SUBST_SIG = 2 _rm = re.compile(r'\$[()]') -_rm_split = re.compile(r'(\$[()])') + +# Note the pattern below only matches $( or $) when there is no +# preceeding $. (Thus the (?<!\$)) +_rm_split = re.compile(r'(?<!\$)(\$[()])') # Indexed by the SUBST_* constants above. _regex_remove = [ _rm, None, _rm_split ] @@ -437,7 +440,11 @@ def scons_subst(strSubst, env, mode=SUBST_RAW, target=None, source=None, gvars={ if s0 != '$': return s if s1 == '$': - return '$' + # In this case keep the double $'s which we'll later + # swap for a single dollar sign as we need to retain + # this information to properly avoid matching "$("" when + # the actual text was "$$("" (or "$)"" when "$$)"" ) + return '$$' elif s1 in '()': return s else: @@ -583,6 +590,12 @@ def scons_subst(strSubst, env, mode=SUBST_RAW, target=None, source=None, gvars={ # Compress strings of white space characters into # a single space. result = _space_sep.sub(' ', result).strip() + + # Now replace escaped $'s currently "$$" + # This is needed because we now retain $$ instead of + # replacing them during substition to avoid + # improperly trying to escape "$$(" as being "$(" + result = result.replace('$$','$') elif is_Sequence(result): remove = _list_remove[mode] if remove: diff --git a/src/engine/SCons/SubstTests.py b/src/engine/SCons/SubstTests.py index 6604128..fcd77df 100644 --- a/src/engine/SCons/SubstTests.py +++ b/src/engine/SCons/SubstTests.py @@ -336,6 +336,10 @@ class scons_subst_TestCase(SubstTestCase): # Test double-dollar-sign behavior. "$$FFF$HHH", "$FFFIII", + # Test double-dollar-sign before open paren. It's not meant + # to be signature escaping + 'echo $$(pwd) > XYZ', 'echo $(pwd) > XYZ', + # Test that a Literal will stop dollar-sign substitution. "$XXX $LITERAL $FFF", "GGG $XXX GGG", |