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",