[bitbake-devel] build.py: support custom task [progress] handlers

Submitted by Nicolas Cornu via bitbake-devel on Oct. 4, 2018, 2:48 a.m. | Patch ID: 155432


Message ID 1538621300-112900-1-git-send-email-chris.laplante@agilent.com
State New
Headers show

Commit Message

Nicolas Cornu via bitbake-devel Oct. 4, 2018, 2:48 a.m.
To use this mechanism, you need to inject your progress handler (i.e.
something derived from bb.progress.ProgressHandler) into __builtins__.
Here's one way to do it (from recipe-space):

    def install_my_progress_handler():
        from bb.progress import ProgressHandler

        class MyProgressHandler(ProgressHandler):

        if "MyProgressHandler" not in __builtins__:
            __builtins__["MyProgressHandler"] = MyProgressHandler

        return "OK"

    _INSTALL_MY_PROGRESS_HANDLERS := "${@install_my_progress_handler()}"

To install on a task:
    do_task[progress] = "custom:MyProgressHandler"

To install on a task and pass extra arguments:
    do_task[progress] = "custom:MyProgressHandler:my-arg"

Signed-off-by: Chris Laplante <chris.laplante@agilent.com>
 lib/bb/build.py | 8 ++++++++
 1 file changed, 8 insertions(+)

Patch hide | download patch | download mbox

diff --git a/lib/bb/build.py b/lib/bb/build.py
index 3e2a94e..2e14572 100644
--- a/lib/bb/build.py
+++ b/lib/bb/build.py
@@ -387,6 +387,14 @@  exit $ret
         elif progress.startswith('outof:'):
             # Use specified regex
             logfile = bb.progress.OutOfProgressHandler(d, regex=progress.split(':', 1)[1], outfile=logfile)
+        elif progress.startswith("custom:"):
+            # Use a custom progress handler
+            parts = progress.split(":", 2)
+            _, cls, otherargs = parts[0], parts[1], (parts[2] or None) if parts[2:] else None
+            if cls and cls in __builtins__:
+                logfile = __builtins__[cls](d, outfile=logfile, otherargs=otherargs)
+            else:
+                bb.warn('%s: unknown custom progress handler in task progress varflag value "%s", ignoring' % (func, cls))
             bb.warn('%s: invalid task progress varflag value "%s", ignoring' % (func, progress))