Skip to content

Commit

Permalink
menu plugin: track root repo dir
Browse files Browse the repository at this point in the history
This patch adds a new top-level schema node `_source_dir` which is used
to track the top repo dir on auto-generated kas files. This node is
generated by the kas menu plugin and provides the absolute path to the
top repo dir at time of invoking the plugin. When later calling any other
kas operation that performs a checkout, this node is evaluated and the
top repo dir is set accordingly. This tracking is required when the
build command is executed from another dir than the top repo dir, as the
repo-dir cannot be computed by kas in this case (the .config.yaml file
is in the KAS_WORK_DIR, not in the repo dir).

Proposed-by: Peter Hoyes <[email protected]>
Signed-off-by: Felix Moessbauer <[email protected]>
[Jan: aligned format-changelog text, simplified load_config returning]
Signed-off-by: Jan Kiszka <[email protected]>
  • Loading branch information
fmoessbauer authored and jan-kiszka committed May 30, 2023
1 parent ea0baa0 commit 76db070
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 11 deletions.
2 changes: 2 additions & 0 deletions docs/format-changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,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.
5 changes: 5 additions & 0 deletions docs/userguide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -533,3 +533,8 @@ Configuration reference
corresponds to a Kconfig configuration variable and can be of the types
string, boolean or integer. The content of this key is typically
maintained by the ``kas menu`` plugin in a ``.config.yaml`` file.

* ``_source_dir``:: string [optional]
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.
7 changes: 4 additions & 3 deletions kas/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, ctx, filename, target=None, task=None):

self.filenames = [os.path.abspath(configfile)
for configfile in filename.split(':')]
self.top_repo_path = Repo.get_root_path(
top_repo_path = Repo.get_root_path(
os.path.dirname(self.filenames[0]))

repo_paths = [Repo.get_root_path(os.path.dirname(configfile),
Expand All @@ -61,7 +61,7 @@ def __init__(self, ctx, filename, target=None, task=None):
update = ctx.args.update if hasattr(ctx.args, 'update') else False

self.handler = IncludeHandler(self.filenames,
self.top_repo_path,
top_repo_path,
not update)
self.repo_dict = self._get_repo_dict()

Expand Down Expand Up @@ -111,10 +111,11 @@ def get_repo(self, name):
overrides = self._config.get('overrides', {}) \
.get('repos', {}).get(name, {})
config = self.get_repos_config()[name] or {}
top_repo_path = self.handler.get_top_repo_path()
return Repo.factory(name,
config,
repo_defaults,
self.top_repo_path,
top_repo_path,
overrides)

def _get_repo_dict(self):
Expand Down
14 changes: 12 additions & 2 deletions kas/includehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
__license__ = 'MIT'
__copyright__ = 'Copyright (c) Siemens AG, 2017-2021'

SOURCE_DIR_OVERRIDE_KEY = '_source_dir'


class LoadConfigException(KasUserError):
"""
Expand Down Expand Up @@ -100,7 +102,7 @@ def load_config(filename):
logging.warning('Obsolete ''proxy_config'' detected. '
'This has no effect and will be rejected soon.')

return config
return (config, config.get(SOURCE_DIR_OVERRIDE_KEY, None))


class IncludeException(KasUserError):
Expand Down Expand Up @@ -145,6 +147,9 @@ def get_lockfile(self):
file = Path(self.top_files[0])
return file.parent / (file.stem + '.lock' + file.suffix)

def get_top_repo_path(self):
return self.top_repo_path

def get_config(self, repos=None):
"""
Parameters:
Expand Down Expand Up @@ -188,7 +193,12 @@ def _internal_include_handler(filename, repo_path):
missing_repos = []
configs = []
try:
current_config = load_config(filename)
current_config, src_dir = load_config(filename)
# src_dir must only be set by auto-generated config file
if src_dir:
self.top_repo_path = src_dir
repo_path = src_dir

except FileNotFoundError:
raise LoadConfigException('Configuration file not found',
filename)
Expand Down
17 changes: 11 additions & 6 deletions kas/plugins/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@
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.repos import Repo
from kas.includehandler import load_config as load_config_yaml, \
SOURCE_DIR_OVERRIDE_KEY
from kas.plugins.build import Build
from kas.kasusererror import KasUserError

Expand Down Expand Up @@ -140,7 +142,7 @@ def setup_parser(cls, parser):

def load_config(self, filename):
try:
self.orig_config = load_config_yaml(filename)
self.orig_config, _ = load_config_yaml(filename)
except FileNotFoundError:
self.orig_config = {}
return
Expand All @@ -163,7 +165,7 @@ def load_config(self, filename):
else: # string
sym.set_value(symvalue)

def save_config(self, filename):
def save_config(self, filename, top_repo_dir):
kas_includes = []
kas_targets = []
kas_build_system = None
Expand Down Expand Up @@ -214,7 +216,8 @@ def save_config(self, filename):
'version': __file_version__,
'includes': kas_includes
},
'menu_configuration': menu_configuration
'menu_configuration': menu_configuration,
SOURCE_DIR_OVERRIDE_KEY: top_repo_dir
}
if kas_build_system:
config['build_system'] = kas_build_system
Expand Down Expand Up @@ -260,11 +263,13 @@ def run(self, args):

ctx = create_global_context(args)

kconfig_file = os.path.abspath(args.kconfig)
try:
self.kconf = Kconfig(args.kconfig, warn_to_stderr=False)
self.kconf = Kconfig(kconfig_file, warn_to_stderr=False)
except (KconfigError, FileNotFoundError) as err:
raise KConfigLoadError(str(err))

top_repo_path = Repo.get_root_path(os.path.dirname(kconfig_file))
config_filename = os.path.join(ctx.kas_work_dir, CONFIG_YAML_FILE)

self.load_config(config_filename)
Expand All @@ -276,7 +281,7 @@ def run(self, args):
if action == 'exit':
return

self.save_config(config_filename)
self.save_config(config_filename, top_repo_path)
self.dump_kconf_warnings()

if action == 'build':
Expand Down
3 changes: 3 additions & 0 deletions kas/schema-kas.json
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@
}
]
}
},
"_source_dir": {
"type": "string"
}
}
}

0 comments on commit 76db070

Please sign in to comment.