manifest: add submanifest.default_groups attribute

When the user does not specify any manifest groups, this allows the
parent manifest to indicate which manifest groups should be used for
syncing the submanifest.

Change-Id: I88806ed35013d13dd2ab3cd245fcd4f9061112c4
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/335474
Tested-by: LaMont Jones <lamontjones@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
LaMont Jones 2022-04-20 16:42:32 +00:00
parent 0165e20fcc
commit 501733c2ab
4 changed files with 39 additions and 14 deletions

View File

@ -66,6 +66,7 @@ following DTD:
<!ATTLIST submanifest revision CDATA #IMPLIED> <!ATTLIST submanifest revision CDATA #IMPLIED>
<!ATTLIST submanifest path CDATA #IMPLIED> <!ATTLIST submanifest path CDATA #IMPLIED>
<!ATTLIST submanifest groups CDATA #IMPLIED> <!ATTLIST submanifest groups CDATA #IMPLIED>
<!ATTLIST submanifest default-groups CDATA #IMPLIED>
<!ELEMENT project (annotation*, <!ELEMENT project (annotation*,
project*, project*,
@ -302,6 +303,9 @@ in the included submanifest belong. This appends and recurses, meaning
all projects in submanifests carry all parent submanifest groups. all projects in submanifests carry all parent submanifest groups.
Same syntax as the corresponding element of `project`. Same syntax as the corresponding element of `project`.
Attribute `default-groups`: The list of manifest groups to sync if no
`--groups=` parameter was specified at init. When that list is empty, use this
list instead of "default" as the list of groups to sync.
### Element project ### Element project

View File

@ -214,6 +214,7 @@ class _XmlSubmanifest:
revision: a string, the commitish. revision: a string, the commitish.
manifestName: a string, the submanifest file name. manifestName: a string, the submanifest file name.
groups: a list of strings, the groups to add to all projects in the submanifest. groups: a list of strings, the groups to add to all projects in the submanifest.
default_groups: a list of strings, the default groups to sync.
path: a string, the relative path for the submanifest checkout. path: a string, the relative path for the submanifest checkout.
parent: an XmlManifest, the parent manifest. parent: an XmlManifest, the parent manifest.
annotations: (derived) a list of annotations. annotations: (derived) a list of annotations.
@ -226,6 +227,7 @@ class _XmlSubmanifest:
revision=None, revision=None,
manifestName=None, manifestName=None,
groups=None, groups=None,
default_groups=None,
path=None, path=None,
parent=None): parent=None):
self.name = name self.name = name
@ -234,6 +236,7 @@ class _XmlSubmanifest:
self.revision = revision self.revision = revision
self.manifestName = manifestName self.manifestName = manifestName
self.groups = groups self.groups = groups
self.default_groups = default_groups
self.path = path self.path = path
self.parent = parent self.parent = parent
self.annotations = [] self.annotations = []
@ -250,7 +253,8 @@ class _XmlSubmanifest:
os.path.join(parent.path_prefix, self.relpath), MANIFEST_FILE_NAME) os.path.join(parent.path_prefix, self.relpath), MANIFEST_FILE_NAME)
rc = self.repo_client = RepoClient( rc = self.repo_client = RepoClient(
parent.repodir, linkFile, parent_groups=','.join(groups) or '', parent.repodir, linkFile, parent_groups=','.join(groups) or '',
submanifest_path=self.relpath, outer_client=outer_client) submanifest_path=self.relpath, outer_client=outer_client,
default_groups=default_groups)
self.present = os.path.exists(manifestFile) self.present = os.path.exists(manifestFile)
@ -264,6 +268,7 @@ class _XmlSubmanifest:
self.revision == other.revision and self.revision == other.revision and
self.manifestName == other.manifestName and self.manifestName == other.manifestName and
self.groups == other.groups and self.groups == other.groups and
self.default_groups == other.default_groups and
self.path == other.path and self.path == other.path and
sorted(self.annotations) == sorted(other.annotations)) sorted(self.annotations) == sorted(other.annotations))
@ -284,6 +289,7 @@ class _XmlSubmanifest:
revision = self.revision or self.name revision = self.revision or self.name
path = self.path or revision.split('/')[-1] path = self.path or revision.split('/')[-1]
groups = self.groups or [] groups = self.groups or []
default_groups = self.default_groups or []
return SubmanifestSpec(self.name, manifestUrl, manifestName, revision, path, return SubmanifestSpec(self.name, manifestUrl, manifestName, revision, path,
groups) groups)
@ -300,6 +306,10 @@ class _XmlSubmanifest:
return ','.join(self.groups) return ','.join(self.groups)
return '' return ''
def GetDefaultGroupsStr(self):
"""Returns the `default-groups` given for this submanifest."""
return ','.join(self.default_groups or [])
def AddAnnotation(self, name, value, keep): def AddAnnotation(self, name, value, keep):
"""Add annotations to the submanifest.""" """Add annotations to the submanifest."""
self.annotations.append(Annotation(name, value, keep)) self.annotations.append(Annotation(name, value, keep))
@ -327,7 +337,8 @@ class XmlManifest(object):
"""manages the repo configuration file""" """manages the repo configuration file"""
def __init__(self, repodir, manifest_file, local_manifests=None, def __init__(self, repodir, manifest_file, local_manifests=None,
outer_client=None, parent_groups='', submanifest_path=''): outer_client=None, parent_groups='', submanifest_path='',
default_groups=None):
"""Initialize. """Initialize.
Args: Args:
@ -340,6 +351,7 @@ class XmlManifest(object):
outer_client: RepoClient of the outertree. outer_client: RepoClient of the outertree.
parent_groups: a string, the groups to apply to this projects. parent_groups: a string, the groups to apply to this projects.
submanifest_path: The submanifest root relative to the repo root. submanifest_path: The submanifest root relative to the repo root.
default_groups: a string, the default manifest groups to use.
""" """
# TODO(vapier): Move this out of this class. # TODO(vapier): Move this out of this class.
self.globalConfig = GitConfig.ForUser() self.globalConfig = GitConfig.ForUser()
@ -358,6 +370,7 @@ class XmlManifest(object):
self.local_manifests = local_manifests self.local_manifests = local_manifests
self._load_local_manifests = True self._load_local_manifests = True
self.parent_groups = parent_groups self.parent_groups = parent_groups
self.default_groups = default_groups
if outer_client and self.isGitcClient: if outer_client and self.isGitcClient:
raise ManifestParseError('Multi-manifest is incompatible with `gitc-init`') raise ManifestParseError('Multi-manifest is incompatible with `gitc-init`')
@ -472,6 +485,8 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
e.setAttribute('path', r.path) e.setAttribute('path', r.path)
if r.groups: if r.groups:
e.setAttribute('groups', r.GetGroupsStr()) e.setAttribute('groups', r.GetGroupsStr())
if r.default_groups:
e.setAttribute('default-groups', r.GetDefaultGroupsStr())
for a in r.annotations: for a in r.annotations:
if a.keep == 'true': if a.keep == 'true':
@ -967,16 +982,21 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
worktree=os.path.join(subdir, 'manifests')) worktree=os.path.join(subdir, 'manifests'))
return mp return mp
def GetDefaultGroupsStr(self): def GetDefaultGroupsStr(self, with_platform=True):
"""Returns the default group string for the platform.""" """Returns the default group string to use.
return 'default,platform-' + platform.system().lower()
Args:
with_platform: a boolean, whether to include the group for the
underlying platform.
"""
groups = ','.join(self.default_groups or ['default'])
if with_platform:
groups += f',platform-{platform.system().lower()}'
return groups
def GetGroupsStr(self): def GetGroupsStr(self):
"""Returns the manifest group string that should be synced.""" """Returns the manifest group string that should be synced."""
groups = self.manifestProject.manifest_groups return self.manifestProject.manifest_groups or self.GetDefaultGroupsStr()
if not groups:
groups = self.GetDefaultGroupsStr()
return groups
def Unload(self): def Unload(self):
"""Unload the manifest. """Unload the manifest.
@ -1491,6 +1511,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
if node.hasAttribute('groups'): if node.hasAttribute('groups'):
groups = node.getAttribute('groups') groups = node.getAttribute('groups')
groups = self._ParseList(groups) groups = self._ParseList(groups)
default_groups = self._ParseList(node.getAttribute('default-groups'))
path = node.getAttribute('path') path = node.getAttribute('path')
if path == '': if path == '':
path = None path = None
@ -1511,7 +1532,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
'<submanifest> invalid "path": %s: %s' % (path, msg)) '<submanifest> invalid "path": %s: %s' % (path, msg))
submanifest = _XmlSubmanifest(name, remote, project, revision, manifestName, submanifest = _XmlSubmanifest(name, remote, project, revision, manifestName,
groups, path, self) groups, default_groups, path, self)
for n in node.childNodes: for n in node.childNodes:
if n.nodeName == 'annotation': if n.nodeName == 'annotation':

