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 <jan.kiszka@siemens.com>
This commit is contained in:
Jan Kiszka 2020-11-15 09:57:51 +01:00
parent f502f92afe
commit 6a8abf277c
8 changed files with 70 additions and 27 deletions

View File

@ -86,3 +86,11 @@ Added
property ``refspec`` and the repository patch property ``repo``. These property ``refspec`` and the repository patch property ``repo``. These
default values will be used if the appropriate properties are not defined default values will be used if the appropriate properties are not defined
for a given repository or patch. for a given repository or patch.
Version 10
----------
Added
~~~~~
- ``build_system`` property to pre-select OE or Isar.

View File

@ -276,6 +276,15 @@ Configuration reference
* ``file``: string [required] * ``file``: string [required]
The path to the file relative to the root of the repository. 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] * ``defaults``: dict [optional]
This key can be used to set default values for various properties. This key can be used to set default values for various properties.
This may help you to avoid repeating the same property assignment in This may help you to avoid repeating the same property assignment in

View File

@ -2,7 +2,7 @@
# #
# kas - setup tool for bitbake based projects # kas - setup tool for bitbake based projects
# #
# Copyright (c) Siemens AG, 2018-2019 # Copyright (c) Siemens AG, 2018-2020
# #
# Authors: # Authors:
# Jan Kiszka <jan.kiszka@siemens.com> # Jan Kiszka <jan.kiszka@siemens.com>
@ -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_IMAGE_VERSION_DEFAULT="2.2"
KAS_CONTAINER_IMAGE_PATH_DEFAULT="ghcr.io/siemens/kas" KAS_CONTAINER_IMAGE_PATH_DEFAULT="ghcr.io/siemens/kas"
KAS_CONTAINER_IMAGE_NAME_DEFAULT="kas" KAS_CONTAINER_IMAGE_NAME_DEFAULT="kas"
@ -112,21 +129,7 @@ esac
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in case "$1" in
--isar) --isar)
KAS_CONTAINER_IMAGE_NAME_DEFAULT="kas-isar" enable_isar_mode
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
shift 1 shift 1
;; ;;
--with-loop-dev) --with-loop-dev)
@ -205,12 +208,12 @@ done
[ -n "${KAS_CMD}" ] || usage [ -n "${KAS_CMD}" ] || usage
KAS_EXTRA_BITBAKE_ARGS=0 KAS_EXTRA_BITBAKE_ARGS=0
set_container_image_var
# parse kas sub-command (build or shell) options # parse kas sub-command (build or shell) options
while [ $# -gt 0 ] && [ $KAS_EXTRA_BITBAKE_ARGS -eq 0 ]; do while [ $# -gt 0 ] && [ $KAS_EXTRA_BITBAKE_ARGS -eq 0 ]; do
case "$1" in case "$1" in
-h|--help) -h|--help)
set_container_image_var
trace ${KAS_CONTAINER_COMMAND} run ${KAS_CONTAINER_IMAGE} ${KAS_CMD} --help trace ${KAS_CONTAINER_COMMAND} run ${KAS_CONTAINER_IMAGE} ${KAS_CMD} --help
exit 0 exit 0
;; ;;
@ -246,6 +249,13 @@ done
[ -n "${KAS_FIRST_FILE}" ] || usage [ -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_FILE_DIR="$(dirname "${KAS_FIRST_FILE}")"
KAS_REPO_DIR=$(git -C "${KAS_FILE_DIR}" rev-parse --show-toplevel 2>/dev/null) \ KAS_REPO_DIR=$(git -C "${KAS_FILE_DIR}" rev-parse --show-toplevel 2>/dev/null) \

View File

@ -1,6 +1,6 @@
# kas - setup tool for bitbake based projects # 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 # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal # of this software and associated documentation files (the "Software"), to deal
@ -23,10 +23,10 @@
This module contains the version of kas. This module contains the version of kas.
""" """
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) Siemens AG, 2017-2018' __copyright__ = 'Copyright (c) Siemens AG, 2017-2020'
__version__ = '2.2' __version__ = '2.2'
# Please update docs/format-changelog.rst when changing the file version. # Please update docs/format-changelog.rst when changing the file version.
__file_version__ = 9 __file_version__ = 10
__compatible_file_version__ = 1 __compatible_file_version__ = 1

View File

@ -1,6 +1,6 @@
# kas - setup tool for bitbake based projects # 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 # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal # of this software and associated documentation files (the "Software"), to deal
@ -53,6 +53,12 @@ class Config:
self.handler = IncludeHandler(self.filenames) self.handler = IncludeHandler(self.filenames)
self.repo_dict = self._get_repo_dict() 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): def find_missing_repos(self):
""" """
Returns repos that are in config but not on disk Returns repos that are in config but not on disk

View File

@ -1,6 +1,6 @@
# kas - setup tool for bitbake based projects # 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 # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal # 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': { 'defaults': {
'type': 'object', 'type': 'object',
'additionalProperties': False, 'additionalProperties': False,

View File

@ -1,6 +1,6 @@
# kas - setup tool for bitbake based projects # 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 # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal # of this software and associated documentation files (the "Software"), to deal
@ -225,7 +225,7 @@ class SetupEnviron(Command):
return 'setup_environ' return 'setup_environ'
def execute(self, ctx): def execute(self, ctx):
ctx.environ.update(get_build_environ()) ctx.environ.update(get_build_environ(ctx.config.get_build_system()))
class WriteBBConfig(Command): class WriteBBConfig(Command):

View File

@ -1,6 +1,6 @@
# kas - setup tool for bitbake based projects # 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 # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal # of this software and associated documentation files (the "Software"), to deal
@ -183,7 +183,7 @@ def repos_apply_patches(repos):
sys.exit(task.result()) sys.exit(task.result())
def get_build_environ(): def get_build_environ(build_system):
""" """
Creates the build environment variables. Creates the build environment variables.
""" """
@ -191,9 +191,15 @@ def get_build_environ():
# creates the conf directory # creates the conf directory
init_repo = None 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 = \ permutations = \
[(repo, script) for repo in get_context().config.get_repos() [(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: for (repo, script) in permutations:
if os.path.exists(repo.path + '/' + script): if os.path.exists(repo.path + '/' + script):
if init_repo: if init_repo: