From 352c93b68084e97ec7a3c09f0bd3f2a161290211 Mon Sep 17 00:00:00 2001 From: Fredrik de Groot Date: Tue, 6 Oct 2020 12:55:14 +0200 Subject: manifest: add support for groups in include Attrib groups can now be added to manifest include, thus all projects in an included manifest file can easily be tagged with a group without modifying all projects in that manifest file. Include groups will add and recurse, meaning included manifest projects will carry all parent includes. Intentionally, no support added for group remove, to keep complexity down. Group handling for projects is untouched, meaning a group set on a project will still append to whatever was or was not inherited in parent manifest includes, resulting in union of groups inherited and set for the project itself. Test: manual multi-level manifest include structure, in serial and parallel, with different groups set on init Test: added unit tests to cover the inheritance Change-Id: Id2229aa6fd78d355ba598cc15c701b2ee71e5c6f Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/283587 Tested-by: Fredrik de Groot Reviewed-by: Mike Frysinger --- manifest_xml.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'manifest_xml.py') diff --git a/manifest_xml.py b/manifest_xml.py index 95c67d73..ad0017cc 100644 --- a/manifest_xml.py +++ b/manifest_xml.py @@ -637,7 +637,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md self._loaded = True - def _ParseManifestXml(self, path, include_root): + def _ParseManifestXml(self, path, include_root, parent_groups=''): try: root = xml.dom.minidom.parse(path) except (OSError, xml.parsers.expat.ExpatError) as e: @@ -656,12 +656,17 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md for node in manifest.childNodes: if node.nodeName == 'include': name = self._reqatt(node, 'name') + include_groups = '' + if parent_groups: + include_groups = parent_groups + if node.hasAttribute('groups'): + include_groups = node.getAttribute('groups') + ',' + include_groups fp = os.path.join(include_root, name) if not os.path.isfile(fp): raise ManifestParseError("include %s doesn't exist or isn't a file" % (name,)) try: - nodes.extend(self._ParseManifestXml(fp, include_root)) + nodes.extend(self._ParseManifestXml(fp, include_root, include_groups)) # should isolate this to the exact exception, but that's # tricky. actual parsing implementation may vary. except (KeyboardInterrupt, RuntimeError, SystemExit): @@ -670,6 +675,11 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md raise ManifestParseError( "failed parsing included manifest %s: %s" % (name, e)) else: + if parent_groups and node.nodeName == 'project': + nodeGroups = parent_groups + if node.hasAttribute('groups'): + nodeGroups = node.getAttribute('groups') + ',' + nodeGroups + node.setAttribute('groups', nodeGroups) nodes.append(node) return nodes -- cgit v1.2.3-54-g00ecf