[PATCH v0 0/1] This change adds support for the build_dir config parameter within a kas .yml file.

10 views
Skip to first unread message

Eric Meyers

unread,
Sep 22, 2025, 7:50:38 AM (4 days ago) Sep 22
to kas-...@googlegroups.com, Eric Meyers
It allows the user to override a KAS_BUILD_DIR environment variable (if set) with
a value passed in via the .yml config which will set the build directory for bitbake
to use when calling into the oe-init-build-env script in poky.

Eric Meyers (1):
kas: Add support for build_dir config parameter

docs/format-changelog.rst | 10 ++++++++++
kas/config.py | 16 ++++++++++++++++
kas/context.py | 11 +++++++++++
kas/libcmds.py | 13 +++++++++++++
kas/schema-kas.json | 6 +++++-
5 files changed, 55 insertions(+), 1 deletion(-)

Eric Meyers

unread,
Sep 22, 2025, 7:50:39 AM (4 days ago) Sep 22
to kas-...@googlegroups.com, Eric Meyers, Geoff Parker
Allow user to pass in 'build_dir' in their kas .yml file to override
KAS_BUILD_DIR environment variable.

Signed-off-by: Eric Meyers <eric....@arthrex.com>
Cc: Geoff Parker <geoffre...@arthrex.com>
---
docs/format-changelog.rst | 10 ++++++++++
kas/config.py | 16 ++++++++++++++++
kas/context.py | 11 +++++++++++
kas/libcmds.py | 13 +++++++++++++
kas/schema-kas.json | 6 +++++-
5 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/docs/format-changelog.rst b/docs/format-changelog.rst
index e5d94d3..e5a1df9 100644
--- a/docs/format-changelog.rst
+++ b/docs/format-changelog.rst
@@ -201,3 +201,13 @@ Added
~~~~~

- The repo key ``branch`` can now be overridden, including to a null-value.
+
+Version 21
+----------
+
+Added
+~~~~~
+
+- A top-level ``build_dir`` key can now be used to specify the build directory.
+ This overrides the ``KAS_BUILD_DIR`` environment variable and the default
+ value of ``${KAS_WORK_DIR}/build``.
diff --git a/kas/config.py b/kas/config.py
index cebc749..735c107 100644
--- a/kas/config.py
+++ b/kas/config.py
@@ -46,6 +46,7 @@ class Config:
self._override_target = target
self._override_task = task
self._build_dir = ctx.build_dir
+ self._ctx = ctx
self.__config = {}
if not filename:
filename = os.path.join(ctx.kas_work_dir, CONFIG_YAML_FILE)
@@ -81,6 +82,15 @@ class Config:

return missing_repo_names

+ def update_build_dir_from_config(self):
+ """
+ Update context build directory from config if specified
+ """
+ config_build_dir = self.get_build_dir_config()
+ if config_build_dir:
+ self._ctx.set_config_build_dir(config_build_dir)
+ self._build_dir = self._ctx.build_dir
+
def get_config(self, remove_includes=False, apply_overrides=False):
"""
Returns a copy of the config dict
@@ -219,6 +229,12 @@ class Config:
return os.environ.get('KAS_DISTRO',
self._config.get('distro', default))

+ def get_build_dir_config(self):
+ """
+ Returns the build directory from config or None if not specified
+ """
+ return self._config.get('build_dir', None)
+
def get_environment(self):
"""
Returns the configured environment variables from the configuration
diff --git a/kas/context.py b/kas/context.py
index f49302c..6ed2f6a 100644
--- a/kas/context.py
+++ b/kas/context.py
@@ -101,6 +101,17 @@ class Context:
self.config = None
self.args = args

