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:
parent
04d6981702
commit
8512f5179d
@ -520,7 +520,6 @@ class QmakeParser:
|
||||
LC = pp.Suppress(pp.Literal('\\\n'))
|
||||
EOL = pp.Suppress(pp.Literal('\n'))
|
||||
Else = pp.Keyword('else')
|
||||
DefineTest = pp.Keyword('defineTest')
|
||||
Identifier = pp.Word(pp.alphas + '_', bodyChars=pp.alphanums+'_-./')
|
||||
BracedValue = pp.nestedExpr(ignoreExpr=pp.quotedString \
|
||||
| pp.QuotedString(quoteChar='$(',
|
||||
@ -560,17 +559,15 @@ class QmakeParser:
|
||||
Operation = Key('key') + pp.Optional(LC) \
|
||||
+ Op('operation') + pp.Optional(LC) \
|
||||
+ Values('value')
|
||||
CallArgs = pp.nestedExpr()
|
||||
CallArgs = pp.Optional(LC) + pp.nestedExpr()
|
||||
CallArgs.setParseAction(lambda x: ' '.join(chain(*x)))
|
||||
Load = pp.Keyword('load') + CallArgs('loaded')
|
||||
Include = pp.Keyword('include') + CallArgs('included')
|
||||
Option = pp.Keyword('option') + CallArgs('option')
|
||||
DefineTestDefinition = pp.Suppress(DefineTest + CallArgs \
|
||||
+ pp.nestedExpr(opener='{', closer='}')) # ignore the whole thing...
|
||||
ForLoop = pp.Suppress(pp.Keyword('for') + pp.nestedExpr()
|
||||
+ pp.nestedExpr(opener='{', closer='}',
|
||||
ignoreExpr=None)
|
||||
+ pp.LineEnd()) # ignore the whole thing...
|
||||
DefineTestDefinition = pp.Suppress(pp.Keyword('defineTest') + CallArgs
|
||||
+ pp.nestedExpr(opener='{', closer='}', ignoreExpr=pp.LineEnd())) # ignore the whole thing...
|
||||
ForLoop = pp.Suppress(pp.Keyword('for') + CallArgs
|
||||
+ pp.nestedExpr(opener='{', closer='}', ignoreExpr=pp.LineEnd())) # ignore the whole thing...
|
||||
FunctionCall = pp.Suppress(Identifier + pp.nestedExpr())
|
||||
|
||||
Scope = pp.Forward()
|
||||
@ -617,7 +614,7 @@ class QmakeParser:
|
||||
'Key Op Values Value BracedValue ' \
|
||||
'Scope Block ' \
|
||||
'StatementGroup StatementLine Statement '\
|
||||
'Load Include Option DefineTest ForLoop ' \
|
||||
'Load Include Option DefineTestDefinition ForLoop ' \
|
||||
'FunctionCall CallArgs Operation'.split():
|
||||
expr = locals()[ename]
|
||||
expr.setName(ename)
|
||||
|
11
util/cmake/tests/data/for.pro
Normal file
11
util/cmake/tests/data/for.pro
Normal 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)
|
||||
}
|
||||
}
|
@ -173,6 +173,13 @@ def test_definetest():
|
||||
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():
|
||||
result = parse_file(_tests_path + '/data/unset.pro')
|
||||
assert len(result) == 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user