Introduce KAS_BUILD_DIR environment variable
This variable can override default build path `${KAS_WORK_DIR}/build`.
Signed-off-by: Peter Hatina <peter@hatina.eu>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
			
			
This commit is contained in:
		@@ -15,6 +15,8 @@ Environment variables
 | 
				
			|||||||
+=======================+=====================================================+
 | 
					+=======================+=====================================================+
 | 
				
			||||||
| ``KAS_WORK_DIR``      | The path of the kas work directory, current work    |
 | 
					| ``KAS_WORK_DIR``      | The path of the kas work directory, current work    |
 | 
				
			||||||
|                       | directory is the default.                           |
 | 
					|                       | 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.     |
 | 
					| ``KAS_REPO_REF_DIR``  | The path to the repository reference directory.     |
 | 
				
			||||||
|                       | Repositories in this directory are used as          |
 | 
					|                       | Repositories in this directory are used as          |
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -93,6 +93,12 @@ else
 | 
				
			|||||||
	KAS_WORK_DIR="$(pwd)"
 | 
						KAS_WORK_DIR="$(pwd)"
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [ -n "${KAS_BUILD_DIR}" ]; then
 | 
				
			||||||
 | 
						KAS_BUILD_DIR=$(readlink -f "${KAS_BUILD_DIR}")
 | 
				
			||||||
 | 
					else
 | 
				
			||||||
 | 
						KAS_BUILD_DIR="${KAS_WORK_DIR}/build"
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
KAS_CONTAINER_ENGINE="${KAS_CONTAINER_ENGINE:-${KAS_DOCKER_ENGINE}}"
 | 
					KAS_CONTAINER_ENGINE="${KAS_CONTAINER_ENGINE:-${KAS_DOCKER_ENGINE}}"
 | 
				
			||||||
if [ -z "${KAS_CONTAINER_ENGINE}" ]; then
 | 
					if [ -z "${KAS_CONTAINER_ENGINE}" ]; then
 | 
				
			||||||
	# Try to auto-detect a container engine
 | 
						# Try to auto-detect a container engine
 | 
				
			||||||
