diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-07-01 17:52:52 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-07-04 22:52:36 +0100 |
commit | bc6d96e69684253a7236594cb0af2738be06b7a9 (patch) | |
tree | 808dd13032bcbecf4ecd62c5a493bfeda289ae57 | |
parent | 04467fb51c6816e7373e0bbbe983a97972c6312f (diff) | |
download | poky-bc6d96e69684253a7236594cb0af2738be06b7a9.tar.gz |
bitbake: ConfHandler/BBHandler: Improve comment error messages and add tests
Currently if you trigger one of the comment errors, the newline characters
are stripped and the line numbers are incorrect. In one case it prints
the empty line which is also unhelpful.
Rework the code around these errors so the line numbers are correct
and the lines in question are more clearly displayed complete with newlines
so the user can more clearly see the error.
I also added a couple of simplistic test cases to ensure that errors
are raised by the two known comment format errors.
[YOCTO #11904]
(Bitbake rev: 712da71b24445c814d79a206ce26188def8fce0a)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | bitbake/lib/bb/parse/parse_py/BBHandler.py | 4 | ||||
-rw-r--r-- | bitbake/lib/bb/parse/parse_py/ConfHandler.py | 9 | ||||
-rw-r--r-- | bitbake/lib/bb/tests/parse.py | 23 |
3 files changed, 32 insertions, 4 deletions
diff --git a/bitbake/lib/bb/parse/parse_py/BBHandler.py b/bitbake/lib/bb/parse/parse_py/BBHandler.py index ee9bd760ce..68415735fd 100644 --- a/bitbake/lib/bb/parse/parse_py/BBHandler.py +++ b/bitbake/lib/bb/parse/parse_py/BBHandler.py | |||
@@ -178,10 +178,10 @@ def feeder(lineno, s, fn, root, statements, eof=False): | |||
178 | 178 | ||
179 | if s and s[0] == '#': | 179 | if s and s[0] == '#': |
180 | if len(__residue__) != 0 and __residue__[0][0] != "#": | 180 | if len(__residue__) != 0 and __residue__[0][0] != "#": |
181 | bb.fatal("There is a comment on line %s of file %s (%s) which is in the middle of a multiline expression.\nBitbake used to ignore these but no longer does so, please fix your metadata as errors are likely as a result of this change." % (lineno, fn, s)) | 181 | bb.fatal("There is a comment on line %s of file %s:\n'''\n%s\n'''\nwhich is in the middle of a multiline expression. This syntax is invalid, please correct it." % (lineno, fn, s)) |
182 | 182 | ||
183 | if len(__residue__) != 0 and __residue__[0][0] == "#" and (not s or s[0] != "#"): | 183 | if len(__residue__) != 0 and __residue__[0][0] == "#" and (not s or s[0] != "#"): |
184 | bb.fatal("There is a confusing multiline, partially commented expression on line %s of file %s (%s).\nPlease clarify whether this is all a comment or should be parsed." % (lineno, fn, s)) | 184 | bb.fatal("There is a confusing multiline partially commented expression on line %s of file %s:\n%s\nPlease clarify whether this is all a comment or should be parsed." % (lineno - len(__residue__), fn, "\n".join(__residue__))) |
185 | 185 | ||
186 | if s and s[-1] == '\\': | 186 | if s and s[-1] == '\\': |
187 | __residue__.append(s[:-1]) | 187 | __residue__.append(s[:-1]) |
diff --git a/bitbake/lib/bb/parse/parse_py/ConfHandler.py b/bitbake/lib/bb/parse/parse_py/ConfHandler.py index 810b6011cf..451e68dd66 100644 --- a/bitbake/lib/bb/parse/parse_py/ConfHandler.py +++ b/bitbake/lib/bb/parse/parse_py/ConfHandler.py | |||
@@ -125,16 +125,21 @@ def handle(fn, data, include): | |||
125 | s = f.readline() | 125 | s = f.readline() |
126 | if not s: | 126 | if not s: |
127 | break | 127 | break |
128 | origlineno = lineno | ||
129 | origline = s | ||
128 | w = s.strip() | 130 | w = s.strip() |
129 | # skip empty lines | 131 | # skip empty lines |
130 | if not w: | 132 | if not w: |
131 | continue | 133 | continue |
132 | s = s.rstrip() | 134 | s = s.rstrip() |
133 | while s[-1] == '\\': | 135 | while s[-1] == '\\': |
134 | s2 = f.readline().rstrip() | 136 | line = f.readline() |
137 | origline += line | ||
138 | s2 = line.rstrip() | ||
135 | lineno = lineno + 1 | 139 | lineno = lineno + 1 |
136 | if (not s2 or s2 and s2[0] != "#") and s[0] == "#" : | 140 | if (not s2 or s2 and s2[0] != "#") and s[0] == "#" : |
137 | bb.fatal("There is a confusing multiline, partially commented expression on line %s of file %s (%s).\nPlease clarify whether this is all a comment or should be parsed." % (lineno, fn, s)) | 141 | bb.fatal("There is a confusing multiline, partially commented expression starting on line %s of file %s:\n%s\nPlease clarify whether this is all a comment or should be parsed." % (origlineno, fn, origline)) |
142 | |||
138 | s = s[:-1] + s2 | 143 | s = s[:-1] + s2 |
139 | # skip comments | 144 | # skip comments |
140 | if s[0] == '#': | 145 | if s[0] == '#': |
diff --git a/bitbake/lib/bb/tests/parse.py b/bitbake/lib/bb/tests/parse.py index 2898f9bb14..1a3b74934d 100644 --- a/bitbake/lib/bb/tests/parse.py +++ b/bitbake/lib/bb/tests/parse.py | |||
@@ -194,3 +194,26 @@ deltask ${EMPTYVAR} | |||
194 | self.assertTrue('addtask ignored: " do_patch"' in stdout) | 194 | self.assertTrue('addtask ignored: " do_patch"' in stdout) |
195 | #self.assertTrue('dependent task do_foo for do_patch does not exist' in stdout) | 195 | #self.assertTrue('dependent task do_foo for do_patch does not exist' in stdout) |
196 | 196 | ||
197 | broken_multiline_comment = """ | ||
198 | # First line of comment \\ | ||
199 | # Second line of comment \\ | ||
200 | |||
201 | """ | ||
202 | def test_parse_broken_multiline_comment(self): | ||
203 | f = self.parsehelper(self.broken_multiline_comment) | ||
204 | with self.assertRaises(bb.BBHandledException): | ||
205 | d = bb.parse.handle(f.name, self.d)[''] | ||
206 | |||
207 | |||
208 | comment_in_var = """ | ||
209 | VAR = " \\ | ||
210 | SOMEVAL \\ | ||
211 | # some comment \\ | ||
212 | SOMEOTHERVAL \\ | ||
213 | " | ||
214 | """ | ||
215 | def test_parse_comment_in_var(self): | ||
216 | f = self.parsehelper(self.comment_in_var) | ||
217 | with self.assertRaises(bb.BBHandledException): | ||
218 | d = bb.parse.handle(f.name, self.d)[''] | ||
219 | |||