Switch overrides and dump plugin to new commit/branch schema

Lock files are now using the commit key, rather than legacy refspec, and
the plugin writes out flattened configs that are in line with the input
configs (only write refspec if input repo was using refspec).

This also requires slight adjustments of the related test case. Enhance
the dump test at this chance to actually validate the written commit ID
against the expected one.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
Jan Kiszka 2023-05-30 17:32:03 +02:00
parent c01a11833f
commit 241d03f159
4 changed files with 23 additions and 18 deletions

View File

@ -1,6 +1,6 @@
# kas - setup tool for bitbake based projects
#
# Copyright (c) Siemens AG, 2017-2022
# Copyright (c) Siemens AG, 2017-2023
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@ -30,17 +30,17 @@
configuration.
When running with ``--lock``, a locking spec is created which only contains
the exact refspecs of each repository. This can be used to pin the
refspecs of floating branches, while still keeping an easy update path.
When combining with ``--inplace``, a lockfile is created next to the
first file on the kas cmdline. For details on the locking support, see
the exact commit of each repository. This can be used to pin the commit of
floating branches, while still keeping an easy update path. When combining
with ``--inplace``, a lockfile is created next to the first file on the kas
cmdline. For details on the locking support, see
:class:`kas.includehandler.IncludeHandler`.
Please note:
- the dumped config is semantically identical but not bit-by-bit identical
- all referenced repositories are checked out to resolve cross-repo configs
- all refspecs are resolved before patches are applied
- all branches are resolved before patches are applied
For example, to get a single config representing the final build config of
``kas-project.yml:target-override.yml`` you could run::
@ -121,8 +121,8 @@ class Dump(Checkout):
name = 'dump'
helpmsg = (
'Expand and dump the final config to stdout. When resolving refspecs, '
'these are resolved before patches are applied.'
'Expand and dump the final config to stdout. When resolving branches, '
'this is done before patches are applied.'
)
class KasYamlDumper(yaml.Dumper):
@ -196,7 +196,7 @@ class Dump(Checkout):
# when locking, only consider repos managed by kas
repos = [r for r in repos if not r.operations_disabled]
config_expanded['overrides'] = \
{'repos': {r.name: {'refspec': r.revision} for r in repos}}
{'repos': {r.name: {'commit': r.revision} for r in repos}}
if args.lock and args.inplace:
lockfile = ctx.config.handler.get_lockfile()
@ -208,7 +208,9 @@ class Dump(Checkout):
if args.resolve_refs and not args.lock:
for r in repos:
if r.refspec:
if r.commit or r.branch:
config_expanded['repos'][r.name]['commit'] = r.revision
elif r.refspec:
config_expanded['repos'][r.name]['refspec'] = r.revision
if args.resolve_env and 'env' in config_expanded:

View File

@ -177,7 +177,7 @@ class Repo:
'"{}". This is only allowed for local '
'repositories.'.format(name))
if refspec is None:
commit = repo_overrides.get('refspec', commit)
commit = repo_overrides.get('commit', commit)
else:
if name not in Repo.__legacy_refspec_warned__:
logging.warning('Using deprecated refspec for repository '
@ -188,7 +188,7 @@ class Repo:
raise RepoRefError('Unsupported mixture of legacy refspec '
'and commit/branch for repository "{}"'
.format(name))
refspec = repo_overrides.get('refspec', refspec)
refspec = repo_overrides.get('commit', refspec)
path = repo_config.get('path', None)
disable_operations = False

View File

@ -102,7 +102,7 @@
"type": "object",
"additionalProperties": false,
"properties": {
"refspec" : {
"commit": {
"type": "string"
}
}

View File

@ -143,6 +143,9 @@ def test_lockfile(changedir, tmpdir, capsys):
rawspec = yaml.safe_load(capsys.readouterr().out)
assert rawspec['repos']['externalrepo']['refspec'] == 'master'
with open('externalrepo/.git/refs/heads/master') as f:
expected_commit = f.readline().strip()
# create lockfile
kas.kas('dump --lock --inplace test.yml'.split())
assert os.path.exists('test.lock.yml')
@ -150,24 +153,24 @@ def test_lockfile(changedir, tmpdir, capsys):
# lockfile is considered during import, expect pinned branches
kas.kas('dump test.yml'.split())
lockspec = yaml.safe_load(capsys.readouterr().out)
assert lockspec['overrides']['repos']['externalrepo']['refspec'] \
!= 'master'
assert lockspec['overrides']['repos']['externalrepo']['commit'] \
== expected_commit
# insert older refspec into lockfile (kas 3.2 tag)
test_refspec = 'dc44638cd87c4d0045ea2ca441e682f3525d8b91'
lockspec['overrides']['repos']['externalrepo']['refspec'] = test_refspec
lockspec['overrides']['repos']['externalrepo']['commit'] = test_refspec
with open('test.lock.yml', 'w') as f:
yaml.safe_dump(lockspec, f)
# check if repo is moved to specified commit
kas.kas('dump test.yml'.split())
lockspec = yaml.safe_load(capsys.readouterr().out)
assert lockspec['overrides']['repos']['externalrepo']['refspec'] \
assert lockspec['overrides']['repos']['externalrepo']['commit'] \
== test_refspec
# update lockfile, check if repo is pinned to other commit
kas.kas('dump --lock --inplace --update test.yml'.split())
with open('test.lock.yml', 'r') as f:
lockspec = yaml.safe_load(f)
assert lockspec['overrides']['repos']['externalrepo']['refspec'] \
assert lockspec['overrides']['repos']['externalrepo']['commit'] \
!= test_refspec