From 306813d5da96a526fb518b7387c0c7dd65a4100c Mon Sep 17 00:00:00 2001 From: dawasser Date: Thu, 28 Mar 2024 14:22:13 -0700 Subject: [PATCH] Remove support for Dex postprocessing. PiperOrigin-RevId: 620056113 Change-Id: I311aeeeac55671874259dd86496f374d10d48f40 --- rules/android_binary_internal/impl.bzl | 30 ++----------- rules/dex.bzl | 60 -------------------------- 2 files changed, 3 insertions(+), 87 deletions(-) diff --git a/rules/android_binary_internal/impl.bzl b/rules/android_binary_internal/impl.bzl index 987c69ac5..b3a2ee969 100644 --- a/rules/android_binary_internal/impl.bzl +++ b/rules/android_binary_internal/impl.bzl @@ -308,14 +308,12 @@ def _process_dex(ctx, validation_ctx, packaged_resources_ctx, deploy_ctx, bp_ctx should_optimize_dex = optimizing_dexer and proguarded_jar and not acls.in_disable_optimizing_dexer(str(ctx.label)) if proguard_output_map: - enable_postprocess_dexing = _dex.enable_postprocess_dexing(ctx) - # Proguard map from preprocessing will be merged with Proguard map for desugared # library. - if (should_optimize_dex or enable_postprocess_dexing) and ctx.fragments.android.desugar_java8_libs: + if should_optimize_dex and ctx.fragments.android.desugar_java8_libs: postprocessing_output_map = _dex.get_dx_artifact(ctx, "_proguard_output_for_desugared_library.map") final_proguard_output_map = _dex.get_dx_artifact(ctx, "_proguard.map") - elif (should_optimize_dex or enable_postprocess_dexing): + elif should_optimize_dex: # No desugared library, Proguard map from postprocessing is the final Proguard map. postprocessing_output_map = _dex.get_dx_artifact(ctx, "_proguard.map") final_proguard_output_map = postprocessing_output_map @@ -380,25 +378,6 @@ def _process_dex(ctx, validation_ctx, packaged_resources_ctx, deploy_ctx, bp_ctx toolchain_type = ANDROID_TOOLCHAIN_TYPE, ) - # TODO(b/261110876): Remove dex postprocessing once Optimizing dexing is enabled by default - if _dex.enable_postprocess_dexing(ctx): - rexed_dex_zip = ctx.actions.declare_file(ctx.label.name + "/_rex/rexed_dexes.zip") - - # TODO(zhaoqxu): Populate final_rex_package_map to the Native rule if needed. - _final_rex_package_map = _dex.postprocess_dexing( - ctx, - rexed_dex_zip = rexed_dex_zip, - classes_dex_zip = classes_dex_zip, - proguard_map = proguard_output_map, - postprocessing_output_map = postprocessing_output_map, - main_dex_list = main_dex_list, - multidex = ctx.attr.multidex, - rexopts = getattr(ctx.attr, "rexopts", []), - rex_wrapper = get_android_toolchain(ctx).rex_wrapper.files_to_run, - toolchain_type = ANDROID_TOOLCHAIN_TYPE, - ) - classes_dex_zip = rexed_dex_zip - if ctx.fragments.android.desugar_java8_libs and classes_dex_zip.extension == "zip": final_classes_dex_zip = _dex.get_dx_artifact(ctx, "final_classes_dex.zip") @@ -800,19 +779,16 @@ def _process_optimize(ctx, validation_ctx, deploy_ctx, packaged_resources_ctx, b ) desugar_java8_libs_generates_map = ctx.fragments.android.desugar_java8 optimizing_dexing = bool(ctx.attr._optimizing_dexer) and not acls.in_disable_optimizing_dexer(str(ctx.label)) - enable_postprocess_dexing = _dex.enable_postprocess_dexing(ctx) if generate_proguard_map: # Determine the output of the Proguard map from shrinking the app. This depends on the # additional steps which can process the map before the final Proguard map artifact is # generated. - if not has_proguard_specs and not enable_postprocess_dexing: + if not has_proguard_specs: # When no shrinking happens a generating rule for the output map artifact is still needed. proguard_output_map = proguard.get_proguard_output_map(ctx) elif optimizing_dexing: proguard_output_map = proguard.get_proguard_temp_artifact(ctx, "pre_dexing.map") - elif enable_postprocess_dexing: - proguard_output_map = proguard.get_proguard_temp_artifact(ctx, "proguard_output_for_rex.map") elif desugar_java8_libs_generates_map: # Proguard map from shrinking will be merged with desugared library proguard map. proguard_output_map = _dex.get_dx_artifact(ctx, "_proguard_output_for_desugared_library.map") diff --git a/rules/dex.bzl b/rules/dex.bzl index 7e8294fe7..b7cfa31f0 100644 --- a/rules/dex.bzl +++ b/rules/dex.bzl @@ -238,64 +238,6 @@ def _process_monolithic_dexing( progress_message = "Trimming %s." % classes_dex_intermediate.short_path, ) -def _postprocess_dexing( - ctx, - rexed_dex_zip = None, - classes_dex_zip = None, - proguard_map = None, - postprocessing_output_map = None, - main_dex_list = None, - multidex = "native", - rexopts = [], - rex_wrapper = None, - toolchain_type = None): - outputs = [rexed_dex_zip] - inputs = [classes_dex_zip] - args = ctx.actions.args() - args.add("--dex_input", classes_dex_zip) - args.add("--dex_output", rexed_dex_zip) - - final_rex_package_map = None - if proguard_map: - final_rex_package_map = ctx.actions.declare_file(ctx.label.name + "_rex/rex_output_package.map") - args.add("--proguard_input_map", proguard_map) - args.add("--proguard_output_map", postprocessing_output_map) - args.add("--rex_output_package_map", final_rex_package_map) - outputs.append(postprocessing_output_map) - outputs.append(final_rex_package_map) - inputs.append(proguard_map) - - # the Rex flag --keep-main-dex is used to support builds with API level below 21 that do not - # support native multi-dex. This flag indicates to Rex to use the main_dex_list file which can - # be provided by the user via the main_dex_list attribute or created automatically when multidex - # mode is set to legacy. - if main_dex_list or multidex == "legacy": - args.add("--keep-main-dex") - if main_dex_list: - inputs.append(main_dex_list) - args.add("--main_dex_list", main_dex_list) - - if rexopts: - args.add_all(rexopts) - - ctx.actions.run( - outputs = outputs, - executable = rex_wrapper, - inputs = inputs, - arguments = [args], - mnemonic = "Rex", - progress_message = "Rexing dex files.", - toolchain = toolchain_type, - ) - - return final_rex_package_map - -def _enable_postprocess_dexing(ctx): - return (not getattr(ctx.attr, "_optimizing_dexer", None) and not acls.in_disable_optimizing_dexer(str(ctx.label))) and ( - ctx.fragments.android.use_rex_to_compress_dex_files or - getattr(ctx.attr, "rewrite_dexes_with_rex", False) - ) - def _shard_proguarded_jar_and_dex( ctx, java_resource_jar, @@ -854,7 +796,6 @@ dex = struct( append_java8_legacy_dex = _append_java8_legacy_dex, dex = _dex, dex_merge = _dex_merge, - enable_postprocess_dexing = _enable_postprocess_dexing, generate_main_dex_list = _generate_main_dex_list, get_dx_artifact = _get_dx_artifact, get_effective_incremental_dexing = _get_effective_incremental_dexing, @@ -864,6 +805,5 @@ dex = struct( normalize_dexopts = _normalize_dexopts, process_monolithic_dexing = _process_monolithic_dexing, process_incremental_dexing = _process_incremental_dexing, - postprocess_dexing = _postprocess_dexing, transform_dex_list_through_proguard_map = _transform_dex_list_through_proguard_map, )