From 5fb906789470481cbe87c2f9255adf5bf5cb8fe6 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 12 Jul 2021 08:47:34 +0200 Subject: [PATCH] Fall back to .config.yaml if no configuration file given Make the configuration file on the command line optional and fall back to trying to open the generated .config.yaml instead. This allows the sequence kas menu -> save & exit kas build kas shell kas ... and also makes rebuilding the self-configured image simpler. Signed-off-by: Jan Kiszka --- kas-container | 20 +++++++++++--------- kas/config.py | 29 ++++++++++++++++++----------- kas/libkas.py | 5 ++++- kas/plugins/menu.py | 3 +-- 4 files changed, 34 insertions(+), 23 deletions(-) diff --git a/kas-container b/kas-container index 9b3d8cb..ae35d2d 100755 --- a/kas-container +++ b/kas-container @@ -29,8 +29,8 @@ set -e usage() { - printf "%b" "Usage: $0 [OPTIONS] { build | checkout | shell } [KASOPTIONS] KASFILE\n" - printf "%b" " $0 [OPTIONS] for-all-repos [KASOPTIONS] KASFILE COMMAND\n" + printf "%b" "Usage: $0 [OPTIONS] { build | checkout | shell } [KASOPTIONS] [KASFILE]\n" + printf "%b" " $0 [OPTIONS] for-all-repos [KASOPTIONS] [KASFILE] COMMAND\n" printf "%b" " $0 [OPTIONS] clean\n" printf "%b" "\nPositional arguments:\n" printf "%b" "build\t\t\tCheck out repositories and build target.\n" @@ -288,7 +288,15 @@ while [ $# -gt 0 ] && [ $KAS_EXTRA_BITBAKE_ARGS -eq 0 ]; do esac done -[ -n "${KAS_FIRST_FILE}" ] || usage +if [ -n "${KAS_FIRST_FILE}" ]; then + 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=$(hg --cwd "${KAS_FILE_DIR}" root 2>/dev/null) \ + || KAS_REPO_DIR=${KAS_FILE_DIR} +else + KAS_FIRST_FILE="${KAS_WORK_DIR}/.config.yaml" + KAS_REPO_DIR=$(pwd) +fi BUILD_SYSTEM=$(grep -e "^build_system: " "${KAS_FIRST_FILE}" 2>/dev/null | sed 's/build_system:[ ]\+//') if [ "${BUILD_SYSTEM}" = "isar" ]; then @@ -297,12 +305,6 @@ 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) \ - || KAS_REPO_DIR=$(hg --cwd "${KAS_FILE_DIR}" root 2>/dev/null) \ - || KAS_REPO_DIR=${KAS_FILE_DIR} - KAS_REPO_MOUNT_OPT="${KAS_REPO_MOUNT_OPT:-${KAS_REPO_MOUNT_OPT_DEFAULT}}" KAS_FILES="$(echo "${KAS_FILES}" | sed 's|'"${KAS_REPO_DIR}"'/|/repo/|g')" diff --git a/kas/config.py b/kas/config.py index b41a683..4866c18 100644 --- a/kas/config.py +++ b/kas/config.py @@ -30,6 +30,8 @@ from .includehandler import IncludeHandler, IncludeException __license__ = 'MIT' __copyright__ = 'Copyright (c) Siemens AG, 2017-2021' +CONFIG_YAML_FILE = '.config.yaml' + class Config: """ @@ -39,18 +41,23 @@ class Config: self._override_target = target self._override_task = task self._config = {} - self.filenames = [os.path.abspath(configfile) - for configfile in filename.split(':')] - self.top_repo_path = Repo.get_root_path( - os.path.dirname(self.filenames[0])) + if filename: + self.filenames = [os.path.abspath(configfile) + for configfile in filename.split(':')] + self.top_repo_path = Repo.get_root_path( + os.path.dirname(self.filenames[0])) - repo_paths = [Repo.get_root_path(os.path.dirname(configfile), - fallback=False) - for configfile in self.filenames] - if len(set(repo_paths)) > 1: - raise IncludeException('All concatenated config files must ' - 'belong to the same repository or all ' - 'must be outside of versioning control') + repo_paths = [Repo.get_root_path(os.path.dirname(configfile), + fallback=False) + for configfile in self.filenames] + + if len(set(repo_paths)) > 1: + raise IncludeException('All concatenated config files must ' + 'belong to the same repository or all ' + 'must be outside of versioning control') + else: + self.filenames = [os.path.join(ctx.kas_work_dir, CONFIG_YAML_FILE)] + self.top_repo_path = os.getcwd() self.handler = IncludeHandler(self.filenames, self.top_repo_path) self.repo_dict = self._get_repo_dict() diff --git a/kas/libkas.py b/kas/libkas.py index 6306ccd..4eb48ac 100644 --- a/kas/libkas.py +++ b/kas/libkas.py @@ -363,7 +363,10 @@ def ssh_no_host_key_check(): def setup_parser_common_args(parser): parser.add_argument('config', - help='Config file') + help='Config file, using .config.yaml if none is ' + 'specified and using the current directory as ' + 'repository anchor', + nargs='?') parser.add_argument('--skip', help='Skip build steps', default=[]) diff --git a/kas/plugins/menu.py b/kas/plugins/menu.py index d3b123e..08a2041 100644 --- a/kas/plugins/menu.py +++ b/kas/plugins/menu.py @@ -75,6 +75,7 @@ from kconfiglib import Kconfig, Symbol, Choice, expr_value, TYPE_TO_STR, \ MENU, COMMENT, STRING, BOOL, INT, HEX, UNKNOWN from kas import __version__, __file_version__ from kas.context import create_global_context +from kas.config import CONFIG_YAML_FILE from kas.includehandler import load_config as load_config_yaml from kas.plugins.build import Build @@ -90,8 +91,6 @@ __copyright__ = \ 'Copyright (c) 2011-2019, Ulf Magnusson \n' \ 'Copyright (c) Siemens AG, 2021' -CONFIG_YAML_FILE = '.config.yaml' - def check_sym_is_string(sym): if sym.type != STRING: