diff options
-rwxr-xr-x | util/cmake/pro2cmake.py | 24 | ||||
-rw-r--r-- | util/cmake/tests/data/value_function.pro | 2 | ||||
-rwxr-xr-x | util/cmake/tests/test_parsing.py | 7 |
3 files changed, 31 insertions, 2 deletions
diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index 3ebb6c7e1c..8e5e830783 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -278,6 +278,20 @@ def handle_vpath(source: str, base_dir: str, vpath: typing.List[str]) -> str: return '{}-NOTFOUND'.format(source) +def handle_function_value(group: pp.ParseResults): + function_name = group[0] + function_args = group[1] + if function_name == 'qtLibraryTarget': + if len(function_args) > 1: + raise RuntimeError('Don\'t know what to with more than one function argument for $$qtLibraryTarget().') + return str(function_args[0]) + + if function_name == 'quote': + # Do nothing, just return a string result + return str(group) + + raise RuntimeError('No logic to handle function "{}", please add one in handle_function_value().'.format(function_name)) + class Operation: def __init__(self, value: typing.Union[typing.List[str], str]): if isinstance(value, list): @@ -751,9 +765,8 @@ class Scope(object): @property def TARGET(self) -> str: - return self.get_string('TARGET') \ + return self.expandString('TARGET') \ or os.path.splitext(os.path.basename(self.file))[0] - @property def _INCLUDED(self) -> typing.List[str]: return self.get('_INCLUDED') @@ -808,10 +821,17 @@ class QmakeParser: pp.Combine(pp.OneOrMore(Substitution | LiteralValuePart | pp.Literal('$')))) + FunctionValue \ + = add_element('FunctionValue', + pp.Group(pp.Suppress(pp.Literal('$') + pp.Literal('$')) + + Identifier + + pp.nestedExpr() #.setParseAction(lambda s, l, t: ['(', *t[0], ')']) + ).setParseAction(lambda s, l, t: handle_function_value(*t))) Value \ = add_element('Value', pp.NotAny(Else | pp.Literal('}') | EOL) \ + (pp.QuotedString(quoteChar='"', escChar='\\') + | FunctionValue | SubstitutionValue | BracedValue)) diff --git a/util/cmake/tests/data/value_function.pro b/util/cmake/tests/data/value_function.pro new file mode 100644 index 0000000000..598e4fadbd --- /dev/null +++ b/util/cmake/tests/data/value_function.pro @@ -0,0 +1,2 @@ +TARGET = Dummy +TARGET = $$qtLibraryTarget($$TARGET) diff --git a/util/cmake/tests/test_parsing.py b/util/cmake/tests/test_parsing.py index f924b13913..4019836ae1 100755 --- a/util/cmake/tests/test_parsing.py +++ b/util/cmake/tests/test_parsing.py @@ -343,3 +343,10 @@ def test_multi_condition_divided_by_lc(): def test_nested_function_calls(): result = parse_file(_tests_path + '/data/nested_function_calls.pro') assert len(result) == 1 + +def test_value_function(): + result = parse_file(_tests_path + '/data/value_function.pro') + target = result[0]['value'][0] + assert target == 'Dummy' + value = result[1]['value'] + assert value[0] == '$$TARGET' |