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 <jan.kiszka@siemens.com>
This commit is contained in:
Jan Kiszka 2021-07-12 08:47:34 +02:00
parent 1271320de3
commit 5fb9067894
4 changed files with 34 additions and 23 deletions

View File

@ -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')"

View File

@ -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()

View File

@ -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=[])

View File

@ -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 <ulfalizer@gmail.com>\n' \
'Copyright (c) Siemens AG, 2021'
CONFIG_YAML_FILE = '.config.yaml'
def check_sym_is_string(sym):
if sym.type != STRING: