superproject: pass groups to ToXml method.
Added the following methods to XmlManifest class.
+ GetDefaultGroupsStr() - return 'default,platform-' + platform.system().lower()
+ GetGroupsStr() - Same as gitc_utils.py's _manifest_groups func.
+ Replaced gitc_utils.py's_manifest_groups calls with GetGroupsStr.
+ Used the above methods to get groups in command.py::GetProjects
and part of init.py.
TODO: clean up these funcs to take structured group data more instead
of passing strings around everywhere that need parsing.
Tested the code with the following commands.
$ ./run_tests -v
Tested the sync code by using repo_dev alias and pointing to this CL
and verified prebuilts/fullsdk-linux directory has all the folders.
Tested repo init and repo sync with --use-superproject and without
--use-superproject argument.
$ repo_dev init -u sso://android.git.corp.google.com/platform/manifest -b androidx-main --partial-clone --clone-filter=blob:limit=10M --repo-rev=main --use-superproject
$ repo_dev sync -c -j32
Bug: [google internal] b/181804931
Bug: https://crbug.com/gerrit/13707
Change-Id: Ia98585cbfa3a1449710655af55d56241794242b6
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/299422
Reviewed-by: Jonathan Nieder <jrn@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
Tested-by: Raman Tenneti <rtenneti@google.com>
diff --git a/command.py b/command.py
index 90bd002..f708832 100644
--- a/command.py
+++ b/command.py
@@ -178,9 +178,7 @@
mp = manifest.manifestProject
if not groups:
- groups = mp.config.GetString('manifest.groups')
- if not groups:
- groups = 'default,platform-' + platform.system().lower()
+ groups = manifest.GetGroupsStr()
groups = [x for x in re.split(r'[,\s]+', groups) if x]
if not args:
diff --git a/git_superproject.py b/git_superproject.py
index 651da48..7f0582c 100644
--- a/git_superproject.py
+++ b/git_superproject.py
@@ -235,7 +235,7 @@
self._superproject_path,
file=sys.stderr)
return None
- manifest_str = self._manifest.ToXml().toxml()
+ manifest_str = self._manifest.ToXml(groups=self._manifest.GetGroupsStr()).toxml()
manifest_path = self._manifest_path
try:
with open(manifest_path, 'w', encoding='utf-8') as fp:
diff --git a/gitc_utils.py b/gitc_utils.py
index a2786c9..486bbeb 100644
--- a/gitc_utils.py
+++ b/gitc_utils.py
@@ -77,22 +77,6 @@
project.revisionExpr = revisionExpr
-def _manifest_groups(manifest):
- """Returns the manifest group string that should be synced
-
- This is the same logic used by Command.GetProjects(), which is used during
- repo sync
-
- Args:
- manifest: The XmlManifest object
- """
- mp = manifest.manifestProject
- groups = mp.config.GetString('manifest.groups')
- if not groups:
- groups = 'default,platform-' + platform.system().lower()
- return groups
-
-
def generate_gitc_manifest(gitc_manifest, manifest, paths=None):
"""Generate a manifest for shafsd to use for this GITC client.
@@ -107,7 +91,7 @@
if paths is None:
paths = list(manifest.paths.keys())
- groups = [x for x in re.split(r'[,\s]+', _manifest_groups(manifest)) if x]
+ groups = [x for x in re.split(r'[,\s]+', manifest.GetGroupsStr()) if x]
# Convert the paths to projects, and filter them to the matched groups.
projects = [manifest.paths[p] for p in paths]
@@ -166,7 +150,7 @@
else:
manifest_file = os.path.join(client_dir, '.manifest')
with open(manifest_file, 'w') as f:
- manifest.Save(f, groups=_manifest_groups(manifest))
+ manifest.Save(f, groups=manifest.GetGroupsStr())
# TODO(sbasi/jorg): Come up with a solution to remove the sleep below.
# Give the GITC filesystem time to register the manifest changes.
time.sleep(3)
diff --git a/manifest_xml.py b/manifest_xml.py
index e96e062..6d8fca1 100644
--- a/manifest_xml.py
+++ b/manifest_xml.py
@@ -14,6 +14,7 @@
import itertools
import os
+import platform
import re
import sys
import xml.dom.minidom
@@ -604,6 +605,17 @@
def HasSubmodules(self):
return self.manifestProject.config.GetBoolean('repo.submodules')
+ def GetDefaultGroupsStr(self):
+ """Returns the default group string for the platform."""
+ return 'default,platform-' + platform.system().lower()
+
+ def GetGroupsStr(self):
+ """Returns the manifest group string that should be synced."""
+ groups = self.manifestProject.config.GetString('manifest.groups')
+ if not groups:
+ groups = self.GetDefaultGroupsStr()
+ return groups
+
def _Unload(self):
self._loaded = False
self._projects = {}
diff --git a/subcmds/init.py b/subcmds/init.py
index 471efc1..86b7774 100644
--- a/subcmds/init.py
+++ b/subcmds/init.py
@@ -267,7 +267,7 @@
groups = [x for x in groups if x]
groupstr = ','.join(groups)
- if opt.platform == 'auto' and groupstr == 'default,platform-' + platform.system().lower():
+ if opt.platform == 'auto' and groupstr == self.manifest.GetDefaultGroupsStr():
groupstr = None
m.config.SetString('manifest.groups', groupstr)
diff --git a/tests/test_git_superproject.py b/tests/test_git_superproject.py
index 07b9a7d..9550949 100644
--- a/tests/test_git_superproject.py
+++ b/tests/test_git_superproject.py
@@ -15,6 +15,7 @@
"""Unittests for the git_superproject.py module."""
import os
+import platform
import tempfile
import unittest
from unittest import mock
@@ -34,6 +35,7 @@
self.manifest_file = os.path.join(
self.repodir, manifest_xml.MANIFEST_FILE_NAME)
os.mkdir(self.repodir)
+ self.platform = platform.system().lower()
# The manifest parsing really wants a git repo currently.
gitdir = os.path.join(self.repodir, 'manifests.git')
@@ -48,8 +50,8 @@
<remote name="default-remote" fetch="http://localhost" />
<default remote="default-remote" revision="refs/heads/main" />
<superproject name="superproject"/>
- <project path="art" name="platform/art" />
-</manifest>
+ <project path="art" name="platform/art" groups="notdefault,platform-""" + self.platform + """
+ " /></manifest>
""")
self._superproject = git_superproject.Superproject(manifest, self.repodir)
@@ -142,7 +144,8 @@
'<?xml version="1.0" ?><manifest>' +
'<remote name="default-remote" fetch="http://localhost"/>' +
'<default remote="default-remote" revision="refs/heads/main"/>' +
- '<project name="platform/art" path="art" revision="ABCDEF"/>' +
+ '<project name="platform/art" path="art" revision="ABCDEF" ' +
+ 'groups="notdefault,platform-' + self.platform + '"/>' +
'<superproject name="superproject"/>' +
'</manifest>')
@@ -169,7 +172,8 @@
'<remote name="default-remote" fetch="http://localhost"/>' +
'<default remote="default-remote" revision="refs/heads/main"/>' +
'<project name="platform/art" path="art" ' +
- 'revision="2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea"/>' +
+ 'revision="2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea" ' +
+ 'groups="notdefault,platform-' + self.platform + '"/>' +
'<superproject name="superproject"/>' +
'</manifest>')
diff --git a/tests/test_manifest_xml.py b/tests/test_manifest_xml.py
index 6977b41..9060ef3 100644
--- a/tests/test_manifest_xml.py
+++ b/tests/test_manifest_xml.py
@@ -15,6 +15,7 @@
"""Unittests for the manifest_xml.py module."""
import os
+import platform
import shutil
import tempfile
import unittest
@@ -377,6 +378,11 @@
self.assertCountEqual(
result['extras'],
['g1', 'g2', 'g1', 'name:extras', 'all', 'path:path'])
+ groupstr = 'default,platform-' + platform.system().lower()
+ self.assertEqual(groupstr, manifest.GetGroupsStr())
+ groupstr = 'g1,g2,g1'
+ manifest.manifestProject.config.SetString('manifest.groups', groupstr)
+ self.assertEqual(groupstr, manifest.GetGroupsStr())
def test_set_revision_id(self):
"""Check setting of project's revisionId."""