CMake: pro2cmake.py: Fix parsing of for loops

Ignore for loops in the pro2cmake.py parser and add a unit test for that.

Change-Id: I2a0c075c45cf56f4f24ada2d53e8e8e94ce19f26
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Tobias Hunger 2019-02-27 13:37:01 +01:00
parent 04d6981702
commit 8512f5179d
3 changed files with 24 additions and 9 deletions

View File

@ -520,7 +520,6 @@ class QmakeParser:
LC = pp.Suppress(pp.Literal('\\\n')) LC = pp.Suppress(pp.Literal('\\\n'))
EOL = pp.Suppress(pp.Literal('\n')) EOL = pp.Suppress(pp.Literal('\n'))
Else = pp.Keyword('else') Else = pp.Keyword('else')
DefineTest = pp.Keyword('defineTest')
Identifier = pp.Word(pp.alphas + '_', bodyChars=pp.alphanums+'_-./') Identifier = pp.Word(pp.alphas + '_', bodyChars=pp.alphanums+'_-./')
BracedValue = pp.nestedExpr(ignoreExpr=pp.quotedString \ BracedValue = pp.nestedExpr(ignoreExpr=pp.quotedString \
| pp.QuotedString(quoteChar='$(', | pp.QuotedString(quoteChar='$(',
@ -560,17 +559,15 @@ class QmakeParser:
Operation = Key('key') + pp.Optional(LC) \ Operation = Key('key') + pp.Optional(LC) \
+ Op('operation') + pp.Optional(LC) \ + Op('operation') + pp.Optional(LC) \
+ Values('value') + Values('value')
CallArgs = pp.nestedExpr() CallArgs = pp.Optional(LC) + pp.nestedExpr()
CallArgs.setParseAction(lambda x: ' '.join(chain(*x))) CallArgs.setParseAction(lambda x: ' '.join(chain(*x)))
Load = pp.Keyword('load') + CallArgs('loaded') Load = pp.Keyword('load') + CallArgs('loaded')
Include = pp.Keyword('include') + CallArgs('included') Include = pp.Keyword('include') + CallArgs('included')
Option = pp.Keyword('option') + CallArgs('option') Option = pp.Keyword('option') + CallArgs('option')
DefineTestDefinition = pp.Suppress(DefineTest + CallArgs \ DefineTestDefinition = pp.Suppress(pp.Keyword('defineTest') + CallArgs
+ pp.nestedExpr(opener='{', closer='}')) # ignore the whole thing... + pp.nestedExpr(opener='{', closer='}', ignoreExpr=pp.LineEnd())) # ignore the whole thing...
ForLoop = pp.Suppress(pp.Keyword('for') + pp.nestedExpr() ForLoop = pp.Suppress(pp.Keyword('for') + CallArgs
+ pp.nestedExpr(opener='{', closer='}', + pp.nestedExpr(opener='{', closer='}', ignoreExpr=pp.LineEnd())) # ignore the whole thing...
ignoreExpr=None)
+ pp.LineEnd()) # ignore the whole thing...
FunctionCall = pp.Suppress(Identifier + pp.nestedExpr()) FunctionCall = pp.Suppress(Identifier + pp.nestedExpr())
Scope = pp.Forward() Scope = pp.Forward()
@ -617,7 +614,7 @@ class QmakeParser:
'Key Op Values Value BracedValue ' \ 'Key Op Values Value BracedValue ' \
'Scope Block ' \ 'Scope Block ' \
'StatementGroup StatementLine Statement '\ 'StatementGroup StatementLine Statement '\
'Load Include Option DefineTest ForLoop ' \ 'Load Include Option DefineTestDefinition ForLoop ' \
'FunctionCall CallArgs Operation'.split(): 'FunctionCall CallArgs Operation'.split():
expr = locals()[ename] expr = locals()[ename]
expr.setName(ename) expr.setName(ename)

View File

@ -0,0 +1,11 @@
SOURCES = main.cpp
for (config, SIMD) {
uc = $$upper($$config)
DEFINES += QT_COMPILER_SUPPORTS_$${uc}
add_cflags {
cflags = QMAKE_CFLAGS_$${uc}
!defined($$cflags, var): error("This compiler does not support $${uc}")
QMAKE_CXXFLAGS += $$eval($$cflags)
}
}

View File

@ -173,6 +173,13 @@ def test_definetest():
assert result[0] == [] assert result[0] == []
def test_for():
result = parse_file(_tests_path + '/data/for.pro')
assert len(result) == 2
validate_op('SOURCES', '=', ['main.cpp'], result[0])
assert result[1] == []
def test_unset(): def test_unset():
result = parse_file(_tests_path + '/data/unset.pro') result = parse_file(_tests_path + '/data/unset.pro')
assert len(result) == 1 assert len(result) == 1