Skip to content

Commit

Permalink
[6.4.0] Cherry pick Add a Starlark flag that allows disabling proguar…
Browse files Browse the repository at this point in the history
…d. This will be useful for testing later. (#19179)

* Format android_sdk_repository_template.bzl.

RELNOTES: None
PiperOrigin-RevId: 527336290
Change-Id: I4212e7c6f8ffd912bcf89b47f5a0ec182866badb

* Add a Starlark flag that allows disabling proguard. This will be useful for testing later.

PiperOrigin-RevId: 527367618
Change-Id: Ia2054aa4b85b52e054791ddb0cac3b72452e51ca
  • Loading branch information
ahumesky authored Aug 7, 2023
1 parent 1b2732f commit e643c57
Showing 1 changed file with 42 additions and 21 deletions.
63 changes: 42 additions & 21 deletions tools/android/android_sdk_repository_template.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
load("@rules_java//java:defs.bzl", "java_binary", "java_import")
load("@local_config_platform//:constraints.bzl", "HOST_CONSTRAINTS")

def _bool_flag_impl(_unused_ctx):
pass

_bool_flag = rule(
implementation = _bool_flag_impl,
build_setting = config.bool(flag = True),
)

def create_config_setting_rule():
"""Create config_setting rule for windows.
Expand All @@ -38,6 +46,16 @@ def create_config_setting_rule():
values = {"define": "android_standalone_dexing_tool=dx_compat_dx"},
)

_bool_flag(
name = "allow_proguard",
build_setting_default = True,
)

native.config_setting(
name = "disallow_proguard",
flag_values = {":allow_proguard": "false"},
)

def create_android_sdk_rules(
name,
build_tools_version,
Expand Down Expand Up @@ -76,8 +94,8 @@ def create_android_sdk_rules(
"platform-tools/adb",
] + native.glob(
["extras", "build-tools/%s/aapt2" % build_tools_directory],
exclude_directories = 0,
allow_empty = True,
exclude_directories = 0,
)

# This filegroup is used to pass the minimal contents of the SDK to the
Expand Down Expand Up @@ -125,8 +143,6 @@ def create_android_sdk_rules(

native.android_sdk(
name = "sdk-%d" % api_level,
build_tools_version = build_tools_version,
proguard = "@bazel_tools//tools/jdk:proguard",
aapt = select({
":windows": "build-tools/%s/aapt.exe" % build_tools_directory,
"//conditions:default": ":aapt_binary",
Expand All @@ -135,41 +151,46 @@ def create_android_sdk_rules(
":windows": "build-tools/%s/aapt2.exe" % build_tools_directory,
"//conditions:default": ":aapt2_binary",
}),
dx = select({
"d8_standalone_dexer": ":d8_compat_dx",
"dx_standalone_dexer": ":dx_binary",
"//conditions:default": ":d8_compat_dx",
}),
legacy_main_dex_list_generator = ":generate_main_dex_list",
adb = select({
":windows": "platform-tools/adb.exe",
"//conditions:default": "platform-tools/adb",
}),
framework_aidl = "platforms/android-%d/framework.aidl" % api_level,
aidl = select({
":windows": "build-tools/%s/aidl.exe" % build_tools_directory,
"//conditions:default": ":aidl_binary",
}),
android_jar = "platforms/android-%d/android.jar" % api_level,
shrinked_android_jar = "platforms/android-%d/android.jar" % api_level,
main_dex_classes = "build-tools/%s/mainDexClasses.rules" % build_tools_directory,
apksigner = ":apksigner",
build_tools_version = build_tools_version,
dx = select({
"d8_standalone_dexer": ":d8_compat_dx",
"dx_standalone_dexer": ":dx_binary",
"//conditions:default": ":d8_compat_dx",
}),
framework_aidl = "platforms/android-%d/framework.aidl" % api_level,
legacy_main_dex_list_generator = ":generate_main_dex_list",
main_dex_classes = "build-tools/%s/mainDexClasses.rules" % build_tools_directory,
proguard = select({
":disallow_proguard": ":fail",
"//conditions:default": "@bazel_tools//tools/jdk:proguard",
}),
shrinked_android_jar = "platforms/android-%d/android.jar" % api_level,
# See https://github.com/bazelbuild/bazel/issues/8757
tags = ["__ANDROID_RULES_MIGRATION__"],
zipalign = select({
":windows": "build-tools/%s/zipalign.exe" % build_tools_directory,
"//conditions:default": ":zipalign_binary",
}),
# See https://github.com/bazelbuild/bazel/issues/8757
tags = ["__ANDROID_RULES_MIGRATION__"],
)

native.toolchain(
name = "sdk-%d-toolchain" % api_level,
toolchain_type = "@bazel_tools//tools/android:sdk_toolchain_type",
exec_compatible_with = HOST_CONSTRAINTS,
target_compatible_with = [
"@platforms//os:android",
],
toolchain = ":sdk-%d" % api_level,
toolchain_type = "@bazel_tools//tools/android:sdk_toolchain_type",
)

create_dummy_sdk_toolchain()
Expand Down Expand Up @@ -201,8 +222,8 @@ def create_android_sdk_rules(
for tool in ["aapt", "aapt2", "aidl", "zipalign"]:
native.genrule(
name = tool + "_runner",
outs = [tool + "_runner.sh"],
srcs = [],
outs = [tool + "_runner.sh"],
cmd = "\n".join([
"cat > $@ << 'EOF'",
"#!/bin/bash",
Expand Down Expand Up @@ -246,16 +267,16 @@ def create_android_sdk_rules(

native.genrule(
name = "generate_fail_sh",
executable = 1,
outs = ["fail.sh"],
cmd = "echo -e '#!/bin/bash\\nexit 1' >> $@; chmod +x $@",
executable = 1,
)

native.genrule(
name = "generate_fail_cmd",
executable = 1,
outs = ["fail.cmd"],
cmd = "echo @exit /b 1 > $@",
executable = 1,
)

native.genrule(
Expand Down Expand Up @@ -313,7 +334,7 @@ def create_android_sdk_rules(
name = "d8_compat_dx",
main_class = "com.google.devtools.build.android.r8.CompatDx",
runtime_deps = [
"@bazel_tools//src/tools/android/java/com/google/devtools/build/android/r8:r8",
"@bazel_tools//src/tools/android/java/com/google/devtools/build/android/r8",
],
)
native.alias(
Expand All @@ -339,8 +360,8 @@ ARCHDIR_TO_ARCH_MAP = {
def create_dummy_sdk_toolchain():
native.toolchain(
name = "sdk-dummy-toolchain",
toolchain_type = "@bazel_tools//tools/android:sdk_toolchain_type",
toolchain = ":sdk-dummy",
toolchain_type = "@bazel_tools//tools/android:sdk_toolchain_type",
)

native.filegroup(name = "jar-filegroup", srcs = ["dummy.jar"])
Expand Down Expand Up @@ -368,8 +389,8 @@ def create_dummy_sdk_toolchain():
main_dex_list_creator = ":empty-binary",
proguard = ":empty-binary",
shrinked_android_jar = "dummy.jar",
zipalign = ":empty-binary",
tags = ["__ANDROID_RULES_MIGRATION__"],
zipalign = ":empty-binary",
)

def create_system_images_filegroups(system_image_dirs):
Expand Down

0 comments on commit e643c57

Please sign in to comment.