kas-container: track repo dir when using menu cmd

When using the kas menu command, we need to track the repository
location outside of the kas container as well. This is required to
prepare the environment for a later kas-container build, as the repo
path inside the container is different from the outside one. For that,
the location of KAS_REPO_DIR is passed via an env-var into the container.
There, this value is picked up by the menu plugin and written to the
.config.yaml file as `_source_host_dir`. When running kas-container build,
we check if the .config.yaml file contains this node and set the
KAS_REPO_DIR accordingly. The schema is extended accordingly.

Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
[Jan: rework _source_dir_host extraction to make it usable for menu as well]
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
Felix Moessbauer 2023-05-26 06:39:43 +02:00 committed by Jan Kiszka
parent e274886ab0
commit e9032bc278
6 changed files with 38 additions and 2 deletions

View File

@ -140,3 +140,5 @@ Added
- The ``overrides`` top-level entry can be used to pin floating repo refspecs.
- ``_source_dir`` top-level entry is auto-generated when using the menu plugin
and provides the path to the top repo at time of invoking the plugin.
- ``_source_dir_host`` top-level entry is auto-generated by kas-container to
track the source path outside of the container.

View File

@ -538,3 +538,10 @@ Configuration reference
This entry is auto-generated by the menu plugin and provides the path to
the top repo at time of invoking the plugin. It must not be set
manually and might only be defined in the top-level ``.config.yaml`` file.
* ``_source_dir_host``:: string [optional]
This entry is auto-generated by the menu plugin when invoking kas via
the ``kas-container`` script. It provides the absolute path to the top repo
outside of the container (on the host). This value is only evaluated by the
``kas-container`` script. It must not be set manually and might only be
defined in the top-level ``.config.yaml`` file.

View File

@ -373,11 +373,28 @@ else
KAS_REPO_DIR=$(pwd)
fi
SOURCE_DIR_HOST=$(
grep -e "^_source_dir_host: " "${KAS_WORK_DIR}/.config.yaml" 2>/dev/null | \
sed 's/_source_dir_host:[ ]\+//')
if [ -n "${SOURCE_DIR_HOST}" ]; then
KAS_REPO_DIR="${SOURCE_DIR_HOST}"
fi
if [ "${KAS_CMD}" = "menu" ]; then
if [ -z "${KAS_FIRST_FILE}" ]; then
KAS_FIRST_FILE="Kconfig"
fi
# When using the menu plugin, we need to track the KAS_REPO_DIR outside
# of the container to later allow a simple `kas-container build`. For
# that, we tell the kas menu plugin via an env-var about the location
# on the host. This data is then added to the .config.yaml where it can
# be evaluated by the next invocation of kas-container.
if ! [ "$(realpath -qe "${KAS_REPO_DIR}")" = "$(realpath -qe "${KAS_WORK_DIR}")" ]; then
set -- "$@" -e _KAS_REPO_DIR_HOST="$(readlink -fv "${KAS_REPO_DIR}")"
fi
BUILD_SYSTEM=$(tr '\n' '\f' 2>/dev/null < ${KAS_FIRST_FILE} | \
sed -e 's/\(.*\fconfig KAS_BUILD_SYSTEM\f\(.*\)\|.*\)/\2/' \
-e 's/\f\([[:alpha:]].*\|$\)//' \

View File

@ -42,6 +42,7 @@ __license__ = 'MIT'
__copyright__ = 'Copyright (c) Siemens AG, 2017-2021'
SOURCE_DIR_OVERRIDE_KEY = '_source_dir'
SOURCE_DIR_HOST_OVERRIDE_KEY = '_source_dir_host'
class LoadConfigException(KasUserError):

View File

@ -77,7 +77,7 @@ from kas.context import create_global_context
from kas.config import CONFIG_YAML_FILE
from kas.repos import Repo
from kas.includehandler import load_config as load_config_yaml, \
SOURCE_DIR_OVERRIDE_KEY
SOURCE_DIR_OVERRIDE_KEY, SOURCE_DIR_HOST_OVERRIDE_KEY
from kas.plugins.build import Build
from kas.kasusererror import KasUserError
@ -91,7 +91,9 @@ except ImportError:
__license__ = 'MIT'
__copyright__ = \
'Copyright (c) 2011-2019, Ulf Magnusson <ulfalizer@gmail.com>\n' \
'Copyright (c) Siemens AG, 2021'
'Copyright (c) Siemens AG, 2021-2023'
SOURCE_DIR_HOST_ENV_KEY = '_KAS_REPO_DIR_HOST'
class VariableTypeError(KasUserError):
@ -219,6 +221,10 @@ class Menu:
'menu_configuration': menu_configuration,
SOURCE_DIR_OVERRIDE_KEY: top_repo_dir
}
if SOURCE_DIR_HOST_ENV_KEY in os.environ:
config[SOURCE_DIR_HOST_OVERRIDE_KEY] = \
os.environ[SOURCE_DIR_HOST_ENV_KEY]
if kas_build_system:
config['build_system'] = kas_build_system
if len(kas_targets) > 0:

View File

@ -272,6 +272,9 @@
},
"_source_dir": {
"type": "string"
},
"_source_dir_host": {
"type": "string"
}
}
}