From c3b79e79afd8dd15aaf6ca4a0a62fd30fcd2f11a Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Tue, 17 Sep 2019 10:39:13 +0200 Subject: [PATCH] pro2cmake: Handle nested lists in handle_function_value Needed to successfully parse qtconnectivity projects where there are expressions like: WINDOWS_SDK_VERSION = $$member($$list($$split(WINDOWS_SDK_VERSION_STRING, .)), 2) Also fix '$$member' to be handled in the function. Change-Id: I35b5cff8c39b3a35d485d1d72f5d668cccbe9b2f Reviewed-by: Simon Hausmann Reviewed-by: Qt CMake Build Bot --- util/cmake/pro2cmake.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index 24fcd85fd02..cea4e4259c4 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -41,6 +41,12 @@ import re import io import typing import glob +import collections + +try: + collectionsAbc = collections.abc +except AttributeError: + collectionsAbc = collections from sympy.logic import (simplify_logic, And, Or, Not,) import pyparsing as pp @@ -361,6 +367,15 @@ def handle_vpath(source: str, base_dir: str, vpath: typing.List[str]) -> str: return '{}-NOTFOUND'.format(source) +def flatten_list(l): + """ Flattens an irregular nested list into a simple list.""" + for el in l: + if isinstance(el, collectionsAbc.Iterable) and not isinstance(el, (str, bytes)): + yield from flatten_list(el) + else: + yield el + + def handle_function_value(group: pp.ParseResults): function_name = group[0] function_args = group[1] @@ -378,10 +393,13 @@ def handle_function_value(group: pp.ParseResults): raise RuntimeError('Don\'t know what to with more than one function argument for $$files().') return str(function_args[0]) + if isinstance(function_args, pp.ParseResults): + function_args = list(flatten_list(function_args.asList())) + # Return the whole expression as a string. if function_name in ['join', 'files', 'cmakeRelativePath', 'shell_quote', 'shadowed', 'cmakeTargetPath', 'shell_path', 'cmakeProcessLibs', 'cmakeTargetPaths', - 'cmakePortablePaths', 'escape_expand']: + 'cmakePortablePaths', 'escape_expand', 'member']: return 'join({})'.format(''.join(function_args))