summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@qt.io>2019-02-27 15:31:29 +0100
committerTobias Hunger <tobias.hunger@qt.io>2019-02-28 08:08:30 +0000
commitf2e968b245e0428b75eecb0bb7244a0391e3b355 (patch)
tree91669c143ebc9102c683398909c45c90a02dd5e3
parent33fe56c630d9e59b2a33e28db5e062323d577d34 (diff)
CMake: pro2cmake.py: Handle for loops without block
Handle for loops with a single line of instructions and add a test for that. Change-Id: I041ae30f64abcbd3db7df29933647f047b92ede3 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rwxr-xr-xutil/cmake/pro2cmake.py4
-rw-r--r--util/cmake/tests/data/single_line_for.pro4
-rwxr-xr-xutil/cmake/tests/test_parsing.py6
3 files changed, 13 insertions, 1 deletions
diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py
index 1f76d9dedd..06d0c925d9 100755
--- a/util/cmake/pro2cmake.py
+++ b/util/cmake/pro2cmake.py
@@ -568,11 +568,13 @@ class QmakeParser:
+ 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...
+ ForLoopSingleLine = pp.Suppress(pp.Keyword('for') + CallArgs
+ + pp.Literal(':') + pp.SkipTo(EOL, ignore=LC)) # ignore the whole thing...
FunctionCall = pp.Suppress(Identifier + pp.nestedExpr())
Scope = pp.Forward()
- Statement = pp.Group(Load | Include | Option | ForLoop \
+ Statement = pp.Group(Load | Include | Option | ForLoop | ForLoopSingleLine \
| DefineTestDefinition | FunctionCall | Operation)
StatementLine = Statement + (EOL | pp.FollowedBy('}'))
StatementGroup = pp.ZeroOrMore(StatementLine | Scope | pp.Suppress(EOL))
diff --git a/util/cmake/tests/data/single_line_for.pro b/util/cmake/tests/data/single_line_for.pro
new file mode 100644
index 0000000000..806d08a49c
--- /dev/null
+++ b/util/cmake/tests/data/single_line_for.pro
@@ -0,0 +1,4 @@
+for(d, sd): \
+ exists($$d/$${d}.pro): \
+ SUBDIRS += $$d
+
diff --git a/util/cmake/tests/test_parsing.py b/util/cmake/tests/test_parsing.py
index dd4e5508f6..2f227e0ba2 100755
--- a/util/cmake/tests/test_parsing.py
+++ b/util/cmake/tests/test_parsing.py
@@ -180,6 +180,12 @@ def test_for():
assert result[1] == []
+def test_single_line_for():
+ result = parse_file(_tests_path + '/data/single_line_for.pro')
+ assert len(result) == 1
+ assert result[0] == []
+
+
def test_unset():
result = parse_file(_tests_path + '/data/unset.pro')
assert len(result) == 1