diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2019-02-13 13:04:45 +0100 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@qt.io> | 2019-02-28 08:06:49 +0000 |
commit | eb832cb00ae231d31052e885d4482e34aeb2640d (patch) | |
tree | b45dcd132c1a47a7db2415145d8b198244006057 | |
parent | 951e297362917675f605154ff6da89fb1acb3d40 (diff) |
CMake: pro2cmake.py: Handle complex conditions
Change-Id: Ifb047e5736f1831ddbd65b210e760c2729378334
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rwxr-xr-x | util/cmake/pro2cmake.py | 19 | ||||
-rw-r--r-- | util/cmake/tests/data/complex_condition.pro | 4 | ||||
-rwxr-xr-x | util/cmake/tests/test_parsing.py | 14 |
3 files changed, 29 insertions, 8 deletions
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 + |