diff --git a/command.py b/command.py index 90bd0021..f708832e 100644 --- a/command.py +++ b/command.py @@ -178,9 +178,7 @@ class Command(object): 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 651da48a..7f0582cb 100644 --- a/git_superproject.py +++ b/git_superproject.py @@ -235,7 +235,7 @@ class Superproject(object): 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 a2786c9f..486bbeb0 100644 --- a/gitc_utils.py +++ b/gitc_utils.py @@ -77,22 +77,6 @@ def _set_project_revisions(projects): 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 @@ def generate_gitc_manifest(gitc_manifest, manifest, paths=None): 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 @@ def save_manifest(manifest, client_dir=None): 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 e96e0620..6d8fca1d 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 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md 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 471efc1e..86b77742 100644 --- a/subcmds/init.py +++ b/subcmds/init.py @@ -267,7 +267,7 @@ to update the working directory files. 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 07b9a7db..9550949b 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 @@ class SuperprojectTestCase(unittest.TestCase): 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 @@ class SuperprojectTestCase(unittest.TestCase): - - + """) self._superproject = git_superproject.Superproject(manifest, self.repodir) @@ -142,7 +144,8 @@ class SuperprojectTestCase(unittest.TestCase): '' + '' + '' + - '' + + '' + '' + '') @@ -169,7 +172,8 @@ class SuperprojectTestCase(unittest.TestCase): '' + '' + '' + + 'revision="2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea" ' + + 'groups="notdefault,platform-' + self.platform + '"/>' + '' + '') diff --git a/tests/test_manifest_xml.py b/tests/test_manifest_xml.py index 6977b417..9060ef3d 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 @@ class ProjectElementTests(ManifestParseTestCase): 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."""