From 60d995ccc49ee817dfdb1f2988357f9a9250d11f Mon Sep 17 00:00:00 2001 From: Johannes Schneider Date: Wed, 8 Oct 2025 18:56:56 +0200 Subject: [PATCH] bitbake: bitbake-setup: support adding environment-passthroughs to the init-build-env 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" ] 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 (Bitbake rev: 782ab99e7a04fba43bdcf5763a6280785944ae3f) Signed-off-by: Johannes Schneider Signed-off-by: Richard Purdie --- bitbake/bin/bitbake-setup | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/bitbake/bin/bitbake-setup b/bitbake/bin/bitbake-setup index e7b955213e..7878cd9394 100755 --- a/bitbake/bin/bitbake-setup +++ b/bitbake/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):