From eb832cb00ae231d31052e885d4482e34aeb2640d Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Wed, 13 Feb 2019 13:04:45 +0100 Subject: [PATCH] CMake: pro2cmake.py: Handle complex conditions Change-Id: Ifb047e5736f1831ddbd65b210e760c2729378334 Reviewed-by: Alexandru Croitor --- util/cmake/pro2cmake.py | 19 +++++++++++-------- util/cmake/tests/data/complex_condition.pro | 4 ++++ util/cmake/tests/test_parsing.py | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 util/cmake/tests/data/complex_condition.pro diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index eccf045559..9dbcac9fc4 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -546,9 +546,9 @@ class QmakeParser: = pp.Combine(pp.OneOrMore(Substitution | LiteralValuePart | pp.Literal('$'))) Value = pp.NotAny(Else | pp.Literal('}') | EOL | pp.Literal('\\')) \ - + (pp.QuotedString(quoteChar='"', escChar='\\') - | SubstitutionValue - | BracedValue) + + (pp.QuotedString(quoteChar='"', escChar='\\') + | SubstitutionValue + | BracedValue) Values = pp.ZeroOrMore(Value + pp.Optional(LC))('value') @@ -584,10 +584,12 @@ class QmakeParser: + StatementGroup + pp.Optional(LC | EOL) \ + pp.Suppress('}') + pp.Optional(LC | EOL) - ConditionEnd = pp.FollowedBy((pp.Optional(LC) + (pp.Literal(':') \ - | pp.Literal('{') \ - | pp.Literal('|')))) - ConditionPart = pp.CharsNotIn('#{}|:=\\\n') + pp.Optional(LC) + ConditionEnd + ConditionEnd = pp.FollowedBy((pp.Optional(pp.White()) + + pp.Optional(LC) + (pp.Literal(':') \ + | pp.Literal('{') \ + | pp.Literal('|')))) + ConditionPart = ((pp.Optional('!') + Identifier + pp.Optional(BracedValue)) \ + ^ pp.CharsNotIn('#{}|:=\\\n')) + pp.Optional(LC) + ConditionEnd Condition = pp.Combine(ConditionPart \ + pp.ZeroOrMore((pp.Literal('|') ^ pp.Literal(':')) \ + ConditionPart)) @@ -1172,7 +1174,8 @@ def write_main_part(cm_fh: typing.IO[str], name: str, typename: str, def write_module(cm_fh: typing.IO[str], scope: Scope, *, indent: int = 0) -> None: module_name = scope.TARGET - assert module_name.startswith('Qt') + if not module_name.startswith('Qt'): + print('XXXXXX Module name {} does not start with Qt!'.format(module_name)) extra = [] if 'static' in scope.get('CONFIG'): diff --git a/util/cmake/tests/data/complex_condition.pro b/util/cmake/tests/data/complex_condition.pro new file mode 100644 index 0000000000..bc3369bd63 --- /dev/null +++ b/util/cmake/tests/data/complex_condition.pro @@ -0,0 +1,4 @@ +!system("dbus-send --session --type=signal / local.AutotestCheck.Hello >$$QMAKE_SYSTEM_NULL_DEVICE 2>&1") { + SOURCES = dbus.cpp +} + diff --git a/util/cmake/tests/test_parsing.py b/util/cmake/tests/test_parsing.py index c238c80c08..f0c80f560e 100755 --- a/util/cmake/tests/test_parsing.py +++ b/util/cmake/tests/test_parsing.py @@ -260,3 +260,17 @@ def test_realworld_complex_assign(): assert len(result) == 1 validate_op('qmake-clean.commands', '+=', '( cd qmake && $(MAKE) clean ":-(==)-:" \'(Foo)\' )'.split(), result[0]) + + +def test_realworld_complex_condition(): + result = parse_file(_tests_path + '/data/complex_condition.pro') + assert len(result) == 1 + (cond, if_branch, else_branch) = evaluate_condition(result[0]) + assert cond == '!system("dbus-send --session --type=signal / ' \ + 'local.AutotestCheck.Hello >$$QMAKE_SYSTEM_NULL_DEVICE ' \ + '2>&1")' + assert len(if_branch) == 1 + validate_op('SOURCES', '=', ['dbus.cpp'], if_branch[0]) + + assert len(else_branch) == 0 +