Adding additional_transformations

Add additional_transformations for module sdk build. This feature is
only supported by S+ releases.

Bug: 254111089
Test: atest mainline_modules_sdks_test --host
Ignore-AOSP-First: Check into internal branch first to make sure all
testing works.

Merged-In: I94989519011e31c7db33656c6730c4f8fd5e0a4f
Change-Id: Idc8bd682550f59e086c431b0be38bfbdf8a75127
This commit is contained in:
Zhi Dou
2023-03-17 16:20:59 +00:00
committed by zhidou
parent b50e8ce2fb
commit 7c3ab89443
3 changed files with 132 additions and 18 deletions

View File

@@ -570,6 +570,42 @@ class TestAndroidBpTransformations(unittest.TestCase):
self.apply_transformations(src, transformations, mm.R, expected)
def test_additional_transformation(self):
"""Tests additional transformation.
This uses ipsec as an example of a common case for adding information
in Android.bp file.
This checks will append the information in Android.bp for a regular module.
"""
@dataclasses.dataclass(frozen=True)
class TestTransformation(mm.FileTransformation):
"""Transforms an Android.bp file by appending testing message."""
test_content: str = ""
def apply(self, producer, path, build_release):
with open(path, "a+", encoding="utf8") as file:
self._apply_transformation(producer, file, build_release)
def _apply_transformation(self, producer, file, build_release):
if build_release >= mm.Tiramisu:
file.write(self.test_content)
src = read_test_data("ipsec_Android.bp.input")
expected = read_test_data(
"ipsec_tiramisu_Android.bp.additional.expected")
test_transformation = TestTransformation(
"Android.bp", test_content="\n// Adding by test")
module = MAINLINE_MODULES_BY_APEX["com.android.ipsec"]
module = dataclasses.replace(
module, apex=module.apex,
first_release=module.first_release,
additional_transformations=[test_transformation])
transformations = module.transformations(mm.Tiramisu, mm.Sdk)
self.apply_transformations(src, transformations, mm.Tiramisu, expected)
class TestFilterModules(unittest.TestCase):