diff mbox series

[1/4] bitbake-setup: support adding environment-passthroughs to the init-build-env

Message ID 20251008165659.1884881-1-alex.kanavin@gmail.com
State New
Headers show
Series [1/4] bitbake-setup: support adding environment-passthroughs to the init-build-env | expand

Commit Message

Alexander Kanavin Oct. 8, 2025, 4:56 p.m. UTC
From: Johannes Schneider <johannes.schneider@leica-geosystems.com>

This patch adds support for extending the BB_ENV_PASSTHROUGH_ADDITIONS
environment variable from within the `init-build-env` wrapper script -
generated by either oe-core's oe-setup-build, or by `bitbake-setup` -
based on per-configuration JSON settings.

This enables CI workflows to inject environment-specific data - such
as build number, host, build type, or credentials required to fetch
from certain SRC_URIs - which cannot be captured via configuration
fragments alone. These variables are now handled early in the setup
process and exported directly into the build environment.

Example:

  "bb-env-passthrough-additions": [
      "ACME_DIR",
      "ARTIFACTORY_TOKEN",
      "ARTIFACTORY_USERNAME",
      "GITHUB_TOKEN",
      "GITHUB_PROTOCOL",
      "KEY"
  ]
  <snip>

the resulting 'init-build-env' would then be:
  # environment passthrough added by bitbake-setup
  export BB_ENV_PASSTHROUGH_ADDITIONS=" \
  $BB_ENV_PASSTHROUGH_ADDITIONS \
  ACME_DIR \
  ARTIFACTORY_TOKEN \
  ARTIFACTORY_USERNAME \
  GITHUB_TOKEN \
  GITHUB_PROTOCOL \
  KEY"
  # init-build-env wrapper created by bitbake-setup
  . /tmp/acme_master-acme-distro_acme-machine_bang/layers/openembedded-core/oe-init-build-env /tmp/bitbake-setup/gs/acme_master-acme-distro_acme-machine_bang/build

Signed-off-by: Johannes Schneider <johannes.schneider@leica-geosystems.com>
---
 bin/bitbake-setup | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/bin/bitbake-setup b/bin/bitbake-setup
index e7b955213..7878cd939 100755
--- a/bin/bitbake-setup
+++ b/bin/bitbake-setup
@@ -162,8 +162,31 @@  def setup_bitbake_build(bitbake_config, layerdir, builddir, thisdir):
         builddir = os.path.realpath(builddir)
         cmd = "cd {}\nset {}\n. ./oe-init-build-env\n".format(oeinitbuildenvdir, builddir)
         initbuild_in_builddir = os.path.join(builddir, 'init-build-env')
+
         with open(initbuild_in_builddir, 'w') as f:
-            f.write(cmd)
+            f.write("# init-build-env wrapper created by bitbake-setup\n")
+            f.write(cmd + '\n')
+
+    def _prepend_passthrough_to_init_build_env(builddir):
+        env = bitbake_config.get("bb-env-passthrough-additions")
+        if not env:
+            return
+
+        initbuild_in_builddir = os.path.join(builddir, 'init-build-env')
+        with open(initbuild_in_builddir) as f:
+            content = f.read()
+
+        joined = " \\\n".join(env)
+        env = "export BB_ENV_PASSTHROUGH_ADDITIONS=\" \\\n"
+        env += "${BB_ENV_PASSTHROUGH_ADDITIONS} \\\n"
+        env += joined
+        env += '"'
+
+        with open(initbuild_in_builddir, 'w') as f:
+            f.write("# environment passthrough added by bitbake-setup\n")
+            f.write(env + '\n')
+            f.write('\n')
+            f.write(content)
 
     bitbake_builddir = os.path.join(builddir, "build")
     print("Setting up bitbake configuration in\n    {}\n".format(bitbake_builddir))
@@ -194,6 +217,8 @@  def setup_bitbake_build(bitbake_config, layerdir, builddir, thisdir):
             return
         _make_init_build_env(bitbake_builddir, os.path.realpath(oeinitbuildenvdir))
 
+    _prepend_passthrough_to_init_build_env(bitbake_builddir)
+
     siteconf_symlink = os.path.join(bitbake_confdir, "site.conf")
     siteconf = os.path.normpath(os.path.join(builddir, '..', "site.conf"))
     if os.path.lexists(siteconf_symlink):