This variable can override default build path `${KAS_WORK_DIR}/build`.
Signed-off-by: Peter Hatina <
pe...@hatina.eu>
---
docs/command-line.rst | 2 ++
kas/context.py | 5 +++-
tests/test_environment_variables.py | 30 +++++++++++++++++++
.../oe-init-build-env | 3 ++
tests/test_environment_variables/test.yml | 5 ++++
5 files changed, 44 insertions(+), 1 deletion(-)
create mode 100644 tests/test_environment_variables.py
create mode 100755 tests/test_environment_variables/oe-init-build-env
create mode 100644 tests/test_environment_variables/test.yml
diff --git a/docs/command-line.rst b/docs/command-line.rst
index a39eb87..2919001 100644
--- a/docs/command-line.rst
+++ b/docs/command-line.rst
@@ -15,6 +15,8 @@ Environment variables
+=======================+=====================================================+
| ``KAS_WORK_DIR`` | The path of the kas work directory, current work |
| | directory is the default. |
+| ``KAS_BUILD_DIR`` | The path build directory, ``KAS_WORK_DIR/build`` is |
+| | the default. |
+-----------------------+-----------------------------------------------------+
| ``KAS_REPO_REF_DIR`` | The path to the repository reference directory. |
| | Repositories in this directory are used as |
diff --git a/kas/context.py b/kas/context.py
index 36ab017..161fcd9 100644
--- a/kas/context.py
+++ b/kas/context.py
@@ -72,6 +72,9 @@ class Context:
"""
def __init__(self, args):
self.__kas_work_dir = os.environ.get('KAS_WORK_DIR', os.getcwd())
+ self.__kas_build_dir = os.environ.get('KAS_BUILD_DIR',
+ os.path.join(self.__kas_work_dir,
+ 'build'))
self.__kas_repo_ref_dir = os.environ.get('KAS_REPO_REF_DIR', None)
self.setup_initial_environ()
self.config = None
@@ -110,7 +113,7 @@ class Context:
"""
The path to the build directory
"""
- return os.path.join(self.__kas_work_dir, 'build')
+ return self.__kas_build_dir
@property
def kas_work_dir(self):
diff --git a/tests/test_environment_variables.py b/tests/test_environment_variables.py
new file mode 100644
index 0000000..d15e9b2
--- /dev/null
+++ b/tests/test_environment_variables.py
@@ -0,0 +1,30 @@
+import os
+import stat
+import shutil
+from kas import kas
+
+
+def test_build_dir_is_placed_inside_work_dir_by_default(changedir, tmpdir):
+ conf_dir = str(tmpdir.mkdir('test_env_variables'))
+ shutil.rmtree(conf_dir, ignore_errors=True)
+ shutil.copytree('tests/test_environment_variables', conf_dir)
+
+ os.chdir(conf_dir)
+
+ kas.kas(['checkout', 'test.yml'])
+
+ assert(os.path.exists(os.path.join(os.getcwd(), 'build', 'conf')))
+
+
+def test_build_dir_can_be_specified_by_environment_variable(changedir, tmpdir):
+ conf_dir = str(tmpdir.mkdir('test_env_variables'))
+ build_dir = str(tmpdir.mkdir('test_build_dir'))
+ shutil.rmtree(conf_dir, ignore_errors=True)
+ shutil.copytree('tests/test_environment_variables', conf_dir)
+ shutil.rmtree(build_dir, ignore_errors=True)
+ os.chdir(conf_dir)
+
+ os.environ['KAS_BUILD_DIR'] = build_dir
+ kas.kas(['checkout', 'test.yml'])
+
+ assert(os.path.exists(os.path.join(build_dir, 'conf')))
diff --git a/tests/test_environment_variables/oe-init-build-env b/tests/test_environment_variables/oe-init-build-env
new file mode 100755
index 0000000..296ef78
--- /dev/null
+++ b/tests/test_environment_variables/oe-init-build-env
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+true
diff --git a/tests/test_environment_variables/test.yml b/tests/test_environment_variables/test.yml
new file mode 100644
index 0000000..187fc96
--- /dev/null
+++ b/tests/test_environment_variables/test.yml
@@ -0,0 +1,5 @@
+header:
+ version: 10
+
+repos:
+ this:
--
Peter Hatina
PGP: 12DC 9BD0 69E9 EB13