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. Change-Id: I94989519011e31c7db33656c6730c4f8fd5e0a4f
This commit is contained in:
@@ -117,10 +117,6 @@ class SoongConfigBoilerplateInserter(SoongConfigVarTransformation):
|
|||||||
def config_module_type(self, module_type):
|
def config_module_type(self, module_type):
|
||||||
return self.configModuleTypePrefix + 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):
|
def _apply_transformation(self, producer, file, build_release):
|
||||||
# TODO(b/174997203): Remove this when we have a proper way to control
|
# TODO(b/174997203): Remove this when we have a proper way to control
|
||||||
# prefer flags in Mainline modules.
|
# prefer flags in Mainline modules.
|
||||||
@@ -857,6 +853,9 @@ class MainlineModule:
|
|||||||
# Defaults to the last part of the apex name.
|
# Defaults to the last part of the apex name.
|
||||||
short_name: str = ""
|
short_name: str = ""
|
||||||
|
|
||||||
|
# Additional transformations
|
||||||
|
additional_transformations: list[FileTransformation] = None
|
||||||
|
|
||||||
def __post_init__(self):
|
def __post_init__(self):
|
||||||
# If short_name is not set then set it to the last component of the apex
|
# If short_name is not set then set it to the last component of the apex
|
||||||
# name.
|
# name.
|
||||||
@@ -898,6 +897,9 @@ class MainlineModule:
|
|||||||
"Android.bp", configVar=config_var)
|
"Android.bp", configVar=config_var)
|
||||||
transformations.append(transformation)
|
transformations.append(transformation)
|
||||||
|
|
||||||
|
if self.additional_transformations and build_release > R:
|
||||||
|
transformations.extend(self.additional_transformations)
|
||||||
|
|
||||||
return transformations
|
return transformations
|
||||||
|
|
||||||
def is_required_for(self, target_build_release):
|
def is_required_for(self, target_build_release):
|
||||||
|
|||||||
@@ -570,6 +570,42 @@ class TestAndroidBpTransformations(unittest.TestCase):
|
|||||||
|
|
||||||
self.apply_transformations(src, transformations, mm.R, expected)
|
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):
|
class TestFilterModules(unittest.TestCase):
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
Reference in New Issue
Block a user