aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-03-27 22:48:08 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-03-27 22:48:08 +0000
commitbdb2e1a52e8c9d2d3e670879c6ad8e284e4158a4 (patch)
tree1571b454c3f60288610ab79b53ebbc924d65755d
parent61e8f47c365455ef6d055f322be27223bdd423ab (diff)
parenta87b70166e708c3ad8e5b46eae16186f500ac570 (diff)
downloadcommon-bdb2e1a52e8c9d2d3e670879c6ad8e284e4158a4.tar.gz
Merge cherrypicks of ['googleplex-android-review.googlesource.com/22203161', 'googleplex-android-review.googlesource.com/22225602'] into sparse-9793911-L15400000959387715.aml_wif_331710030
SPARSE_CHANGE: If71a921752f4c481030efb0fd391fb328b5dffb6 SPARSE_CHANGE: I94989519011e31c7db33656c6730c4f8fd5e0a4f Change-Id: I3f234be57d7ae8d5a6cf906282510aea307070bd
-rwxr-xr-xbuild/mainline_modules_sdks.py37
-rw-r--r--build/mainline_modules_sdks_test.py55
-rw-r--r--build/mainline_modules_sdks_test_data/ipsec_tiramisu_Android.bp.additional.expected79
3 files changed, 146 insertions, 25 deletions
diff --git a/build/mainline_modules_sdks.py b/build/mainline_modules_sdks.py
index 55c24d7c..713c8cac 100755
--- a/build/mainline_modules_sdks.py
+++ b/build/mainline_modules_sdks.py
@@ -72,12 +72,12 @@ class FileTransformation:
# The path of the file within the SDK snapshot zip file.
path: str
- def apply(self, producer, path):
+ def apply(self, producer, path, build_release):
"""Apply the transformation to the path; changing it in place."""
with open(path, "r+", encoding="utf8") as file:
- self._apply_transformation(producer, file)
+ self._apply_transformation(producer, file, build_release)
- def _apply_transformation(self, producer, file):
+ def _apply_transformation(self, producer, file, build_release):
"""Apply the transformation to the file.
The file has been opened in read/write mode so the implementation of
@@ -96,7 +96,7 @@ class SoongConfigVarTransformation(FileTransformation):
# The line containing the prefer property.
PREFER_LINE = " prefer: false,"
- def _apply_transformation(self, producer, file):
+ def _apply_transformation(self, producer, file, build_release):
raise NotImplementedError
@@ -117,11 +117,7 @@ class SoongConfigBoilerplateInserter(SoongConfigVarTransformation):
def config_module_type(self, module_type):
return self.configModuleTypePrefix + module_type
- def apply(self, producer, path):
- with open(path, "r+", encoding="utf8") as file:
- self._apply_transformation(producer, file)
-
- def _apply_transformation(self, producer, file):
+ 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.
@@ -228,7 +224,7 @@ soong_config_module_type {{
@dataclasses.dataclass(frozen=True)
class UseSourceConfigVarTransformation(SoongConfigVarTransformation):
- def _apply_transformation(self, producer, file):
+ def _apply_transformation(self, producer, file, build_release):
lines = []
for line in file:
line = line.rstrip("\n")
@@ -822,6 +818,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.
@@ -863,6 +862,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):
@@ -1204,9 +1206,11 @@ class SdkDistProducer:
sdk_path = sdk_snapshot_zip_file(snapshots_dir, sdk)
sdk_type = sdk_type_from_name(sdk)
transformations = module.transformations(build_release, sdk_type)
- self.dist_sdk_snapshot_zip(sdk_path, sdk_dist_subdir, transformations)
+ self.dist_sdk_snapshot_zip(
+ build_release, sdk_path, sdk_dist_subdir, transformations)
- def dist_sdk_snapshot_zip(self, src_sdk_zip, sdk_dist_dir, transformations):
+ def dist_sdk_snapshot_zip(
+ self, build_release, src_sdk_zip, sdk_dist_dir, transformations):
"""Copy the sdk snapshot zip file to a dist directory.
If no transformations are provided then this simply copies the show sdk
@@ -1214,7 +1218,8 @@ class SdkDistProducer:
provided then the files to be transformed are extracted from the
snapshot zip file, they are transformed to files in a separate directory
and then a new zip file is created in the dist directory with the
- original files replaced by the newly transformed files.
+ original files replaced by the newly transformed files. build_release is
+ provided for transformations if it is needed.
"""
os.makedirs(sdk_dist_dir, exist_ok=True)
dest_sdk_zip = os.path.join(sdk_dist_dir, os.path.basename(src_sdk_zip))
@@ -1237,7 +1242,7 @@ class SdkDistProducer:
extract_matching_files_from_zip(src_sdk_zip, tmp_dir, pattern)
# Apply the transformations to the extracted files in situ.
- apply_transformations(self, tmp_dir, transformations)
+ apply_transformations(self, tmp_dir, transformations, build_release)
# Replace the original entries in the zip with the transformed
# files.
@@ -1291,7 +1296,7 @@ def copy_zip_and_replace(producer, src_zip_path, dest_zip_path, src_dir, paths):
cwd=src_dir)
-def apply_transformations(producer, tmp_dir, transformations):
+def apply_transformations(producer, tmp_dir, transformations, build_release):
for transformation in transformations:
path = os.path.join(tmp_dir, transformation.path)
@@ -1299,7 +1304,7 @@ def apply_transformations(producer, tmp_dir, transformations):
modified = os.path.getmtime(path)
# Transform the file.
- transformation.apply(producer, path)
+ transformation.apply(producer, path, build_release)
# Reset the timestamp of the file to the original timestamp before the
# transformation was applied.
diff --git a/build/mainline_modules_sdks_test.py b/build/mainline_modules_sdks_test.py
index e66b3bb2..3c1484c8 100644
--- a/build/mainline_modules_sdks_test.py
+++ b/build/mainline_modules_sdks_test.py
@@ -405,7 +405,7 @@ def read_test_data(relative_path):
class TestAndroidBpTransformations(unittest.TestCase):
- def apply_transformations(self, src, transformations, expected):
+ def apply_transformations(self, src, transformations, build_release, expected):
producer = mm.SdkDistProducer(
subprocess_runner=mock.Mock(mm.SubprocessRunner),
snapshot_builder=mock.Mock(mm.SnapshotBuilder),
@@ -417,7 +417,8 @@ class TestAndroidBpTransformations(unittest.TestCase):
with open(path, "w", encoding="utf8") as f:
f.write(src)
- mm.apply_transformations(producer, tmp_dir, transformations)
+ mm.apply_transformations(
+ producer, tmp_dir, transformations, build_release)
with open(path, "r", encoding="utf8") as f:
result = f.read()
@@ -438,7 +439,7 @@ class TestAndroidBpTransformations(unittest.TestCase):
module = MAINLINE_MODULES_BY_APEX["com.android.ipsec"]
transformations = module.transformations(mm.S, mm.Sdk)
- self.apply_transformations(src, transformations, expected)
+ self.apply_transformations(src, transformations, mm.S, expected)
def test_common_mainline_module_tiramisu(self):
"""Tests the transformations applied to a common mainline sdk on T.
@@ -453,7 +454,7 @@ class TestAndroidBpTransformations(unittest.TestCase):
module = MAINLINE_MODULES_BY_APEX["com.android.ipsec"]
transformations = module.transformations(mm.Tiramisu, mm.Sdk)
- self.apply_transformations(src, transformations, expected)
+ self.apply_transformations(src, transformations, mm.Tiramisu, expected)
def test_optional_mainline_module(self):
"""Tests the transformations applied to an optional mainline sdk on S.
@@ -469,7 +470,7 @@ class TestAndroidBpTransformations(unittest.TestCase):
module = MAINLINE_MODULES_BY_APEX["com.android.wifi"]
transformations = module.transformations(mm.S, mm.Sdk)
- self.apply_transformations(src, transformations, expected)
+ self.apply_transformations(src, transformations, mm.S, expected)
def test_optional_mainline_module_tiramisu(self):
"""Tests the transformations applied to an optional mainline sdk on T.
@@ -484,7 +485,7 @@ class TestAndroidBpTransformations(unittest.TestCase):
module = MAINLINE_MODULES_BY_APEX["com.android.wifi"]
transformations = module.transformations(mm.Tiramisu, mm.Sdk)
- self.apply_transformations(src, transformations, expected)
+ self.apply_transformations(src, transformations, mm.Tiramisu, expected)
def test_art(self):
"""Tests the transformations applied to a the ART mainline module.
@@ -500,7 +501,7 @@ class TestAndroidBpTransformations(unittest.TestCase):
module = MAINLINE_MODULES_BY_APEX["com.android.art"]
transformations = module.transformations(mm.S, mm.Sdk)
- self.apply_transformations(src, transformations, expected)
+ self.apply_transformations(src, transformations, mm.S, expected)
def test_art_module_exports(self):
"""Tests the transformations applied to a the ART mainline module.
@@ -516,7 +517,7 @@ class TestAndroidBpTransformations(unittest.TestCase):
module = MAINLINE_MODULES_BY_APEX["com.android.art"]
transformations = module.transformations(mm.S, mm.HostExports)
- self.apply_transformations(src, transformations, expected)
+ self.apply_transformations(src, transformations, mm.S, expected)
def test_r_build(self):
"""Tests the transformations that are applied for the R build.
@@ -534,7 +535,43 @@ class TestAndroidBpTransformations(unittest.TestCase):
module = MAINLINE_MODULES_BY_APEX["com.android.ipsec"]
transformations = module.transformations(mm.R, mm.Sdk)
- self.apply_transformations(src, transformations, 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):
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 00000000..2b844ab6
--- /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