summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeander Beernaert <leander.beernaert@qt.io>2019-08-08 13:21:23 +0200
committerLeander Beernaert <leander.beernaert@qt.io>2019-08-08 13:03:28 +0000
commit5d7bb2e4f084908a0e807ff8b0105f231bf74298 (patch)
tree2d95ad2396233d1c63d854c0a6edd127fb85d794
parent6396840182dd80518493c66fe025a4f032954dbd (diff)
Add support for converting qtTargetLibrary() value assignments
Add support to pro2cmake to handle variable assignments via functions, e.g: TARGET = $$qtTargetLibrary($$TARGET). The evalulation of the functions happens during parsing and is very rudementary in nature. Currently it only covers the qtTargetLibrary(), required for certain projects, and quote(), required for passing unit tests. If we run into any unhanlded function an exception will be thrown. This patch also changes the TARGET property on Scope to expand the value. Change-Id: I678b7058067348a3972944bdba110f556cf22447 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> Reviewed-by: Qt CMake Build Bot
-rwxr-xr-xutil/cmake/pro2cmake.py24
-rw-r--r--util/cmake/tests/data/value_function.pro2
-rwxr-xr-xutil/cmake/tests/test_parsing.py7
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'