diff options
-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 |