+ def set_config_build_dir(self, config_build_dir):
+ """
+ Updates the build directory if specified in config and not overridden by env var
+ """
+ # Only use config build_dir if KAS_BUILD_DIR env var is not set
+ if config_build_dir and not os.environ.get('KAS_BUILD_DIR'):
+ if not os.path.isabs(config_build_dir):
+ config_build_dir = os.path.join(self.__kas_work_dir, config_build_dir)
+ self.__kas_build_dir = os.path.abspath(config_build_dir)
+ self.managed_paths.add(self.__kas_build_dir)
+
def setup_initial_environ(self):
"""
Sets the environment variables for processes that are
diff --git a/kas/libcmds.py b/kas/libcmds.py
index bf02fce..7316267 100644
--- a/kas/libcmds.py
+++ b/kas/libcmds.py
@@ -78,6 +78,7 @@ class Macro:
self.setup_commands += [(x, None) for x in [
SetupHome(),
InitSetupRepos(),
+ UpdateBuildDir(),
repo_loop,
FinishSetupRepos(),
ReposCheckout(),
@@ -516,6 +517,18 @@ class ReposApplyPatches(Command):
self._vcs_restore_user(gitconfig, user)


+class UpdateBuildDir(Command):
+ """
+ Updates the build directory from config if specified
+ """
+
+ def __str__(self):
+ return 'update_build_dir'
+
+ def execute(self, ctx):
+ ctx.config.update_build_dir_from_config()
+
+
class InitSetupRepos(Command):
"""
Prepares setting up repos including the include logic
diff --git a/kas/schema-kas.json b/kas/schema-kas.json
index 87934f9..ff89622 100644
--- a/kas/schema-kas.json
+++ b/kas/schema-kas.json
@@ -26,7 +26,7 @@
{
"type": "integer",
"minimum": 1,
- "maximum": 20
+ "maximum": 21
}
]
},
@@ -140,6 +140,10 @@
"default": "poky",
"type": "string"
},
+ "build_dir": {
+ "description": "Name of the build directory. If not specified, falls back to the ``KAS_BUILD_DIR`` environment variable or defaults to ``${KAS_WORK_DIR}/build``.",
+ "type": "string"
+ },
"env": {
"description": "Environment variables to forward and their default values (set to nulltype to only forward if set). These variables are made available to bitbake via ``BB_ENV_PASSTHROUGH_ADDITIONS`` (``BB_ENV_EXTRAWHITE`` in older Bitbake versions) and can be overwritten by the variables of the environment in which kas is started.",
"type": "object",

Jan Kiszka

unread,
Sep 23, 2025, 12:37:59 AM (3 days ago) Sep 23
to Eric Meyers, kas-...@googlegroups.com, Eric Meyers, Geoff Parker
On 22.09.25 13:50, Eric Meyers wrote:
> Allow user to pass in 'build_dir' in their kas .yml file to override
> KAS_BUILD_DIR environment variable.
>

And why do you need this? A commit message should always provide a
reason for the change to follow.
Environment trumps configuration, that is the normal ordering. Can you
explain why you divert from that?

Jan

> "env": {
> "description": "Environment variables to forward and their default values (set to nulltype to only forward if set). These variables are made available to bitbake via ``BB_ENV_PASSTHROUGH_ADDITIONS`` (``BB_ENV_EXTRAWHITE`` in older Bitbake versions) and can be overwritten by the variables of the environment in which kas is started.",
> "type": "object",
>


--
Siemens AG, Foundational Technologies
Linux Expert Center

Eric Meyers

unread,
Sep 23, 2025, 7:12:38 AM (3 days ago) Sep 23
to Jan Kiszka, kas-...@googlegroups.com, Eric Meyers, Geoff Parker
Apologies for not providing reasoning. We were investigating sstate issues on our system that shares several machine types in which each machine has its own kas .yaml file. These machines switch various DISTRO settings between them and a note in the Yocto docs states (here):

If DISTRO settings change or fundamental configuration settings such as the filesystem layout, you need to work with a clean TMPDIR. Sharing TMPDIR under these circumstances might work but since it is not guaranteed, you should use a clean TMPDIR.

So we were exploring a change where each machine .yaml could define it's own separate build directory (or share one if they want) to avoid some sstate corruption issues we are seeing. But looking into it more, I might scrap these changes in favor of just defining TMPDIR in my local.yaml. For some reason, I was thinking that the build directory needed to be outright switched between different machine .yaml files, but this is most likely overcomplicating it.

Feel free to take the patch (or a modified version of it) if you think it'd still be useful for the project. 
Reply all
Reply to author
Forward
0 new messages