Skip to contentSkip to conversation

BBHandler: Handle comments in addtask/deltask

PATCH New Richard Purdie 1 participant 1 message Aug 6, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 BBHandler: Handle comments in addtask/deltask

Technically our syntax would allow for comments after an addtask/deltask. Currently these get silently processed in various ways by the code which is bad.

Tweak the regex to drop any comments and add test cases to ensure this continues to work in the future.

[YOCTO #15250]

---
 lib/bb/parse/parse_py/BBHandler.py |  4 ++--
 lib/bb/tests/parse.py              | 10 ++++++++++
 2 files changed, 12 insertions(+), 2 deletions(-)
lib/bb/parse/parse_py/BBHandler.py +2 -2
index c13e4b9755..c1653faeee 100644
@@ -23,8 +23,8 @@ __func_start_regexp__    = re.compile(r"(((?P<py>python(?=(\s|\()))|(?P<fr>faker
 __inherit_regexp__       = re.compile(r"inherit\s+(.+)" )
 __inherit_def_regexp__   = re.compile(r"inherit_defer\s+(.+)" )
 __export_func_regexp__   = re.compile(r"EXPORT_FUNCTIONS\s+(.+)" )
-__addtask_regexp__       = re.compile(r"addtask\s+(?P<func>\w+)\s*((before\s*(?P<before>((.*(?=after))|(.*))))|(after\s*(?P<after>((.*(?=before))|(.*)))))*")
-__deltask_regexp__       = re.compile(r"deltask\s+(.+)")
+__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>#.*|.*?)")
+__deltask_regexp__       = re.compile(r"deltask\s+([^#\n]+)(?P<comment>#.*|.*?)")
 __addhandler_regexp__    = re.compile(r"addhandler\s+(.+)" )
 __def_regexp__           = re.compile(r"def\s+(\w+).*:" )
 __python_func_regexp__   = re.compile(r"(\s+.*)|(^$)|(^#)" )
lib/bb/tests/parse.py +10 -0
index 72d1962e7e..d076fcc208 100644
@@ -179,6 +179,15 @@ python () {
 addtask do_patch after do_foo after do_unpack before do_configure before do_compile
 addtask do_fetch do_patch
 
+addtask do_myplaintask
+addtask do_myplaintask2
+deltask do_myplaintask2
+addtask do_mytask# comment
+addtask do_mytask2 # comment2
+addtask do_mytask3
+deltask do_mytask3# comment
+deltask do_mytask4 # comment2
+
 MYVAR = "do_patch"
 EMPTYVAR = ""
 deltask do_fetch ${MYVAR} ${EMPTYVAR}
@@ -195,6 +204,7 @@ deltask ${EMPTYVAR}
         self.assertTrue("addtask contained multiple 'before' keywords" in output)
         self.assertTrue("addtask contained multiple 'after' keywords" in output)
         self.assertTrue('addtask ignored: " do_patch"' in output)
+        self.assertEqual(['do_myplaintask', 'do_mytask', 'do_mytask2'], d.getVar("__BBTASKS"))
         #self.assertTrue('dependent task do_foo for do_patch does not exist' in output)
 
     broken_multiline_comment = """