diff --git a/build/mainline_modules_sdks.py b/build/mainline_modules_sdks.py index 6bff48a..b52b85a 100755 --- a/build/mainline_modules_sdks.py +++ b/build/mainline_modules_sdks.py @@ -117,10 +117,6 @@ class SoongConfigBoilerplateInserter(SoongConfigVarTransformation): def config_module_type(self, module_type): return self.configModuleTypePrefix + module_type - def apply(self, producer, path, build_release): - with open(path, "r+", encoding="utf8") as file: - self._apply_transformation(producer, file, build_release) - def _apply_transformation(self, producer, file, build_release): # TODO(b/174997203): Remove this when we have a proper way to control # prefer flags in Mainline modules. @@ -864,6 +860,9 @@ class MainlineModule: # Defaults to the last part of the apex name. short_name: str = "" + # Additional transformations + additional_transformations: list[FileTransformation] = None + def __post_init__(self): # If short_name is not set then set it to the last component of the apex # name. @@ -905,6 +904,9 @@ class MainlineModule: "Android.bp", configVar=config_var) transformations.append(transformation) + if self.additional_transformations and build_release > R: + transformations.extend(self.additional_transformations) + return transformations def is_required_for(self, target_build_release): diff --git a/build/mainline_modules_sdks_test.py b/build/mainline_modules_sdks_test.py index ee5ba57..2131a60 100644 --- a/build/mainline_modules_sdks_test.py +++ b/build/mainline_modules_sdks_test.py @@ -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): diff --git a/build/mainline_modules_sdks_test_data/ipsec_tiramisu_Android.bp.additional.expected b/build/mainline_modules_sdks_test_data/ipsec_tiramisu_Android.bp.additional.expected new file mode 100644 index 0000000..2b844ab --- /dev/null +++ b/build/mainline_modules_sdks_test_data/ipsec_tiramisu_Android.bp.additional.expected @@ -0,0 +1,79 @@ +// This is auto-generated. DO NOT EDIT. + +package { + // A default list here prevents the license LSC from adding its own list which would + // be unnecessary as every module in the sdk already has its own licenses property. + default_applicable_licenses: ["Android-Apache-2.0"], +} + +prebuilt_bootclasspath_fragment { + name: "com.android.ipsec-bootclasspath-fragment", + // Do not prefer prebuilt if the Soong config variable "module_build_from_source" in namespace "ANDROID" is true. + use_source_config_var: { + config_namespace: "ANDROID", + var_name: "module_build_from_source", + }, + visibility: ["//visibility:public"], + apex_available: ["com.android.ipsec"], + licenses: ["ipsec-module-sdk_Android-Apache-2.0"], + contents: ["android.net.ipsec.ike"], + hidden_api: { + stub_flags: "hiddenapi/stub-flags.csv", + annotation_flags: "hiddenapi/annotation-flags.csv", + metadata: "hiddenapi/metadata.csv", + index: "hiddenapi/index.csv", + all_flags: "hiddenapi/all-flags.csv", + }, +} + +java_sdk_library_import { + name: "android.net.ipsec.ike", + // Do not prefer prebuilt if the Soong config variable "module_build_from_source" in namespace "ANDROID" is true. + use_source_config_var: { + config_namespace: "ANDROID", + var_name: "module_build_from_source", + }, + visibility: ["//visibility:public"], + apex_available: [ + "com.android.ipsec", + "test_com.android.ipsec", + ], + licenses: ["ipsec-module-sdk_Android-Apache-2.0"], + shared_library: true, + compile_dex: true, + permitted_packages: [ + "com.android.internal.net", + "android.net.ipsec.ike", + "android.net.eap", + ], + public: { + jars: ["sdk_library/public/android.net.ipsec.ike-stubs.jar"], + stub_srcs: ["sdk_library/public/android.net.ipsec.ike.srcjar"], + current_api: "sdk_library/public/android.net.ipsec.ike.txt", + removed_api: "sdk_library/public/android.net.ipsec.ike-removed.txt", + sdk_version: "module_current", + }, + system: { + jars: ["sdk_library/system/android.net.ipsec.ike-stubs.jar"], + stub_srcs: ["sdk_library/system/android.net.ipsec.ike.srcjar"], + current_api: "sdk_library/system/android.net.ipsec.ike.txt", + removed_api: "sdk_library/system/android.net.ipsec.ike-removed.txt", + sdk_version: "module_current", + }, + module_lib: { + jars: ["sdk_library/module-lib/android.net.ipsec.ike-stubs.jar"], + stub_srcs: ["sdk_library/module-lib/android.net.ipsec.ike.srcjar"], + current_api: "sdk_library/module-lib/android.net.ipsec.ike.txt", + removed_api: "sdk_library/module-lib/android.net.ipsec.ike-removed.txt", + sdk_version: "module_current", + }, +} + +license { + name: "ipsec-module-sdk_Android-Apache-2.0", + visibility: ["//visibility:private"], + license_kinds: ["SPDX-license-identifier-Apache-2.0"], + license_text: ["licenses/build/soong/licenses/LICENSE"], +} + +// Adding by test \ No newline at end of file