Skip to content

Commit

Permalink
Remove support for Dex postprocessing.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 620056113
Change-Id: I311aeeeac55671874259dd86496f374d10d48f40
  • Loading branch information
dawasser authored and copybara-github committed Mar 28, 2024
1 parent f0d4c4b commit 306813d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 87 deletions.
30 changes: 3 additions & 27 deletions rules/android_binary_internal/impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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")
Expand Down
60 changes: 0 additions & 60 deletions rules/dex.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
)

0 comments on commit 306813d

Please sign in to comment.