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:
parent
c01a11833f
commit
241d03f159
@ -1,6 +1,6 @@
|
|||||||
# kas - setup tool for bitbake based projects
|
# 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
|
# 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
|
||||||
@ -30,17 +30,17 @@
|
|||||||
configuration.
|
configuration.
|
||||||
|
|
||||||
When running with ``--lock``, a locking spec is created which only contains
|
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
|
the exact commit of each repository. This can be used to pin the commit of
|
||||||
refspecs of floating branches, while still keeping an easy update path.
|
floating branches, while still keeping an easy update path. When combining
|
||||||
When combining with ``--inplace``, a lockfile is created next to the
|
with ``--inplace``, a lockfile is created next to the first file on the kas
|
||||||
first file on the kas cmdline. For details on the locking support, see
|
cmdline. For details on the locking support, see
|
||||||
:class:`kas.includehandler.IncludeHandler`.
|
:class:`kas.includehandler.IncludeHandler`.
|
||||||
|
|
||||||
Please note:
|
Please note:
|
||||||
|
|
||||||
- the dumped config is semantically identical but not bit-by-bit identical
|
- the dumped config is semantically identical but not bit-by-bit identical
|
||||||
- all referenced repositories are checked out to resolve cross-repo configs
|
- 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
|
For example, to get a single config representing the final build config of
|
||||||
``kas-project.yml:target-override.yml`` you could run::
|
``kas-project.yml:target-override.yml`` you could run::
|
||||||
@ -121,8 +121,8 @@ class Dump(Checkout):
|
|||||||
|
|
||||||
name = 'dump'
|
name = 'dump'
|
||||||
helpmsg = (
|
helpmsg = (
|
||||||
'Expand and dump the final config to stdout. When resolving refspecs, '
|
'Expand and dump the final config to stdout. When resolving branches, '
|
||||||
'these are resolved before patches are applied.'
|
'this is done before patches are applied.'
|
||||||
)
|
)
|
||||||
|
|
||||||
class KasYamlDumper(yaml.Dumper):
|
class KasYamlDumper(yaml.Dumper):
|
||||||
@ -196,7 +196,7 @@ class Dump(Checkout):
|
|||||||
# when locking, only consider repos managed by kas
|
# when locking, only consider repos managed by kas
|
||||||
repos = [r for r in repos if not r.operations_disabled]
|
repos = [r for r in repos if not r.operations_disabled]
|
||||||
config_expanded['overrides'] = \
|
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:
|
if args.lock and args.inplace:
|
||||||
lockfile = ctx.config.handler.get_lockfile()
|
lockfile = ctx.config.handler.get_lockfile()
|
||||||
@ -208,7 +208,9 @@ class Dump(Checkout):
|
|||||||
|
|
||||||
if args.resolve_refs and not args.lock:
|
if args.resolve_refs and not args.lock:
|
||||||
for r in repos:
|
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
|
config_expanded['repos'][r.name]['refspec'] = r.revision
|
||||||
|
|
||||||
if args.resolve_env and 'env' in config_expanded:
|
if args.resolve_env and 'env' in config_expanded:
|
||||||
|
@ -177,7 +177,7 @@ class Repo:
|
|||||||
'"{}". This is only allowed for local '
|
'"{}". This is only allowed for local '
|
||||||
'repositories.'.format(name))
|
'repositories.'.format(name))
|
||||||
if refspec is None:
|
if refspec is None:
|
||||||
commit = repo_overrides.get('refspec', commit)
|
commit = repo_overrides.get('commit', commit)
|
||||||
else:
|
else:
|
||||||
if name not in Repo.__legacy_refspec_warned__:
|
if name not in Repo.__legacy_refspec_warned__:
|
||||||
logging.warning('Using deprecated refspec for repository '
|
logging.warning('Using deprecated refspec for repository '
|
||||||
@ -188,7 +188,7 @@ class Repo:
|
|||||||
raise RepoRefError('Unsupported mixture of legacy refspec '
|
raise RepoRefError('Unsupported mixture of legacy refspec '
|
||||||
'and commit/branch for repository "{}"'
|
'and commit/branch for repository "{}"'
|
||||||
.format(name))
|
.format(name))
|
||||||
refspec = repo_overrides.get('refspec', refspec)
|
refspec = repo_overrides.get('commit', refspec)
|
||||||
path = repo_config.get('path', None)
|
path = repo_config.get('path', None)
|
||||||
disable_operations = False
|
disable_operations = False
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"properties": {
|
"properties": {
|
||||||
"refspec" : {
|
"commit": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,6 +143,9 @@ def test_lockfile(changedir, tmpdir, capsys):
|
|||||||
rawspec = yaml.safe_load(capsys.readouterr().out)
|
rawspec = yaml.safe_load(capsys.readouterr().out)
|
||||||
assert rawspec['repos']['externalrepo']['refspec'] == 'master'
|
assert rawspec['repos']['externalrepo']['refspec'] == 'master'
|
||||||
|
|
||||||
|
with open('externalrepo/.git/refs/heads/master') as f:
|
||||||
|
expected_commit = f.readline().strip()
|
||||||
|
|
||||||
# create lockfile
|
# create lockfile
|
||||||
kas.kas('dump --lock --inplace test.yml'.split())
|
kas.kas('dump --lock --inplace test.yml'.split())
|
||||||
assert os.path.exists('test.lock.yml')
|
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
|
# lockfile is considered during import, expect pinned branches
|
||||||
kas.kas('dump test.yml'.split())
|
kas.kas('dump test.yml'.split())
|
||||||
lockspec = yaml.safe_load(capsys.readouterr().out)
|
lockspec = yaml.safe_load(capsys.readouterr().out)
|
||||||
assert lockspec['overrides']['repos']['externalrepo']['refspec'] \
|
assert lockspec['overrides']['repos']['externalrepo']['commit'] \
|
||||||
!= 'master'
|
== expected_commit
|
||||||
|
|
||||||
# insert older refspec into lockfile (kas 3.2 tag)
|
# insert older refspec into lockfile (kas 3.2 tag)
|
||||||
test_refspec = 'dc44638cd87c4d0045ea2ca441e682f3525d8b91'
|
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:
|
with open('test.lock.yml', 'w') as f:
|
||||||
yaml.safe_dump(lockspec, f)
|
yaml.safe_dump(lockspec, f)
|
||||||
|
|
||||||
# check if repo is moved to specified commit
|
# check if repo is moved to specified commit
|
||||||
kas.kas('dump test.yml'.split())
|
kas.kas('dump test.yml'.split())
|
||||||
lockspec = yaml.safe_load(capsys.readouterr().out)
|
lockspec = yaml.safe_load(capsys.readouterr().out)
|
||||||
assert lockspec['overrides']['repos']['externalrepo']['refspec'] \
|
assert lockspec['overrides']['repos']['externalrepo']['commit'] \
|
||||||
== test_refspec
|
== test_refspec
|
||||||
|
|
||||||
# update lockfile, check if repo is pinned to other commit
|
# update lockfile, check if repo is pinned to other commit
|
||||||
kas.kas('dump --lock --inplace --update test.yml'.split())
|
kas.kas('dump --lock --inplace --update test.yml'.split())
|
||||||
with open('test.lock.yml', 'r') as f:
|
with open('test.lock.yml', 'r') as f:
|
||||||
lockspec = yaml.safe_load(f)
|
lockspec = yaml.safe_load(f)
|
||||||
assert lockspec['overrides']['repos']['externalrepo']['refspec'] \
|
assert lockspec['overrides']['repos']['externalrepo']['commit'] \
|
||||||
!= test_refspec
|
!= test_refspec
|
||||||
|
Loading…
Reference in New Issue
Block a user