<div dir="ltr"><div dir="ltr">This is a great idea, thanks a lot for contribution. As Richard says, I think using and hardcoding __builtins__ as the injection point isn’t ideal. Ideally I think we'd be able to provide a python module in a layer with the progress handler, let OE_IMPORTS import it, and then let bitbake use it as is.<div><br></div><div>I think we just need to tweak it to accept the full name with imports, i.e. custom:oe.myprogressmodule.MyProgressHandler. Then if you want to inject it you can (though I think bb.context is better than __builtins__), or use an imported module, whichever is preferred, rather than hardcoding the context.</div><div><br></div><div>Something like `<font color="#262626" face="Helvetica Neue"><span style="font-size:12px">functools.reduce(lambda x, y: x[y], cls.split("."), globals())` might do for resolving the dot-separated name to the class object, assuming it’s already been imported.</span></font></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Feb 21, 2019 at 2:13 PM Richard Purdie <<a href="mailto:richard.purdie@linuxfoundation.org">richard.purdie@linuxfoundation.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">On Wed, 2018-10-03 at 22:48 -0400, Chris Laplante via bitbake-devel<br>
wrote:<br>
> To use this mechanism, you need to inject your progress handler (i.e.<br>
> something derived from bb.progress.ProgressHandler) into<br>
> __builtins__.<br>
> Here's one way to do it (from recipe-space):<br>
> <br>
> def install_my_progress_handler():<br>
> from bb.progress import ProgressHandler<br>
> <br>
> class MyProgressHandler(ProgressHandler):<br>
> pass<br>
> <br>
> if "MyProgressHandler" not in __builtins__:<br>
> __builtins__["MyProgressHandler"] = MyProgressHandler<br>
> <br>
> return "OK"<br>
> <br>
> _INSTALL_MY_PROGRESS_HANDLERS := "${@install_my_progress_handler(<br>
> )}"<br>
<br>
Sorry about the lack of review.<br>
<br>
My concern on this is the fact we have to poke around __builtins__. I<br>
understand why, I just can't help wonder if there is a better way<br>
somehow.<br>
<br>
I'm not sure I have a better one, not sure if Chris or others might?<br>
<br>
Cheers,<br>
<br>
Richard<br>
<br>
<br>
> To install on a task:<br>
> do_task[progress] = "custom:MyProgressHandler"<br>
> <br>
> To install on a task and pass extra arguments:<br>
> do_task[progress] = "custom:MyProgressHandler:my-arg"<br>
> <br>
> Signed-off-by: Chris Laplante <<a href="mailto:chris.laplante@agilent.com" target="_blank">chris.laplante@agilent.com</a>><br>
> ---<br>
> lib/bb/build.py | 8 ++++++++<br>
> 1 file changed, 8 insertions(+)<br>
> <br>
> diff --git a/lib/bb/build.py b/lib/bb/build.py<br>
> index 3e2a94e..2e14572 100644<br>
> --- a/lib/bb/build.py<br>
> +++ b/lib/bb/build.py<br>
> @@ -387,6 +387,14 @@ exit $ret<br>
> elif progress.startswith('outof:'):<br>
> # Use specified regex<br>
> logfile = bb.progress.OutOfProgressHandler(d,<br>
> regex=progress.split(':', 1)[1], outfile=logfile)<br>
> + elif progress.startswith("custom:"):<br>
> + # Use a custom progress handler<br>
> + parts = progress.split(":", 2)<br>
> + _, cls, otherargs = parts[0], parts[1], (parts[2] or<br>
> None) if parts[2:] else None<br>
> + if cls and cls in __builtins__:<br>
> + logfile = __builtins__[cls](d, outfile=logfile,<br>
> otherargs=otherargs)<br>
> + else:<br>
> + bb.warn('%s: unknown custom progress handler in task<br>
> progress varflag value "%s", ignoring' % (func, cls))<br>
> else:<br>
> bb.warn('%s: invalid task progress varflag value "%s",<br>
> ignoring' % (func, progress))<br>
> <br>
> -- <br>
> 2.7.4<br>
> <br>
<br>
-- <br>
_______________________________________________<br>
bitbake-devel mailing list<br>
<a href="mailto:bitbake-devel@lists.openembedded.org" target="_blank">bitbake-devel@lists.openembedded.org</a><br>
<a href="http://lists.openembedded.org/mailman/listinfo/bitbake-devel" rel="noreferrer" target="_blank">http://lists.openembedded.org/mailman/listinfo/bitbake-devel</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr">Christopher Larson<br>kergoth at gmail dot com<br>Founder - BitBake, OpenEmbedded, OpenZaurus<br>Senior Software Engineer, Mentor Graphics</div></div></div></div>