Skip to contentSkip to conversation

build: Catch and error upon circular task references

PATCH In review Richard Purdie 2 participants 7 messages Sep 10, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 build: Catch and error upon circular task references

If there are circular task references, error on them rather than show a recursion error. A simple reproducer is:

"""

do_packageswu () {
       :
}

addtask do_packageswu after do_image_complete before do_image_qa """

into image_types.bbclass. There is code in runqueue to detect these but we never get that far with the current codebase.

[YOCTO #13140]

---
 lib/bb/build.py | 2 ++
 1 file changed, 2 insertions(+)
lib/bb/build.py +2 -0
index 1e062adb51..4249c0be2b 100644
@@ -1034,6 +1034,8 @@ def tasksbetween(task_start, task_end, d):
     def follow_chain(task, endtask, chain=None):
         if not chain:
             chain = []
+        if task in chain:
+            bb.fatal("Circular task dependencies as %s depends itself via the chain %s" % (task, " -> ".join(chain)))
         chain.append(task)
         for othertask in tasks:
             if othertask == task:
Signature · 1 line
2.32.0
#1 lore raw

PATCH 2/3 data_smart: Improve error display for handled exceptions

We don't need tracebacks for BBHandledException. Reduces confusing output like:

ERROR: /meta/recipes-core/images/core-image-tiny-initramfs.bb: Circular task dependencies as do_image_complete depends itself via the chain do_image_complete -> do_packageswu -> do_image_qa -> do_image -> do_image_cpio
ERROR: ExpansionError during parsing /meta/recipes-core/images/core-image-tiny-initramfs.bb
Traceback (most recent call last):
File "/bitbake/lib/bb/build.py", line 1050, in follow_chain(task='do_image_qa', endtask='do_build', chain=['do_image_complete', 'do_packageswu', 'do_image_qa', 'do_image', 'do_image_cpio']):
if task in deps:
> follow_chain(othertask, endtask, chain)
chain.pop()
File "/bitbake/lib/bb/build.py", line 1050, in follow_chain(task='do_image', endtask='do_build', chain=['do_image_complete', 'do_packageswu', 'do_image_qa', 'do_image', 'do_image_cpio']):
if task in deps:
> follow_chain(othertask, endtask, chain)
chain.pop()
File "/bitbake/lib/bb/build.py", line 1050, in follow_chain(task='do_image_cpio', endtask='do_build', chain=['do_image_complete', 'do_packageswu', 'do_image_qa', 'do_image', 'do_image_cpio']):
if task in deps:
> follow_chain(othertask, endtask, chain)
chain.pop()
File "/bitbake/lib/bb/build.py", line 1038, in follow_chain(task='do_image_complete', endtask='do_build', chain=['do_image_complete', 'do_packageswu', 'do_image_qa', 'do_image', 'do_image_cpio']):
if task in chain:
> bb.fatal("Circular task dependencies as %s depends itself via the chain %s?!" % (task, " -> ".join(chain)))
chain.append(task)
File "/bitbake/lib/bb/__init__.py", line 165, in fatal:
mainlogger.critical(''.join(args), extra=kwargs)
> raise BBHandledException()

to the real error:

ERROR: /media/build1/poky/meta/recipes-core/images/core-image-tiny-initramfs.bb: Circular task dependencies as do_image_complete depends itself via the chain do_image_complete -> do_packageswu -> do_image_qa -> do_image -> do_image_cpio

---
 lib/bb/data_smart.py | 2 ++
 1 file changed, 2 insertions(+)
lib/bb/data_smart.py +2 -0
index 515d195fe8..e4afac64b2 100644
@@ -418,6 +418,8 @@ class DataSmart(MutableMapping):
                 raise
             except bb.parse.SkipRecipe:
                 raise
+            except bb.BBHandledException:
+                raise
             except Exception as exc:
                 tb = sys.exc_info()[2]
                 raise ExpansionError(varname, s, exc).with_traceback(tb) from exc
Signature · 1 line
2.32.0
#2 lore raw

PATCH 3/3 fetch2: Add recursion guard

In reply to Richard Purdie

Users sometimes put ${S} references in ${SRC_URI} without realising this can be problematic. Improve the error messages if they accidentally do.

[YOCTO #11593]

---
 lib/bb/fetch2/__init__.py | 7 +++++++
 1 file changed, 7 insertions(+)
lib/bb/fetch2/__init__.py +7 -0
index 47a4943369..d9e1599a05 100644
@@ -754,6 +754,11 @@ def get_srcrev(d, method_name='sortable_revision'):
     that fetcher provides a method with the given name and the same signature as sortable_revision.
     """
 
+    recursion = d.getVar("__BBINSRCREV")
+    if recursion:
+        raise FetchError("There are recursive references in fetcher variables, likely through SRC_URI")
+    d.setVar("__BBINSRCREV", True)
+
     scms = []
     fetcher = Fetch(d.getVar('SRC_URI').split(), d)
     urldata = fetcher.ud
@@ -768,6 +773,7 @@ def get_srcrev(d, method_name='sortable_revision'):
         autoinc, rev = getattr(urldata[scms[0]].method, method_name)(urldata[scms[0]], d, urldata[scms[0]].names[0])
         if len(rev) > 10:
             rev = rev[:10]
+        d.delVar("__BBINSRCREV")
         if autoinc:
             return "AUTOINC+" + rev
         return rev
@@ -802,6 +808,7 @@ def get_srcrev(d, method_name='sortable_revision'):
     if seenautoinc:
         format = "AUTOINC+" + format
 
+    d.delVar("__BBINSRCREV")
     return format
 
 def localpath(url, d):
Signature · 1 line
2.32.0
#3 lore raw

Re: [bitbake-devel] [PATCH 3/3] fetch2: Add recursion guard

Hi Richard,

Quoted 3 lines · Richard Purdie

Users sometimes put ${S} references in ${SRC_URI} without realising this can be problematic. Improve the error messages if they accidentally do.

I think we could also add this check to
insane.bbclass:package_qa_check_src_uri ?

Cheers,
Quentin

#4 lore raw

Re: [bitbake-devel] [PATCH 3/3] fetch2: Add recursion guard

Quoted 9 lines · Quentin Schulz

Hi Richard,

Quoted 3 lines · Richard Purdie

Users sometimes put ${S} references in ${SRC_URI} without realising this can be problematic. Improve the error messages if they accidentally do.

I think we could also add this check to
insane.bbclass:package_qa_check_src_uri ?

It is a nice idea but would be problematic as it causes a parsing failure unfortunately.

Cheers,

Richard

#5 lore raw
In reply to Richard Purdie

Hi Richard,

Quoted 26 lines · Richard Purdie

If there are circular task references, error on them rather than show a recursion error. A simple reproducer is:

"""

do_packageswu () {
       :
}

addtask do_packageswu after do_image_complete before do_image_qa """

into image_types.bbclass. There is code in runqueue to detect these but we never get that far with the current codebase.

[YOCTO #13140]

---
 lib/bb/build.py | 2 ++
 1 file changed, 2 insertions(+)
lib/bb/build.py +0 -0
index 1e062adb51..4249c0be2b 100644

lib/bb/build.py def tasksbetween(task_start, task_end, d): · line 1038

Quoted 5 lines
lib/bb/build.py +2 -0
@@ -1034,6 +1034,8 @@ def tasksbetween(task_start, task_end, d):
     def follow_chain(task, endtask, chain=None):
         if not chain:
             chain = []
+        if task in chain:
+            bb.fatal("Circular task dependencies as %s depends itself via the chain %s" % (task, " -> ".join(chain)))

depends +on itself?

Cheers,
Quentin

#6 lore raw
Quoted 24 lines · Quentin Schulz

Hi Richard,

Quoted 21 lines · Richard Purdie

If there are circular task references, error on them rather than show a recursion error. A simple reproducer is:

"""

do_packageswu () {
       :
}

addtask do_packageswu after do_image_complete before do_image_qa """

into image_types.bbclass. There is code in runqueue to detect these but we never get that far with the current codebase.

[YOCTO #13140]

---
 lib/bb/build.py | 2 ++
 1 file changed, 2 insertions(+)
Quoted 12 lines

lib/bb/build.py def tasksbetween(task_start, task_end, d): · line 1038

Quoted 10 lines
lib/bb/build.py +2 -0
index 1e062adb51..4249c0be2b 100644
@@ -1034,6 +1034,8 @@ def tasksbetween(task_start, task_end, d):
     def follow_chain(task, endtask, chain=None):
         if not chain:
             chain = []
+        if task in chain:
+            bb.fatal("Circular task dependencies as %s depends itself via the chain %s" % (task, " -> ".join(chain)))

depends +on itself?

Well spotted, tweaked in master-next, thanks.

Cheers,

Richard