From e9032bc278435f6e03e7639fa5c1432e6d0e262a Mon Sep 17 00:00:00 2001 From: Felix Moessbauer Date: Fri, 26 May 2023 06:39:43 +0200 Subject: [PATCH] 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 [Jan: rework _source_dir_host extraction to make it usable for menu as well] Signed-off-by: Jan Kiszka --- docs/format-changelog.rst | 2 ++ docs/userguide.rst | 7 +++++++ kas-container | 17 +++++++++++++++++ kas/includehandler.py | 1 + kas/plugins/menu.py | 10 ++++++++-- kas/schema-kas.json | 3 +++ 6 files changed, 38 insertions(+), 2 deletions(-) diff --git a/docs/format-changelog.rst b/docs/format-changelog.rst index ae9c50c..15941cb 100644 --- a/docs/format-changelog.rst +++ b/docs/format-changelog.rst @@ -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. diff --git a/docs/userguide.rst b/docs/userguide.rst index a7ab050..4bc87ae 100644 --- a/docs/userguide.rst +++ b/docs/userguide.rst @@ -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. diff --git a/kas-container b/kas-container index 99b6d7d..0d22651 100755 --- a/kas-container +++ b/kas-container @@ -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:]].*\|$\)//' \ diff --git a/kas/includehandler.py b/kas/includehandler.py index f84d62a..aa4ef38 100644 --- a/kas/includehandler.py +++ b/kas/includehandler.py @@ -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): diff --git a/kas/plugins/menu.py b/kas/plugins/menu.py index e325bc8..07bfe4e 100644 --- a/kas/plugins/menu.py +++ b/kas/plugins/menu.py @@ -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 \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: diff --git a/kas/schema-kas.json b/kas/schema-kas.json index 688a1f4..8f8f858 100644 --- a/kas/schema-kas.json +++ b/kas/schema-kas.json @@ -272,6 +272,9 @@ }, "_source_dir": { "type": "string" + }, + "_source_dir_host": { + "type": "string" } } }