diff options
author | Paul Duffin <paulduffin@google.com> | 2022-03-16 13:06:42 +0000 |
---|---|---|
committer | Paul Duffin <paulduffin@google.com> | 2022-03-23 15:45:15 +0000 |
commit | ffa89fd0a094d58bc548aa024e54e3fd35ae69c2 (patch) | |
tree | eac27349be03fe8e5607e62ed621bf20fdf8b431 /build/mainline_modules_sdks_test.py | |
parent | 726f9ab1bfff7e727dd2abd7fa6fc99cf7339e31 (diff) | |
download | common-ffa89fd0a094d58bc548aa024e54e3fd35ae69c2.tar.gz |
Generate sdk snapshots for the R build
This change replicates the behavior of the generate_ml_bundle.sh that
creates an Android.bp file along with the necessary file structure for
an R build.
It adds the information needed to a ForRBuild object which is set on
those MainlineModules that need to provide SDKs for R. That includes
a list of SdkLibrary objects each of which has a name and a flag that
indicates whether it is a shared library.
The R BuildRelease creator function builds the sdk snapshots as normal
and then extracts information from those snapshot files to construct
snapshots suitable for an R build. It then passes the directory
containing those new snapshot files to populate_dist() which will then
copy them into the correct location in the dist directory.
For each MainlineModule that provides an SDK for R the following is
created in the out/soong/mainline-sdks/for-R-build directory:
* A sub-directory using the apex name containing:
* An Android.bp file with definitions for each SdkLibrary.
* A file structure containing API txt file, removed API txt file,
a srcjar containing the stub sources and a stubs jar.
* A zip file containing the contents of the previous directory whose
name is <sdk-name>-current.zip, to match the files that are
generated by Soong when building sdk snapshots.
As R does not support the Soong config boilerplate code that
transformation is disabled for R.
Test: atest --host mainline_modules_sdks_test
packages/modules/common/build/mainline_modules_sdks.sh
pyformat -s 4 --force_quote_type double -i build/mainline_modules_sdks*.py
/usr/bin/pylint --rcfile $ANDROID_BUILD_TOP/tools/repohooks/tools/pylintrc build/mainline_modules_sdks*.py
Change-Id: I70001782496a3e9805bf56181c0e08419e31e191
Diffstat (limited to 'build/mainline_modules_sdks_test.py')
-rw-r--r-- | build/mainline_modules_sdks_test.py | 103 |
1 files changed, 84 insertions, 19 deletions
diff --git a/build/mainline_modules_sdks_test.py b/build/mainline_modules_sdks_test.py index 38a6e9e0..8d452bdd 100644 --- a/build/mainline_modules_sdks_test.py +++ b/build/mainline_modules_sdks_test.py @@ -41,12 +41,16 @@ class FakeSnapshotBuilder(mm.SnapshotBuilder): z.writestr(f"sdk_library/public/{name}-stubs.jar", "") z.writestr(f"sdk_library/public/{name}.txt", "") - def create_snapshot_file(self, out_dir, name, version): + def create_snapshot_file(self, out_dir, name, version, for_r_build): zip_file = Path(mm.sdk_snapshot_zip_file(out_dir, name, version)) with zipfile.ZipFile(zip_file, "w") as z: z.writestr("Android.bp", "") if name.endswith("-sdk"): - self.create_sdk_library_files(z, re.sub(r"-.*$", "", name)) + if for_r_build: + for library in for_r_build.sdk_libraries: + self.create_sdk_library_files(z, library.name) + else: + self.create_sdk_library_files(z, re.sub(r"-.*$", "", name)) def build_snapshots(self, build_release, sdk_versions, modules): # Create input file structure. @@ -56,7 +60,8 @@ class FakeSnapshotBuilder(mm.SnapshotBuilder): for module in modules: for sdk in module.sdks: for sdk_version in sdk_versions: - self.create_snapshot_file(sdks_out_dir, sdk, sdk_version) + self.create_snapshot_file(sdks_out_dir, sdk, sdk_version, + module.for_r_build) return sdks_out_dir @@ -80,6 +85,7 @@ class TestProduceDist(unittest.TestCase): subprocess_runner = mm.SubprocessRunner() snapshot_builder = FakeSnapshotBuilder( + tool_path="path/to/mainline_modules_sdks.sh", subprocess_runner=subprocess_runner, out_dir=tmp_out_dir, ) @@ -100,11 +106,6 @@ class TestProduceDist(unittest.TestCase): producer.produce_dist(modules, build_releases) - files = [] - for abs_dir, _, filenames in os.walk(tmp_dist_dir): - rel_dir = os.path.relpath(abs_dir, tmp_dist_dir) - for f in filenames: - files.append(os.path.join(rel_dir, f)) # pylint: disable=line-too-long self.assertEqual( [ @@ -115,6 +116,8 @@ class TestProduceDist(unittest.TestCase): "mainline-sdks/current/com.android.ipsec/sdk/ipsec-module-sdk-current.zip", "mainline-sdks/current/com.google.android.wifi/sdk/wifi-module-sdk-current.zip", # Build specific snapshots. + "mainline-sdks/for-R-build/current/com.android.ipsec/sdk/ipsec-module-sdk-current.zip", + "mainline-sdks/for-R-build/current/com.google.android.wifi/sdk/wifi-module-sdk-current.zip", "mainline-sdks/for-S-build/current/com.android.art/host-exports/art-module-host-exports-current.zip", "mainline-sdks/for-S-build/current/com.android.art/sdk/art-module-sdk-current.zip", "mainline-sdks/for-S-build/current/com.android.art/test-exports/art-module-test-exports-current.zip", @@ -130,16 +133,60 @@ class TestProduceDist(unittest.TestCase): "stubs/com.android.art/sdk_library/public/art-stubs.jar", "stubs/com.android.art/sdk_library/public/art.srcjar", "stubs/com.android.art/sdk_library/public/art.txt", - "stubs/com.android.ipsec/sdk_library/public/ipsec-removed.txt", - "stubs/com.android.ipsec/sdk_library/public/ipsec-stubs.jar", - "stubs/com.android.ipsec/sdk_library/public/ipsec.srcjar", - "stubs/com.android.ipsec/sdk_library/public/ipsec.txt", - "stubs/com.google.android.wifi/sdk_library/public/wifi-removed.txt", - "stubs/com.google.android.wifi/sdk_library/public/wifi-stubs.jar", - "stubs/com.google.android.wifi/sdk_library/public/wifi.srcjar", - "stubs/com.google.android.wifi/sdk_library/public/wifi.txt", + "stubs/com.android.ipsec/sdk_library/public/android.net.ipsec.ike-removed.txt", + "stubs/com.android.ipsec/sdk_library/public/android.net.ipsec.ike-stubs.jar", + "stubs/com.android.ipsec/sdk_library/public/android.net.ipsec.ike.srcjar", + "stubs/com.android.ipsec/sdk_library/public/android.net.ipsec.ike.txt", + "stubs/com.google.android.wifi/sdk_library/public/framework-wifi-removed.txt", + "stubs/com.google.android.wifi/sdk_library/public/framework-wifi-stubs.jar", + "stubs/com.google.android.wifi/sdk_library/public/framework-wifi.srcjar", + "stubs/com.google.android.wifi/sdk_library/public/framework-wifi.txt", ], - sorted(files)) + sorted(self.list_files_in_dir(tmp_dist_dir))) + + r_snaphot_dir = os.path.join( + tmp_out_dir, "soong/mainline-sdks/test/for-R-build") + aosp_ipsec_r_bp_file = "com.android.ipsec/Android.bp" + google_wifi_android_bp = "com.google.android.wifi/Android.bp" + self.assertEqual([ + aosp_ipsec_r_bp_file, + "com.android.ipsec/sdk_library/public/android.net.ipsec.ike-removed.txt", + "com.android.ipsec/sdk_library/public/android.net.ipsec.ike-stubs.jar", + "com.android.ipsec/sdk_library/public/android.net.ipsec.ike.srcjar", + "com.android.ipsec/sdk_library/public/android.net.ipsec.ike.txt", + google_wifi_android_bp, + "com.google.android.wifi/sdk_library/public/framework-wifi-removed.txt", + "com.google.android.wifi/sdk_library/public/framework-wifi-stubs.jar", + "com.google.android.wifi/sdk_library/public/framework-wifi.srcjar", + "com.google.android.wifi/sdk_library/public/framework-wifi.txt", + "ipsec-module-sdk-current.zip", + "wifi-module-sdk-current.zip", + ], sorted(self.list_files_in_dir(r_snaphot_dir))) + + def read_r_snapshot_contents(path): + abs_path = os.path.join(r_snaphot_dir, path) + with open(abs_path, "r", encoding="utf8") as file: + return file.read() + + # Check the contents of the AOSP ipsec module + ipsec_contents = read_r_snapshot_contents(aosp_ipsec_r_bp_file) + expected = read_test_data("ipsec_for_r_Android.bp") + self.assertEqual(expected, ipsec_contents) + + # Check the contents of the Google ipsec module + wifi_contents = read_r_snapshot_contents(google_wifi_android_bp) + expected = read_test_data("google_wifi_for_r_Android.bp") + self.assertEqual(expected, wifi_contents) + + def list_files_in_dir(self, tmp_dist_dir): + files = [] + for abs_dir, _, filenames in os.walk(tmp_dist_dir): + rel_dir = os.path.relpath(abs_dir, tmp_dist_dir) + if rel_dir == ".": + rel_dir = "" + for f in filenames: + files.append(os.path.join(rel_dir, f)) + return files def path_to_test_data(relative_path): @@ -201,7 +248,7 @@ class TestSoongConfigBoilerplateInserter(unittest.TestCase): expected = read_test_data("ipsec_Android.bp.expected") module = MAINLINE_MODULES_BY_APEX["com.android.ipsec"] - transformations = module.transformations() + transformations = module.transformations(mm.S) self.apply_transformations(src, transformations, expected) @@ -217,7 +264,25 @@ class TestSoongConfigBoilerplateInserter(unittest.TestCase): expected = read_test_data("art_Android.bp.expected") module = MAINLINE_MODULES_BY_APEX["com.android.art"] - transformations = module.transformations() + transformations = module.transformations(mm.S) + + self.apply_transformations(src, transformations, expected) + + def test_r_build(self): + """Tests the transformations that are applied for the R build. + + This uses ipsec as an example of a common mainline module. That would + usually apply the mm.SoongConfigBoilerplateInserter transformation but + because this is being run for build R that transformation should not be + applied. + """ + src = read_test_data("ipsec_for_r_Android.bp") + + # There should be no changes made. + expected = src + + module = MAINLINE_MODULES_BY_APEX["com.android.ipsec"] + transformations = module.transformations(mm.R) self.apply_transformations(src, transformations, expected) |