Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common: resolve recursively include in root manifest #39

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
makohoek marked this conversation as resolved.
Show resolved Hide resolved
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
1 change: 1 addition & 0 deletions repo_resource/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
setuptools==74.1.2
gitrepo==2.32.2
ssh-agent-setup==2.0.1
GitPython==3.1.31
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()
Loading