From e0a6e9f3aa66da3018b8362d949e288a2c801daa Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Fri, 17 May 2019 14:56:11 +0200 Subject: [PATCH] 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 --- util/cmake/pro2cmake.py | 7 ++++++- util/cmake/tests/data/lc_with_comment.pro | 4 ++++ util/cmake/tests/test_parsing.py | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 util/cmake/tests/data/lc_with_comment.pro diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index 5b6b3847d8b..71053d288b7 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 00000000000..c087dadacc1 --- /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 79ad0a49454..4b6f48b931e 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