From 5c75f6a21aba9192743f060768c9f185708d4b64 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Tue, 27 Aug 2019 19:15:36 +0200 Subject: [PATCH] Fix some corner cases of condition mapping in pro2cmake no-png is an old unused scope that should be mapped to the png feature instead. Map contains(QT_CONFIG, shared) to correct variable check. Sympy doesn't like dashes in indentifiers, so replace all of them with a _dash_ token which will be replaced again at the end of the condition simplifying. When doing sympy preprocessing, fix mapping of target names that don't contain double colons. Change-Id: Id3d37800665c96505b7cbb1d80fdbed59c3ae9c0 Reviewed-by: Simon Hausmann --- util/cmake/pro2cmake.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index 3a17ea05d9f..2e80ef12fee 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -1016,7 +1016,9 @@ def map_condition(condition: str) -> str: condition) condition = re.sub(r'qtConfig\(opengl\.\*\)', r'QT_FEATURE_opengl', condition) condition = re.sub(r'^win\*$', r'win', condition) + condition = re.sub(r'^no-png$', r'NOT QT_FEATURE_png', condition) condition = re.sub(r'contains\(CONFIG, static\)', r'NOT QT_BUILD_SHARED_LIBS', condition) + condition = re.sub(r'contains\(QT_CONFIG,\w*shared\)', r'QT_BUILD_SHARED_LIBS', condition) def gcc_version_handler(match_obj: re.Match): operator = match_obj.group(1) @@ -1624,6 +1626,8 @@ def simplify_condition(condition: str) -> str: condition = condition.replace(' OR ', ' | ') condition = condition.replace(' ON ', ' true ') condition = condition.replace(' OFF ', ' false ') + # Replace dashes with a token + condition = condition.replace('-', '_dash_') # SymPy chokes on expressions that contain two tokens one next to # the other delimited by a space, which are not an operation. @@ -1633,7 +1637,9 @@ def simplify_condition(condition: str) -> str: # the expression, and thus simplify it. # Do this by replacing and keeping a map of conditions to single # token symbols. - pattern = re.compile(r'(TARGET [a-zA-Z]+::[a-zA-Z]+)') + # Support both target names without double colons, and with double + # colons. + pattern = re.compile(r'(TARGET [a-zA-Z]+(?:::[a-zA-Z]+)?)') target_symbol_mapping = {} all_target_conditions = re.findall(pattern, condition) for target_condition in all_target_conditions: @@ -1657,6 +1663,7 @@ def simplify_condition(condition: str) -> str: condition = condition.replace('|', 'OR') condition = condition.replace('True', 'ON') condition = condition.replace('False', 'OFF') + condition = condition.replace('_dash_', '-') except: # sympy did not like our input, so leave this condition alone: condition = input_condition