From 501733c2abb1180679f25b2f78970d73a2f8d413 Mon Sep 17 00:00:00 2001 From: LaMont Jones Date: Wed, 20 Apr 2022 16:42:32 +0000 Subject: 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 Reviewed-by: Mike Frysinger --- manifest_xml.py | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) (limited to 'manifest_xml.py') diff --git a/manifest_xml.py b/manifest_xml.py index dbab974b..3c43295e 100644 --- a/manifest_xml.py +++ b/manifest_xml.py @@ -214,6 +214,7 @@ class _XmlSubmanifest: revision: a string, the commitish. manifestName: a string, the submanifest file name. 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. parent: an XmlManifest, the parent manifest. annotations: (derived) a list of annotations. @@ -226,6 +227,7 @@ class _XmlSubmanifest: revision=None, manifestName=None, groups=None, + default_groups=None, path=None, parent=None): self.name = name @@ -234,6 +236,7 @@ class _XmlSubmanifest: self.revision = revision self.manifestName = manifestName self.groups = groups + self.default_groups = default_groups self.path = path self.parent = parent self.annotations = [] @@ -250,7 +253,8 @@ class _XmlSubmanifest: os.path.join(parent.path_prefix, self.relpath), MANIFEST_FILE_NAME) rc = self.repo_client = RepoClient( 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) @@ -264,6 +268,7 @@ class _XmlSubmanifest: self.revision == other.revision and self.manifestName == other.manifestName and self.groups == other.groups and + self.default_groups == other.default_groups and self.path == other.path and sorted(self.annotations) == sorted(other.annotations)) @@ -284,6 +289,7 @@ class _XmlSubmanifest: revision = self.revision or self.name path = self.path or revision.split('/')[-1] groups = self.groups or [] + default_groups = self.default_groups or [] return SubmanifestSpec(self.name, manifestUrl, manifestName, revision, path, groups) @@ -300,6 +306,10 @@ class _XmlSubmanifest: return ','.join(self.groups) return '' + def GetDefaultGroupsStr(self): + """Returns the `default-groups` given for this submanifest.""" + return ','.join(self.default_groups or []) + def AddAnnotation(self, name, value, keep): """Add annotations to the submanifest.""" self.annotations.append(Annotation(name, value, keep)) @@ -327,7 +337,8 @@ class XmlManifest(object): """manages the repo configuration file""" 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. Args: @@ -340,6 +351,7 @@ class XmlManifest(object): outer_client: RepoClient of the outertree. parent_groups: a string, the groups to apply to this projects. 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. self.globalConfig = GitConfig.ForUser() @@ -358,6 +370,7 @@ class XmlManifest(object): self.local_manifests = local_manifests self._load_local_manifests = True self.parent_groups = parent_groups + self.default_groups = default_groups if outer_client and self.isGitcClient: 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) if r.groups: e.setAttribute('groups', r.GetGroupsStr()) + if r.default_groups: + e.setAttribute('default-groups', r.GetDefaultGroupsStr()) for a in r.annotations: 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')) return mp - def GetDefaultGroupsStr(self): - """Returns the default group string for the platform.""" - return 'default,platform-' + platform.system().lower() + def GetDefaultGroupsStr(self, with_platform=True): + """Returns the default group string to use. + + 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): """Returns the manifest group string that should be synced.""" - groups = self.manifestProject.manifest_groups - if not groups: - groups = self.GetDefaultGroupsStr() - return groups + return self.manifestProject.manifest_groups or self.GetDefaultGroupsStr() def Unload(self): """Unload the manifest. @@ -1491,6 +1511,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md if node.hasAttribute('groups'): groups = node.getAttribute('groups') groups = self._ParseList(groups) + default_groups = self._ParseList(node.getAttribute('default-groups')) path = node.getAttribute('path') if path == '': path = None @@ -1511,7 +1532,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md ' invalid "path": %s: %s' % (path, msg)) submanifest = _XmlSubmanifest(name, remote, project, revision, manifestName, - groups, path, self) + groups, default_groups, path, self) for n in node.childNodes: if n.nodeName == 'annotation': -- cgit v1.2.3-54-g00ecf