diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-05-17 14:56:11 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-05-17 13:31:03 +0000 |
commit | e0a6e9f3aa66da3018b8362d949e288a2c801daa (patch) | |
tree | ac649b4a270c3e48081267a500424974e868ec2d /util | |
parent | 14bf7e952e529f5656514295960fa050aa3a8e69 (diff) |
Fix parsing qmake assignments that have comments in between
For some reason the python comment regex that we used does not ignore
the line break at the end of a comment line.
This caused issues when parsing multi line assignments with comments
in between.
Use our own regex for comments to circumvent the issue. It was found
while trying to port the qtimageformats repo.
Added a pytest as well.
Change-Id: Ie4bbdac2d1e1c133bc787a995224d0bbd8238204
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
Diffstat (limited to 'util')
-rwxr-xr-x | util/cmake/pro2cmake.py | 7 | ||||
-rw-r--r-- | util/cmake/tests/data/lc_with_comment.pro | 4 | ||||
-rwxr-xr-x | util/cmake/tests/test_parsing.py | 4 |
3 files changed, 14 insertions, 1 deletions
diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index 5b6b3847d8..71053d288b 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -779,7 +779,12 @@ class QmakeParser: expr.setDebug() Grammar = StatementGroup('statements') - Grammar.ignore(pp.pythonStyleComment()) + + # Ignore comment lines, including the final line break, + # otherwise parsing fails when looking at multi line assignments + # with comments in between. + Comment = pp.Regex(r"#.*\n").setName("qmake style comment") + Grammar.ignore(Comment()) return Grammar diff --git a/util/cmake/tests/data/lc_with_comment.pro b/util/cmake/tests/data/lc_with_comment.pro new file mode 100644 index 0000000000..c087dadacc --- /dev/null +++ b/util/cmake/tests/data/lc_with_comment.pro @@ -0,0 +1,4 @@ +SUBDIRS = \ +# dds \ + tga \ + wbmp diff --git a/util/cmake/tests/test_parsing.py b/util/cmake/tests/test_parsing.py index 79ad0a4945..4b6f48b931 100755 --- a/util/cmake/tests/test_parsing.py +++ b/util/cmake/tests/test_parsing.py @@ -305,3 +305,7 @@ def test_realworld_lc(): result = parse_file(_tests_path + '/data/lc.pro') assert len(result) == 3 + +def test_realworld_lc_with_comment_in_between(): + result = parse_file(_tests_path + '/data/lc_with_comment.pro') + assert len(result) == 1 |