diff options
author | Vinh Tran <vinhdaitran@google.com> | 2023-03-08 14:25:26 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2023-03-08 14:25:26 +0000 |
commit | 6489e4770254281b13f23d4802414ebe653be2ff (patch) | |
tree | 603413daecbed6c8f4295d7132166f185ffbc5d5 | |
parent | ee1d333420402c9d600dbd56600cde8d04310bb9 (diff) | |
parent | 54ea5cfcfb882a0dc16ec27ae80727c9f4a6f7f9 (diff) | |
download | bazel-6489e4770254281b13f23d4802414ebe653be2ff.tar.gz |
Merge "Make apex compression dependent on CompressedApex and Unbundled_apps product vars"
-rw-r--r-- | rules/apex/BUILD | 7 | ||||
-rw-r--r-- | rules/apex/apex.bzl | 17 | ||||
-rw-r--r-- | rules/apex/apex_test.bzl | 71 |
3 files changed, 93 insertions, 2 deletions
diff --git a/rules/apex/BUILD b/rules/apex/BUILD index 82899dff..09ccf4c8 100644 --- a/rules/apex/BUILD +++ b/rules/apex/BUILD @@ -4,6 +4,7 @@ load("//build/bazel/rules/apex:toolchain.bzl", "apex_toolchain") load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "bool_setting", "string_list_setting", "string_setting") load("@soong_injection//product_config:product_variables.bzl", "product_vars") load("//build/bazel/rules/common:api.bzl", api_levels = "api_levels_with_previews") +load(":apex.bzl", "compression_enabled") load(":apex_test.bzl", "apex_test_suite") load(":apex_aab_test.bzl", "apex_aab_test_suite") load(":apex_key_test.bzl", "apex_key_test_suite") @@ -142,6 +143,12 @@ bool_setting( visibility = ["//visibility:public"], ) +bool_setting( + name = "compression_enabled", + build_setting_default = compression_enabled(), + visibility = ["//visibility:public"], +) + toolchain_type(name = "apex_toolchain_type") apex_toolchain( diff --git a/rules/apex/apex.bzl b/rules/apex/apex.bzl index 3ebdb7db..5c1f6614 100644 --- a/rules/apex/apex.bzl +++ b/rules/apex/apex.bzl @@ -495,6 +495,14 @@ def _run_signapk(ctx, unsigned_file, signed_file, private_key, public_key, mnemo return signed_file +# https://cs.android.com/android/platform/superproject/+/master:build/soong/android/config.go;drc=5ca657189aac546af0aafaba11bbc9c5d889eab3;l=1501 +# In Soong, we don't check whether the current apex is part of Unbundled_apps. +# Hence, we might simplify the logic by just checking product_vars["Unbundled_build"] +# TODO(b/271474456): Eventually we might default to unbundled mode in bazel-only mode +# so that we don't need to check Unbundled_apps. +def compression_enabled(): + return product_vars.get("CompressedApex", False) and len(product_vars.get("Unbundled_apps", [])) == 0 + # Compress a file with apex_compression_tool. def _run_apex_compression_tool(ctx, apex_toolchain, input_file, output_file_name): avbtool_files = apex_toolchain.avbtool[DefaultInfo].files_to_run @@ -635,7 +643,7 @@ def _apex_rule_impl(ctx): _run_signapk(ctx, unsigned_apex, signed_apex, private_key, public_key, "BazelApexSigning") - if ctx.attr.compressible: + if ctx.attr.compressible and ctx.attr._compression_enabled[BuildSettingInfo].value: compressed_apex_output_file = _run_apex_compression_tool(ctx, apex_toolchain, signed_apex, ctx.attr.name + ".capex.unsigned") signed_capex = ctx.outputs.capex_output _run_signapk(ctx, compressed_apex_output_file, signed_capex, private_key, public_key, "BazelCompressedApexSigning") @@ -819,6 +827,10 @@ When not set, defaults to 10000 (or "current").""", default = "//build/bazel/rules/apex:device_secondary_arch", doc = "If specified, also include the libraries from the secondary arch.", ), + "_compression_enabled": attr.label( + default = "//build/bazel/rules/apex:compression_enabled", + doc = "If specified along with compressible attribute, run compression tool.", + ), }, # The apex toolchain is not mandatory so that we don't get toolchain resolution errors even # when the apex is not compatible with the current target (via target_compatible_with). @@ -863,7 +875,8 @@ def apex( apex_output = name + ".apex" capex_output = None - if compressible: + + if compressible and compression_enabled(): capex_output = name + ".capex" if certificate and certificate_name: diff --git a/rules/apex/apex_test.bzl b/rules/apex/apex_test.bzl index 1c8627f2..db4eaf40 100644 --- a/rules/apex/apex_test.bzl +++ b/rules/apex/apex_test.bzl @@ -2363,6 +2363,75 @@ def _test_apex_in_bundled_build(): return test_name +def _apex_compression_test(ctx): + env = analysistest.begin(ctx) + + target = analysistest.target_under_test(env) + asserts.true( + env, + target[ApexInfo].signed_compressed_output != None, + "ApexInfo.signed_compressed_output should exist from compressible apex", + ) + + return analysistest.end(env) + +apex_compression_test = analysistest.make( + _apex_compression_test, + config_settings = { + "@//build/bazel/rules/apex:compression_enabled": True, + }, +) + +def _test_apex_compression(): + name = "apex_compression" + test_name = name + "_test" + + test_apex( + name = name, + compressible = True, + ) + + apex_compression_test( + name = test_name, + target_under_test = name, + ) + + return test_name + +def _apex_no_compression_test(ctx): + env = analysistest.begin(ctx) + + target = analysistest.target_under_test(env) + asserts.true( + env, + target[ApexInfo].signed_compressed_output == None, + "ApexInfo.signed_compressed_output should not exist when compression_enabled is not specified", + ) + + return analysistest.end(env) + +apex_no_compression_test = analysistest.make( + _apex_no_compression_test, + config_settings = { + "@//build/bazel/rules/apex:compression_enabled": False, + }, +) + +def _test_apex_no_compression(): + name = "apex_no_compression" + test_name = name + "_test" + + test_apex( + name = name, + ) + + apex_no_compression_test( + name = test_name, + target_under_test = name, + ) + + return test_name + def apex_test_suite(name): native.test_suite( name = name, @@ -2412,5 +2481,7 @@ def apex_test_suite(name): _test_directly_included_stubs_lib_with_indirectly_static_variant(), _test_apex_in_unbundled_build(), _test_apex_in_bundled_build(), + _test_apex_compression(), + _test_apex_no_compression(), ] + _test_apex_transition(), ) |