[bitbake-devel] [RFC PATCH] cooker: Support saving the base environment to file

Jacob Kroon jacob.kroon at gmail.com
Fri Sep 13 17:21:40 UTC 2019


Add support for saving the base environment to ${PERSISTENT_DIR}/bb_env when
BB_SAVE_ENV is set to 1.

Signed-off-by: Jacob Kroon <jacob.kroon at gmail.com>
---
 lib/bb/cooker.py | 4 ++++
 1 file changed, 4 insertions(+)

I have a usecase where I would like to extract a couple of variables like
BUILDHISTORY_DIR, DEPLOY_DIR_IMAGE and TMPDIR from Bitbake's environment,
and use them for further processing in Makefiles/shell scripts.

Running "bitbake -e | grep ..." works, but on my laptop that takes ~5 seconds
to finish. I'm perfectly fine with using values from the most recent parsing
done by Bitbake, so an up-2-date copy of the Bitbake environment on disk would
solve my problem.

I couldn't find a switch to turn on that would enable this, or a utility
script that would allow me to inspect existing cached data, but I did get
something working using a custom .bbclass in INHERIT and a custom
"write-bitbake-variables-to-file" recipe, but that seems like overkill after
realizing that patching cooker.py was not that intrusive, although the
patch is not perfect.

Does anyone know a better way to achieve this ?

Cheers,
Jacob

diff --git a/lib/bb/cooker.py b/lib/bb/cooker.py
index 5840aa75..7a37f808 100644
--- a/lib/bb/cooker.py
+++ b/lib/bb/cooker.py
@@ -385,6 +385,10 @@ class BBCooker:
         self.baseconfig_valid = True
         self.parsecache_valid = False
 
+        if self.data.getVar('BB_SAVE_ENV') == "1":
+            with closing(open(os.path.join(self.data.getVar('PERSISTENT_DIR'), 'bb_env'), 'w')) as out:
+                data.emit_env(out, self.data, True)
+
     def handlePRServ(self):
         # Setup a PR Server based on the new configuration
         try:


More information about the bitbake-devel mailing list