summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2019-10-07 16:56:29 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2019-10-07 22:44:55 +0000
commit887a56f8cc05902f89ea2c02526004cc17e9031b (patch)
tree11474c7a59d39d8b15aa0933ede9fbc7c5b32824 /util
parentdca364ed1999ff1d4d9aa08154802963445f6508 (diff)
pro2cmake: Handle parentheses in if() scopes better
The unwrap_if handler just removed the if keyword from a condition expression, and return the rest of the condition as-is. This proves not be enough, because map_condition splits on spaces and tries to map platform keywords, which would fail for values like "unix)". Change unwrap_if to add additional space between the values in the parentheses. Change-Id: I769ab430363d008a9fd91eaba014c88bd5ee43bd Reviewed-by: Simon Hausmann <simon.hausmann@qt.io> Reviewed-by: Qt CMake Build Bot
Diffstat (limited to 'util')
-rwxr-xr-xutil/cmake/pro2cmake.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py
index e55f703930..fec4eed19d 100755
--- a/util/cmake/pro2cmake.py
+++ b/util/cmake/pro2cmake.py
@@ -1491,7 +1491,20 @@ def parseProFile(file: str, *, debug=False):
def unwrap_if(input_string):
# Compute the grammar only once.
if not hasattr(unwrap_if, "if_grammar"):
+ def handle_expr_with_parentheses(s, l, t):
+ # The following expression unwraps the condition via the
+ # additional info set by originalTextFor, thus returning the
+ # condition without parentheses.
+ condition_without_parentheses = s[t._original_start + 1 : t._original_end - 1]
+
+ # Re-add the parentheses, but with spaces in-between. This
+ # fixes map_condition -> map_platform to apply properly.
+ condition_with_parentheses = "( " + condition_without_parentheses + " )"
+ return condition_with_parentheses
+
expr_with_parentheses = pp.originalTextFor(pp.nestedExpr())
+ expr_with_parentheses.setParseAction(handle_expr_with_parentheses)
+
if_keyword = pp.Suppress(pp.Keyword("if"))
unwrap_if.if_grammar = if_keyword + expr_with_parentheses