diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-08-12 15:53:06 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-08-13 15:47:55 +0100 |
commit | 5226f46342cae47cb96fafb725dc082ef206f9e8 (patch) | |
tree | f48ab32e3419d2a947e2309c5a4981dbd85abc8c /bitbake/lib/bb/parse/parse_py/BBHandler.py | |
parent | 36f98fc1f27015a1724f1677495227927341b0ff (diff) | |
download | poky-5226f46342cae47cb96fafb725dc082ef206f9e8.tar.gz |
bitbake: BBHandler/ast: Improve addtask handling
The recent addtask improvement to handle comments complicated the regex significantly
and there are already a number of corner cases in that code which aren't handled well.
Instead of trying to complicate the regex further, switch to code logic instead. This
means the following cases are now handled:
* addtask with multiple task names
* addtask with multiple before constraints
* addtask with multiple after constraints
The testcase is updated to match the improvements.
(Bitbake rev: 417016b83c21fca7616b2ee768d5d08e1edd1e06)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/parse/parse_py/BBHandler.py')
-rw-r--r-- | bitbake/lib/bb/parse/parse_py/BBHandler.py | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/bitbake/lib/bb/parse/parse_py/BBHandler.py b/bitbake/lib/bb/parse/parse_py/BBHandler.py index c1653faeee..4bdb11994f 100644 --- a/bitbake/lib/bb/parse/parse_py/BBHandler.py +++ b/bitbake/lib/bb/parse/parse_py/BBHandler.py | |||
@@ -23,7 +23,7 @@ __func_start_regexp__ = re.compile(r"(((?P<py>python(?=(\s|\()))|(?P<fr>faker | |||
23 | __inherit_regexp__ = re.compile(r"inherit\s+(.+)" ) | 23 | __inherit_regexp__ = re.compile(r"inherit\s+(.+)" ) |
24 | __inherit_def_regexp__ = re.compile(r"inherit_defer\s+(.+)" ) | 24 | __inherit_def_regexp__ = re.compile(r"inherit_defer\s+(.+)" ) |
25 | __export_func_regexp__ = re.compile(r"EXPORT_FUNCTIONS\s+(.+)" ) | 25 | __export_func_regexp__ = re.compile(r"EXPORT_FUNCTIONS\s+(.+)" ) |
26 | __addtask_regexp__ = re.compile(r"addtask\s+(?P<func>\w+)\s*((before\s*(?P<before>(([^#\n]*(?=after))|([^#\n]*))))|(after\s*(?P<after>(([^#\n]*(?=before))|([^#\n]*)))))*(?P<comment>#.*|.*?)") | 26 | __addtask_regexp__ = re.compile(r"addtask\s+([^#\n]+)(?P<comment>#.*|.*?)") |
27 | __deltask_regexp__ = re.compile(r"deltask\s+([^#\n]+)(?P<comment>#.*|.*?)") | 27 | __deltask_regexp__ = re.compile(r"deltask\s+([^#\n]+)(?P<comment>#.*|.*?)") |
28 | __addhandler_regexp__ = re.compile(r"addhandler\s+(.+)" ) | 28 | __addhandler_regexp__ = re.compile(r"addhandler\s+(.+)" ) |
29 | __def_regexp__ = re.compile(r"def\s+(\w+).*:" ) | 29 | __def_regexp__ = re.compile(r"def\s+(\w+).*:" ) |
@@ -239,29 +239,38 @@ def feeder(lineno, s, fn, root, statements, eof=False): | |||
239 | 239 | ||
240 | m = __addtask_regexp__.match(s) | 240 | m = __addtask_regexp__.match(s) |
241 | if m: | 241 | if m: |
242 | if len(m.group().split()) == 2: | 242 | after = "" |
243 | # Check and warn for "addtask task1 task2" | 243 | before = "" |
244 | m2 = re.match(r"addtask\s+(?P<func>\w+)(?P<ignores>.*)", s) | 244 | |
245 | if m2 and m2.group('ignores'): | 245 | # This code splits on 'before' and 'after' instead of on whitespace so we can defer |
246 | logger.warning('addtask ignored: "%s"' % m2.group('ignores')) | 246 | # evaluation to as late as possible. |
247 | 247 | tasks = m.group(1).split(" before ")[0].split(" after ")[0] | |
248 | # Check and warn for "addtask task1 before task2 before task3", the | 248 | |
249 | # similar to "after" | 249 | for exp in m.group(1).split(" before "): |
250 | taskexpression = s.split() | 250 | exp2 = exp.split(" after ") |
251 | for word in ('before', 'after'): | 251 | if len(exp2) > 1: |
252 | if taskexpression.count(word) > 1: | 252 | after = after + " ".join(exp2[1:]) |
253 | logger.warning("addtask contained multiple '%s' keywords, only one is supported" % word) | ||
254 | 253 | ||
255 | # Check and warn for having task with exprssion as part of task name | 254 | for exp in m.group(1).split(" after "): |
255 | exp2 = exp.split(" before ") | ||
256 | if len(exp2) > 1: | ||
257 | before = before + " ".join(exp2[1:]) | ||
258 | |||
259 | # Check and warn for having task with a keyword as part of task name | ||
260 | taskexpression = s.split() | ||
256 | for te in taskexpression: | 261 | for te in taskexpression: |
257 | if any( ( "%s_" % keyword ) in te for keyword in bb.data_smart.__setvar_keyword__ ): | 262 | if any( ( "%s_" % keyword ) in te for keyword in bb.data_smart.__setvar_keyword__ ): |
258 | raise ParseError("Task name '%s' contains a keyword which is not recommended/supported.\nPlease rename the task not to include the keyword.\n%s" % (te, ("\n".join(map(str, bb.data_smart.__setvar_keyword__)))), fn) | 263 | raise ParseError("Task name '%s' contains a keyword which is not recommended/supported.\nPlease rename the task not to include the keyword.\n%s" % (te, ("\n".join(map(str, bb.data_smart.__setvar_keyword__)))), fn) |
259 | ast.handleAddTask(statements, fn, lineno, m) | 264 | |
265 | if tasks is not None: | ||
266 | ast.handleAddTask(statements, fn, lineno, tasks, before, after) | ||
260 | return | 267 | return |
261 | 268 | ||
262 | m = __deltask_regexp__.match(s) | 269 | m = __deltask_regexp__.match(s) |
263 | if m: | 270 | if m: |
264 | ast.handleDelTask(statements, fn, lineno, m) | 271 | task = m.group(1) |
272 | if task is not None: | ||
273 | ast.handleDelTask(statements, fn, lineno, task) | ||
265 | return | 274 | return |
266 | 275 | ||
267 | m = __addhandler_regexp__.match(s) | 276 | m = __addhandler_regexp__.match(s) |