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/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 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()