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
This commit is contained in:
parent
6396840182
commit
5d7bb2e4f0
@ -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))
|
||||
|
||||
|
2
util/cmake/tests/data/value_function.pro
Normal file
2
util/cmake/tests/data/value_function.pro
Normal file
@ -0,0 +1,2 @@
|
||||
TARGET = Dummy
|
||||
TARGET = $$qtLibraryTarget($$TARGET)
|
@ -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'
|
||||
|
Loading…
x
Reference in New Issue
Block a user