From d4a269b40f43748d9437a0a90c462bdfb190f1b9 Mon Sep 17 00:00:00 2001 From: Julien Masson Date: Thu, 5 Sep 2024 16:38:27 +0200 Subject: [PATCH] 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()