From 6a8abf277c6d0ab0a37d67d532d68e4f5fc6a09a Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Sun, 15 Nov 2020 09:57:51 +0100 Subject: [PATCH] Add build_system property to config file This allows to pre-select the build system, specifically avoiding confusion when kas-container is accidentally not called with --isar for an isar config. For that, build_system needs to be defined in the lop-level config file passed to kas-container. Theoretically, this also allows to combine layers which have both oe-init-build-env and isar-init-build-env scripts. Signed-off-by: Jan Kiszka --- docs/format-changelog.rst | 8 +++++++ docs/userguide.rst | 9 ++++++++ kas-container | 44 ++++++++++++++++++++++++--------------- kas/__version__.py | 6 +++--- kas/config.py | 8 ++++++- kas/configschema.py | 6 +++++- kas/libcmds.py | 4 ++-- kas/libkas.py | 12 ++++++++--- 8 files changed, 70 insertions(+), 27 deletions(-) diff --git a/docs/format-changelog.rst b/docs/format-changelog.rst index 7b3167f..ca5f9fb 100644 --- a/docs/format-changelog.rst +++ b/docs/format-changelog.rst @@ -86,3 +86,11 @@ Added property ``refspec`` and the repository patch property ``repo``. These default values will be used if the appropriate properties are not defined for a given repository or patch. + +Version 10 +---------- + +Added +~~~~~ + +- ``build_system`` property to pre-select OE or Isar. diff --git a/docs/userguide.rst b/docs/userguide.rst index b7182be..c8bbade 100644 --- a/docs/userguide.rst +++ b/docs/userguide.rst @@ -276,6 +276,15 @@ Configuration reference * ``file``: string [required] The path to the file relative to the root of the repository. +* ``build_system``: string [optional] + Defines the bitbake-based build system. Known build systems are + ``openembedded`` (or ``oe``) and ``isar``. If set, this restricts the + search of kas for the init script in the configured repositories to + ``oe-init-build-env`` or ``isar-init-build-env``, respectively. If + ``kas-container`` finds this property in the top-level kas configuration + file (includes are not evaluated), it will automatically select the + required container image and invocation mode. + * ``defaults``: dict [optional] This key can be used to set default values for various properties. This may help you to avoid repeating the same property assignment in diff --git a/kas-container b/kas-container index f273789..954a9ef 100755 --- a/kas-container +++ b/kas-container @@ -2,7 +2,7 @@ # # kas - setup tool for bitbake based projects # -# Copyright (c) Siemens AG, 2018-2019 +# Copyright (c) Siemens AG, 2018-2020 # # Authors: # Jan Kiszka @@ -64,6 +64,23 @@ trace() "$@" } +enable_isar_mode() { + KAS_CONTAINER_IMAGE_NAME_DEFAULT="kas-isar" + KAS_ISAR_ARGS="--privileged" + + case "${KAS_CONTAINER_ENGINE}" in + docker) + KAS_ISAR_ARGS="${KAS_ISAR_ARGS} --cap-add=SYS_ADMIN" + KAS_ISAR_ARGS="${KAS_ISAR_ARGS} --cap-add=MKNOD" + ;; + podman) + # sudo is needed for a privileged podman container + KAS_CONTAINER_COMMAND="sudo ${KAS_CONTAINER_COMMAND}" + KAS_ISAR_ARGS="${KAS_ISAR_ARGS} --pid=host" + ;; + esac +} + KAS_IMAGE_VERSION_DEFAULT="2.2" KAS_CONTAINER_IMAGE_PATH_DEFAULT="ghcr.io/siemens/kas" KAS_CONTAINER_IMAGE_NAME_DEFAULT="kas" @@ -112,21 +129,7 @@ esac while [ $# -gt 0 ]; do case "$1" in --isar) - KAS_CONTAINER_IMAGE_NAME_DEFAULT="kas-isar" - KAS_ISAR_ARGS="--privileged" - - case "${KAS_CONTAINER_ENGINE}" in - docker) - KAS_ISAR_ARGS="${KAS_ISAR_ARGS} --cap-add=SYS_ADMIN" - KAS_ISAR_ARGS="${KAS_ISAR_ARGS} --cap-add=MKNOD" - ;; - podman) - # sudo is needed for a privileged podman container - KAS_CONTAINER_COMMAND="sudo ${KAS_CONTAINER_COMMAND}" - KAS_ISAR_ARGS="${KAS_ISAR_ARGS} --pid=host" - ;; - esac - + enable_isar_mode shift 1 ;; --with-loop-dev) @@ -205,12 +208,12 @@ done [ -n "${KAS_CMD}" ] || usage KAS_EXTRA_BITBAKE_ARGS=0 -set_container_image_var # parse kas sub-command (build or shell) options while [ $# -gt 0 ] && [ $KAS_EXTRA_BITBAKE_ARGS -eq 0 ]; do case "$1" in -h|--help) + set_container_image_var trace ${KAS_CONTAINER_COMMAND} run ${KAS_CONTAINER_IMAGE} ${KAS_CMD} --help exit 0 ;; @@ -246,6 +249,13 @@ done [ -n "${KAS_FIRST_FILE}" ] || usage +BUILD_SYSTEM=$(cat ${KAS_FIRST_FILE} 2>/dev/null| grep "^build_system: " | sed 's/build_system:[ ]\+//') +if [ "${BUILD_SYSTEM}" = "isar" ]; then + enable_isar_mode +fi + +set_container_image_var + KAS_FILE_DIR="$(dirname "${KAS_FIRST_FILE}")" KAS_REPO_DIR=$(git -C "${KAS_FILE_DIR}" rev-parse --show-toplevel 2>/dev/null) \ diff --git a/kas/__version__.py b/kas/__version__.py index 44a9074..1fc14aa 100644 --- a/kas/__version__.py +++ b/kas/__version__.py @@ -1,6 +1,6 @@ # kas - setup tool for bitbake based projects # -# Copyright (c) Siemens AG, 2017-2018 +# Copyright (c) Siemens AG, 2017-2020 # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -23,10 +23,10 @@ This module contains the version of kas. """ __license__ = 'MIT' -__copyright__ = 'Copyright (c) Siemens AG, 2017-2018' +__copyright__ = 'Copyright (c) Siemens AG, 2017-2020' __version__ = '2.2' # Please update docs/format-changelog.rst when changing the file version. -__file_version__ = 9 +__file_version__ = 10 __compatible_file_version__ = 1 diff --git a/kas/config.py b/kas/config.py index 4a9cc60..0119f68 100644 --- a/kas/config.py +++ b/kas/config.py @@ -1,6 +1,6 @@ # kas - setup tool for bitbake based projects # -# Copyright (c) Siemens AG, 2017-2018 +# Copyright (c) Siemens AG, 2017-2020 # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -53,6 +53,12 @@ class Config: self.handler = IncludeHandler(self.filenames) self.repo_dict = self._get_repo_dict() + def get_build_system(self): + """ + Returns the pre-selected build system + """ + return self._config.get('build_system', '') + def find_missing_repos(self): """ Returns repos that are in config but not on disk diff --git a/kas/configschema.py b/kas/configschema.py index da4d098..b97ef42 100644 --- a/kas/configschema.py +++ b/kas/configschema.py @@ -1,6 +1,6 @@ # kas - setup tool for bitbake based projects # -# Copyright (c) Siemens AG, 2017-2018 +# Copyright (c) Siemens AG, 2017-2020 # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the 'Software'), to deal @@ -72,6 +72,10 @@ CONFIGSCHEMA = { }, }, }, + 'build_system': { + 'type': 'string', + 'enum': ['openembedded', 'oe', 'isar'], + }, 'defaults': { 'type': 'object', 'additionalProperties': False, diff --git a/kas/libcmds.py b/kas/libcmds.py index 75d5bd0..d65048d 100644 --- a/kas/libcmds.py +++ b/kas/libcmds.py @@ -1,6 +1,6 @@ # kas - setup tool for bitbake based projects # -# Copyright (c) Siemens AG, 2017-2018 +# Copyright (c) Siemens AG, 2017-2020 # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -225,7 +225,7 @@ class SetupEnviron(Command): return 'setup_environ' def execute(self, ctx): - ctx.environ.update(get_build_environ()) + ctx.environ.update(get_build_environ(ctx.config.get_build_system())) class WriteBBConfig(Command): diff --git a/kas/libkas.py b/kas/libkas.py index a1aee6d..8be0e0f 100644 --- a/kas/libkas.py +++ b/kas/libkas.py @@ -1,6 +1,6 @@ # kas - setup tool for bitbake based projects # -# Copyright (c) Siemens AG, 2017-2018 +# Copyright (c) Siemens AG, 2017-2020 # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -183,7 +183,7 @@ def repos_apply_patches(repos): sys.exit(task.result()) -def get_build_environ(): +def get_build_environ(build_system): """ Creates the build environment variables. """ @@ -191,9 +191,15 @@ def get_build_environ(): # creates the conf directory init_repo = None + if build_system in ['openembedded', 'oe']: + scripts = ['oe-init-build-env'] + elif build_system == 'isar': + scripts = ['isar-init-build-env'] + else: + scripts = ['oe-init-build-env', 'isar-init-build-env'] permutations = \ [(repo, script) for repo in get_context().config.get_repos() - for script in ['oe-init-build-env', 'isar-init-build-env']] + for script in scripts] for (repo, script) in permutations: if os.path.exists(repo.path + '/' + script): if init_repo: