From 887a56f8cc05902f89ea2c02526004cc17e9031b Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Mon, 7 Oct 2019 16:56:29 +0200 Subject: [PATCH] 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 Reviewed-by: Qt CMake Build Bot --- util/cmake/pro2cmake.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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