From e82647737af4dd246b59975dfca5cfb39de00bb2 Mon Sep 17 00:00:00 2001 From: Julien Masson Date: Fri, 6 Sep 2024 12:35:34 +0200 Subject: [PATCH 1/2] requirements: add setuptools setuptools must be present in the requirements, otherwise we have the following errors: ``` $ make test ... ====================================================================== ERROR: repo_resource.test_check (unittest.loader._FailedTest.repo_resource.test_check) ---------------------------------------------------------------------- ImportError: Failed to import test module: repo_resource.test_check Traceback (most recent call last): File "/usr/local/lib/python3.12/unittest/loader.py", line 396, in _find_test_path module = self._get_module_from_name(name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/unittest/loader.py", line 339, in _get_module_from_name __import__(name) File "/root/repo_resource/test_check.py", line 16, in from . import check File "/root/repo_resource/check.py", line 19, in from repo_resource import common File "/root/repo_resource/common.py", line 27, in from repo import main as repo File "/usr/local/lib/python3.12/site-packages/repo/main.py", line 48, in from repo.subcmds.version import Version File "/usr/local/lib/python3.12/site-packages/repo/subcmds/__init__.py", line 18, in import pkg_resources ModuleNotFoundError: No module named 'pkg_resources' ``` Signed-off-by: Julien Masson --- repo_resource/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/repo_resource/requirements.txt b/repo_resource/requirements.txt index 54349a8..45ffbba 100644 --- a/repo_resource/requirements.txt +++ b/repo_resource/requirements.txt @@ -1,3 +1,4 @@ +setuptools==74.1.2 gitrepo==2.32.2 ssh-agent-setup==2.0.1 GitPython==3.1.31 From 877aba82d2dfdd4ba010d41e96e45efe6e6f93ae Mon Sep 17 00:00:00 2001 From: Julien Masson Date: Thu, 5 Sep 2024 16:38:27 +0200 Subject: [PATCH 2/2] common: resolve recursively include in root manifest The root manifest may have 'include' tag, we should resolve recursively these elements and add the contents of the subsequent manifests found in the root manifest. Signed-off-by: Julien Masson --- repo_resource/common.py | 19 +++++++++++++++++++ repo_resource/test_check.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/repo_resource/common.py b/repo_resource/common.py index 81c599c..6148dde 100644 --- a/repo_resource/common.py +++ b/repo_resource/common.py @@ -376,6 +376,24 @@ def __manifest_out(self, filename): finally: self.__restore_oldpwd() + def resolve_manifest_include(self, manifest): + for idx, element in enumerate(list(manifest.iter())): + if element.tag == 'include': + sub_manifest_name = element.get('name') + sub_xml = ET.parse('.repo/manifests/'+sub_manifest_name) + sub_manifest = sub_xml.getroot() + + # resolve recursively include in sub manifests + self.resolve_manifest_include(sub_manifest) + + # insert sub manifest in the parent without 'manifest' elements + for sub_element in reversed(list(sub_manifest.iter())): + if sub_element.tag != 'manifest': + manifest.insert(idx, sub_element) + + # remove 'include' element + manifest.remove(element) + def update_manifest(self, jobs): projects = [] removed_projects = [] @@ -387,6 +405,7 @@ def update_manifest(self, jobs): print('Updating project revisions in manifest') xml = ET.parse('.repo/manifests/'+self.__name) manifest = xml.getroot() + self.resolve_manifest_include(manifest) for r in manifest.findall('remote'): url = r.get('fetch').rstrip('/') diff --git a/repo_resource/test_check.py b/repo_resource/test_check.py index 34b6182..7debee6 100644 --- a/repo_resource/test_check.py +++ b/repo_resource/test_check.py @@ -78,6 +78,20 @@ def setUp(self): 'name': 'aosp_remove_yukawa_project.xml' } } + self.include_one_project_source = { + 'source': { + 'url': 'https://github.com/makohoek/demo-manifests.git', + 'revision': 'main', + 'name': 'aosp_include_one_project.xml' + } + } + self.include_multiple_projects_source = { + 'source': { + 'url': 'https://github.com/makohoek/demo-manifests.git', + 'revision': 'main', + 'name': 'aosp_include_multiple_projects.xml' + } + } def tearDown(self): p = common.CACHEDIR @@ -403,6 +417,26 @@ def test_no_remove_project_element(self): version = versions[0]['version'] self.assertNotIn('remove-project', version) + def test_include_one_project_version(self): + data = self.include_one_project_source + instream = StringIO(json.dumps(data)) + versions = check.check(instream) + + expected_version = '' # noqa: E501 + + version = versions[0]['version'] + self.assertEqual(version, expected_version) + + def test_include_multiple_projects_version(self): + data = self.include_multiple_projects_source + instream = StringIO(json.dumps(data)) + versions = check.check(instream) + + expected_version = '' # noqa: E501 + + version = versions[0]['version'] + self.assertEqual(version, expected_version) + if __name__ == '__main__': unittest.main()