View File

@ -715,7 +715,8 @@ class Project(object):
The special manifest group "default" will match any project that The special manifest group "default" will match any project that
does not have the special project group "notdefault" does not have the special project group "notdefault"
""" """
expanded_manifest_groups = manifest_groups or ['default'] default_groups = self.manifest.default_groups or ['default']
expanded_manifest_groups = manifest_groups or default_groups
expanded_project_groups = ['all'] + (self.groups or []) expanded_project_groups = ['all'] + (self.groups or [])
if 'notdefault' not in expanded_project_groups: if 'notdefault' not in expanded_project_groups:
expanded_project_groups += ['default'] expanded_project_groups += ['default']
@ -3496,7 +3497,7 @@ class ManifestProject(MetaProject):
""" """
assert _kwargs_only == (), 'Sync only accepts keyword arguments.' assert _kwargs_only == (), 'Sync only accepts keyword arguments.'
groups = groups or 'default' groups = groups or self.manifest.GetDefaultGroupsStr(with_platform=False)
platform = platform or 'auto' platform = platform or 'auto'
git_event_log = git_event_log or EventLog() git_event_log = git_event_log or EventLog()
if outer_manifest and self.manifest.is_submanifest: if outer_manifest and self.manifest.is_submanifest:

View File

@ -65,8 +65,7 @@ class Info(PagedCommand):
self.manifest = self.manifest.outer_client self.manifest = self.manifest.outer_client
manifestConfig = self.manifest.manifestProject.config manifestConfig = self.manifest.manifestProject.config
mergeBranch = manifestConfig.GetBranch("default").merge mergeBranch = manifestConfig.GetBranch("default").merge
manifestGroups = (manifestConfig.GetString('manifest.groups') manifestGroups = self.manifest.GetGroupsStr()
or 'all,-notdefault')
self.heading("Manifest branch: ") self.heading("Manifest branch: ")
if self.manifest.default.revisionExpr: if self.manifest.default.revisionExpr: