Allow manifest object to also provide userdata in preparation for removing ManifestProject class eventually and strengthen related tests

This commit is contained in:
Ryan Lindeman 2022-04-01 12:37:42 -06:00 committed by Marti Bolivar
parent c5ecb2ec75
commit ca52ee5073
2 changed files with 25 additions and 3 deletions

View File

@ -1361,7 +1361,7 @@ class Manifest:
self._posixpath: Optional[str] = None
self._repo_posixpath: Optional[str] = None
# This backs the userdata property
self._userdata: Optional[Any] = None
self.userdata: Any = None
# Load context needed for import resolution. Do top-level
# argument validation and storage if self._top_level is True,
# but otherwise just get self._ctx from the caller.
@ -1803,7 +1803,7 @@ class Manifest:
mp = ManifestProject(
path=self._config_path if self.topdir else self.yaml_path,
west_commands=self._ctx.manifest_west_commands,
topdir=self.topdir, userdata=self._userdata)
topdir=self.topdir, userdata=self.userdata)
# Save the resulting projects and initialize lookup tables
# that rely on the ManifestProject existing.
@ -1906,7 +1906,7 @@ class Manifest:
_logger.debug('resolved self import')
userdata = slf.get('userdata')
self._userdata = userdata
self.userdata = userdata
# The current manifest data's west-comands comes first because
# we treat imports from self as if they are defined "before"

View File

@ -589,12 +589,34 @@ def test_self_userdata(tmpdir):
''')
foo, bar = m.get_projects(['manifest', 'bar'])
assert m.userdata == {'key': 'value'}
assert foo.userdata == {'key': 'value'}
assert bar.userdata is None
assert 'userdata' in foo.as_dict()
assert 'userdata' not in bar.as_dict()
def test_self_missing_userdata(tmpdir):
m = M('''
defaults:
remote: r
remotes:
- name: r
url-base: base
projects:
- name: bar
self:
path: foo
''')
foo, bar = m.get_projects(['manifest', 'bar'])
assert m.userdata is None
assert foo.userdata is None
assert bar.userdata is None
assert 'userdata' not in foo.as_dict()
assert 'userdata' not in bar.as_dict()
def test_no_projects():
# An empty projects list is allowed.