Bug 15881

Summary: consecutive bitbake-getvar invocations cause log messages to be sent to stdout
Product: [Build System, Metadata & Runtime] BitBake Reporter: Enrico Jorns <ejo>
Component: bitbakeAssignee: Richard Purdie <richard.purdie>
Status: NEW --- QA Contact:
Severity: normal    
Priority: Medium+ CC: ccasciato, poky.bs.watcher, poky.watcher, randy.macleod
Version: 5.2   
Target Milestone: 6.2 M2   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)

Description Enrico Jorns 2025-05-28 07:39:14 UTC
When using bitbake-getvar for scripting, I have two consecutive calls to get two different variable contents. The output should be stored in a variable, thus, the commands should only emit the value of the queried variable:

  YOCTO_BUILD=$(bitbake-getvar -r busybox --value B -q)
  YOCTO_SOURCE=$(bitbake-getvar -r busybox --value S -q)

While the first call only prints the variable value to stdout, the second call prints:

  NOTE: Reconnecting to bitbake server...
  NOTE: Retrying server connection (#1)... (09:07:49.112555)
  /path/to/tmp/work/../build

which will break the script's variable.

I've noted this only happens when the bitbake from the previous call is still terminating (seems to work fine for still running/memres bitbake).

Digging through the code, I realized this is a somewhat intentional behavior for bitbake that ensures no log messages get lost. It happens in the print_ui_queue() method, registered as an exit handler, which drains all remaining UI LogEvents (if no UI is present) and dumps them using simple stdout/stderr log handlers.

My understanding is that the terminating bitbake still receives and prints these logs before finally exiting.

What's unclear to me is if this can be avoided for the bitbake-getvar use case.
An option I have thought about is to ensure the previous bitbake is fully shut down before spawning a new one. But maybe there are also options for silencing the log draining? Or something conceptual I haven't thought of?