@@ -183,17 +189,16 @@ while [ $# -gt 0 ]; do
 | 
				
			|||||||
		;;
 | 
							;;
 | 
				
			||||||
	clean)
 | 
						clean)
 | 
				
			||||||
		[ $# -eq 1 ] || usage
 | 
							[ $# -eq 1 ] || usage
 | 
				
			||||||
		KAS_CLEAN_DIR=build/tmp
 | 
					 | 
				
			||||||
		if [ -n "${KAS_ISAR_ARGS}" ]; then
 | 
							if [ -n "${KAS_ISAR_ARGS}" ]; then
 | 
				
			||||||
			set_container_image_var
 | 
								set_container_image_var
 | 
				
			||||||
			# SC2086: Double quote to prevent globbing and word splitting.
 | 
								# SC2086: Double quote to prevent globbing and word splitting.
 | 
				
			||||||
			# shellcheck disable=2086
 | 
								# shellcheck disable=2086
 | 
				
			||||||
			trace ${KAS_CONTAINER_COMMAND} run -v "${KAS_WORK_DIR}":/work:rw \
 | 
								trace ${KAS_CONTAINER_COMMAND} run -v "${KAS_BUILD_DIR}":/build:rw \
 | 
				
			||||||
					 --workdir=/work --rm ${KAS_ISAR_ARGS} \
 | 
										 --workdir=/build --rm ${KAS_ISAR_ARGS} \
 | 
				
			||||||
					 ${KAS_CONTAINER_IMAGE} \
 | 
										 ${KAS_CONTAINER_IMAGE} \
 | 
				
			||||||
					 sudo rm -rf ${KAS_CLEAN_DIR}
 | 
										 sudo rm -rf tmp
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
			trace rm -rf "${KAS_WORK_DIR}/${KAS_CLEAN_DIR}"
 | 
								trace rm -rf "${KAS_BUILD_DIR}/tmp"
 | 
				
			||||||
		fi
 | 
							fi
 | 
				
			||||||
		exit 0
 | 
							exit 0
 | 
				
			||||||
		;;
 | 
							;;
 | 
				
			||||||
@@ -276,6 +281,7 @@ KAS_REPO_DIR=$(git -C "${KAS_FILE_DIR}" rev-parse --show-toplevel 2>/dev/null) \
 | 
				
			|||||||
KAS_FILES=/repo/"$(echo "${KAS_FILES}" | sed 's|'"${KAS_REPO_DIR}"'/||g;s|:|:/repo/|g')"
 | 
					KAS_FILES=/repo/"$(echo "${KAS_FILES}" | sed 's|'"${KAS_REPO_DIR}"'/||g;s|:|:/repo/|g')"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
trace mkdir -p "${KAS_WORK_DIR}"
 | 
					trace mkdir -p "${KAS_WORK_DIR}"
 | 
				
			||||||
 | 
					trace mkdir -p "${KAS_BUILD_DIR}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [ "$(id -u)" -eq 0 ] && [ "${KAS_ALLOW_ROOT}" != "yes" ] ; then
 | 
					if [ "$(id -u)" -eq 0 ] && [ "${KAS_ALLOW_ROOT}" != "yes" ] ; then
 | 
				
			||||||
	echo "Error: Running as root - may break certain recipes."
 | 
						echo "Error: Running as root - may break certain recipes."
 | 
				
			||||||
@@ -286,6 +292,8 @@ fi
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
set -- "$@" -v "${KAS_REPO_DIR}":/repo:ro \
 | 
					set -- "$@" -v "${KAS_REPO_DIR}":/repo:ro \
 | 
				
			||||||
	-v "${KAS_WORK_DIR}":/work:rw --workdir=/work \
 | 
						-v "${KAS_WORK_DIR}":/work:rw --workdir=/work \
 | 
				
			||||||
 | 
						-v "${KAS_BUILD_DIR}":/build:rw \
 | 
				
			||||||
 | 
						-e KAS_BUILD_DIR=/build \
 | 
				
			||||||
	-e USER_ID="$(id -u)" -e GROUP_ID="$(id -g)" --rm
 | 
						-e USER_ID="$(id -u)" -e GROUP_ID="$(id -g)" --rm
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [ -n "${KAS_SSH_DIR}" ] ; then
 | 
					if [ -n "${KAS_SSH_DIR}" ] ; then
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -72,6 +72,9 @@ class Context:
 | 
				
			|||||||
    """
 | 
					    """
 | 
				
			||||||
    def __init__(self, args):
 | 
					    def __init__(self, args):
 | 
				
			||||||
        self.__kas_work_dir = os.environ.get('KAS_WORK_DIR', os.getcwd())
 | 
					        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.__kas_repo_ref_dir = os.environ.get('KAS_REPO_REF_DIR', None)
 | 
				
			||||||
        self.setup_initial_environ()
 | 
					        self.setup_initial_environ()
 | 
				
			||||||
        self.config = None
 | 
					        self.config = None
 | 
				
			||||||
@@ -110,7 +113,7 @@ class Context:
 | 
				
			|||||||
        """
 | 
					        """
 | 
				
			||||||
            The path to the build directory
 | 
					            The path to the build directory
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        return os.path.join(self.__kas_work_dir, 'build')
 | 
					        return self.__kas_build_dir
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @property
 | 
					    @property
 | 
				
			||||||
    def kas_work_dir(self):
 | 
					    def kas_work_dir(self):
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										30
									
								
								tests/test_environment_variables.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								tests/test_environment_variables.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
				
			|||||||
 | 
					import os
 | 
				
			||||||
 | 
					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'])
 | 
				
			||||||
 | 
					    del os.environ['KAS_BUILD_DIR']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    assert(os.path.exists(os.path.join(build_dir, 'conf')))
 | 
				
			||||||
							
								
								
									
										3
									
								
								tests/test_environment_variables/oe-init-build-env
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										3
									
								
								tests/test_environment_variables/oe-init-build-env
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					#!/bin/sh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					true
 | 
				
			||||||
							
								
								
									
										5
									
								
								tests/test_environment_variables/test.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								tests/test_environment_variables/test.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					header:
 | 
				
			||||||
 | 
					  version: 10
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					repos:
 | 
				
			||||||
 | 
					  this:
 | 
				
			||||||
		Reference in New Issue
	
	Block a user