diff options
author | William Deegan <bill@baddogconsulting.com> | 2020-01-06 22:55:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-06 22:55:58 (GMT) |
commit | f98705588b32c84c918b2e0013cc2fa630d71f37 (patch) | |
tree | 515e5f35a1323f1567a3f91f2b0dc347f06e5203 /src/engine/SCons | |
parent | b9d927ddbfa0153bbece478def31d97486e164f3 (diff) | |
parent | 2ff7ea17b28e6962c48238550d77ec9cdd96c02c (diff) | |
download | SCons-f98705588b32c84c918b2e0013cc2fa630d71f37.zip SCons-f98705588b32c84c918b2e0013cc2fa630d71f37.tar.gz SCons-f98705588b32c84c918b2e0013cc2fa630d71f37.tar.bz2 |
Merge pull request #3518 from chasinglogic/subst-less-recursion
Prevent unnecessary recursion when value is already expanded
Diffstat (limited to 'src/engine/SCons')
-rw-r--r-- | src/engine/SCons/Subst.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/engine/SCons/Subst.py b/src/engine/SCons/Subst.py index 92aa52c..a1ef053 100644 --- a/src/engine/SCons/Subst.py +++ b/src/engine/SCons/Subst.py @@ -499,6 +499,21 @@ class ListSubber(collections.UserList): self.in_strip = None self.next_line() + def expanded(self, s): + """Determines if the string s requires further expansion. + + Due to the implementation of ListSubber expand will call + itself 2 additional times for an already expanded string. This + method is used to determine if a string is already fully + expanded and if so exit the loop early to prevent these + recursive calls. + """ + if not is_String(s) or isinstance(s, CmdStringHolder): + return False + + s = str(s) # in case it's a UserString + return _separate_args.findall(s) is None + def expand(self, s, lvars, within_list): """Expand a single "token" as necessary, appending the expansion to the current result. @@ -554,6 +569,12 @@ class ListSubber(collections.UserList): elif s is None: return + # If the string is already full expanded there's no + # need to continue recursion. + if self.expanded(s): + self.append(s) + return + # Before re-expanding the result, handle # recursive expansion by copying the local # variable dictionary and overwriting a null |