diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-05-23 11:53:41 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-05-23 14:17:46 +0000 |
commit | 6dfeb81bcb05360e83a55b519886014c55e8e771 (patch) | |
tree | 4b863091f50783179f9e97c3d09b7047ca44f52d /util | |
parent | 80271e82807b4ac51d158398d08554925b9fcdd5 (diff) |
Improve qmake syntax parser in pro2cmake.py
Some qtdeclarative pro files caused exceptions when trying to parse
them using the script. This included the following:
- handling conditions divided by newlines and backslashes
- handling conditions that have no scope
The parser has been fixed to deal with those cases and relevant
tests were added.
After the change, all qtdeclarative project files are parseable by
the script.
Change-Id: Ib9736423f7fb3bcc1944b26cfb3114306b4db9a7
Reviewed-by: Qt CMake Build Bot
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
Diffstat (limited to 'util')
-rwxr-xr-x | util/cmake/pro2cmake.py | 25 | ||||
-rw-r--r-- | util/cmake/tests/data/condition_without_scope.pro | 2 | ||||
-rw-r--r-- | util/cmake/tests/data/multi_condition_divided_by_lc.pro | 3 | ||||
-rw-r--r-- | util/cmake/tests/data/nested_function_calls.pro | 2 | ||||
-rwxr-xr-x | util/cmake/tests/test_parsing.py | 15 |
5 files changed, 41 insertions, 6 deletions
diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index ea68b57a19..fbf153b057 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -794,13 +794,26 @@ class QmakeParser: + 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)) + + ConditionPart1 = (pp.Optional('!') + Identifier + pp.Optional(BracedValue)) + ConditionPart2 = pp.CharsNotIn('#{}|:=\\\n') + ConditionPart = (ConditionPart1 ^ ConditionPart2) + pp.Optional(LC) + ConditionEnd + + ConditionOp = pp.Literal('|') ^ pp.Literal(':') + ConditionLC = pp.Suppress(pp.Optional(pp.White(' ') + LC + pp.White(' '))) + + ConditionRepeated = pp.ZeroOrMore((ConditionOp) + ConditionLC + ConditionPart) + + Condition = pp.Combine(ConditionPart + ConditionRepeated) Condition.setParseAction(lambda x: ' '.join(x).strip().replace(':', ' && ').strip(' && ')) + # Weird thing like write_file(a)|error() where error() is the alternative condition + # which happens to be a function call. In this case there is no scope, but our code expects + # a scope with a list of statements, so create a fake empty statement. + ConditionEndingInFunctionCall = pp.Suppress(ConditionOp) + FunctionCall \ + + pp.Empty().setParseAction(lambda x: [[]])\ + .setResultsName('statements') + SingleLineScope = pp.Suppress(pp.Literal(':')) + pp.Optional(LC) \ + pp.Group(Block | (Statement + EOL))('statements') MultiLineScope = pp.Optional(LC) + Block('statements') @@ -811,7 +824,7 @@ class QmakeParser: ElseBranch = pp.Suppress(Else) + (SingleLineElse | MultiLineElse) Scope <<= pp.Optional(LC) \ + pp.Group(Condition('condition') \ - + (SingleLineScope | MultiLineScope) \ + + (SingleLineScope | MultiLineScope | ConditionEndingInFunctionCall) \ + pp.Optional(ElseBranch)('else_statements')) if debug: diff --git a/util/cmake/tests/data/condition_without_scope.pro b/util/cmake/tests/data/condition_without_scope.pro new file mode 100644 index 0000000000..2aa1237c12 --- /dev/null +++ b/util/cmake/tests/data/condition_without_scope.pro @@ -0,0 +1,2 @@ +write_file("a", contents)|error() + diff --git a/util/cmake/tests/data/multi_condition_divided_by_lc.pro b/util/cmake/tests/data/multi_condition_divided_by_lc.pro new file mode 100644 index 0000000000..23254231df --- /dev/null +++ b/util/cmake/tests/data/multi_condition_divided_by_lc.pro @@ -0,0 +1,3 @@ +equals(a): \ + greaterThan(a):flags += 1 + diff --git a/util/cmake/tests/data/nested_function_calls.pro b/util/cmake/tests/data/nested_function_calls.pro new file mode 100644 index 0000000000..5ecc53f1cc --- /dev/null +++ b/util/cmake/tests/data/nested_function_calls.pro @@ -0,0 +1,2 @@ +requires(qtConfig(dlopen)) + diff --git a/util/cmake/tests/test_parsing.py b/util/cmake/tests/test_parsing.py index c8feeb1811..11d1ed093f 100755 --- a/util/cmake/tests/test_parsing.py +++ b/util/cmake/tests/test_parsing.py @@ -309,3 +309,18 @@ def test_realworld_lc(): def test_realworld_lc_with_comment_in_between(): result = parse_file(_tests_path + '/data/lc_with_comment.pro') assert len(result) == 6 + + +def test_condition_without_scope(): + result = parse_file(_tests_path + '/data/condition_without_scope.pro') + assert len(result) == 1 + + +def test_multi_condition_divided_by_lc(): + result = parse_file(_tests_path + '/data/multi_condition_divided_by_lc.pro') + assert len(result) == 1 + + +def test_nested_function_calls(): + result = parse_file(_tests_path + '/data/nested_function_calls.pro') + assert len(result) == 1 |