Skip to content

Commit

Permalink
common: resolve recursively include in root manifest
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
massonju authored and makohoek committed Sep 10, 2024
1 parent f43d57a commit d4a269b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
19 changes: 19 additions & 0 deletions repo_resource/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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('/')
Expand Down
34 changes: 34 additions & 0 deletions repo_resource/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = '<manifest><remote fetch=\"https://android.googlesource.com/\" name=\"aosp\"></remote><default remote=\"aosp\" revision=\"refs/tags/android-12.0.0_r32\"></default><project groups=\"pdk\" name=\"device/generic/common\" path=\"device/generic/common\" revision=\"033d50e2298811d81de7db8cdea63e349a96c9ba\"></project><remote fetch=\"https://github.com/\" name=\"github\"></remote><project name=\"CirrusLogic/tinyhal\" path=\"external/tinyhal\" remote=\"github\" revision=\"69d47887c13da461bf8400231a1c7f7290826037\"></project></manifest>' # 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 = '<manifest><remote fetch=\"https://android.googlesource.com/\" name=\"aosp\"></remote><default remote=\"aosp\" revision=\"refs/tags/android-12.0.0_r32\"></default><remote fetch=\"https://github.com/\" name=\"github\"></remote><project name=\"wimglenn/oyaml\" path=\"external/oyaml\" remote=\"github\" revision=\"6350d9de586f40014296b55427ccbc1d7f47269a\"></project><remote fetch=\"https://github.com/\" name=\"github\"></remote><project name=\"OP-TEE/optee_client\" path=\"vendor/linaro/optee_client\" remote=\"github\" revision=\"8533e0e6329840ee96cf81b6453f257204227e6c\"></project><project groups=\"pdk\" name=\"device/generic/common\" path=\"device/generic/common\" revision=\"033d50e2298811d81de7db8cdea63e349a96c9ba\"></project><remote fetch=\"https://github.com/\" name=\"github\"></remote><project name=\"CirrusLogic/tinyhal\" path=\"external/tinyhal\" remote=\"github\" revision=\"69d47887c13da461bf8400231a1c7f7290826037\"></project></manifest>' # noqa: E501

version = versions[0]['version']
self.assertEqual(version, expected_version)


if __name__ == '__main__':
unittest.main()

0 comments on commit d4a269b

Please sign in to comment.