Skip to content

Commit 8923695

Browse files
pswaminathancopybara-github
authored andcommitted
Merge #344 by pswaminathan: Check R8 usage before grabbing proguard outputs from ctx.outputs
Fixes #343 Closes #344 COPYBARA_INTEGRATE_REVIEW=#344 from pswaminathan:p/stacked/fix-proguard-outputs cdbd9ff PiperOrigin-RevId: 794620428 Change-Id: I5c06fb7fb8bb1d5c865c2c1e09fd3dbb8f207ed4
1 parent 61400d3 commit 8923695

4 files changed

Lines changed: 36 additions & 11 deletions

File tree

rules/android_binary/impl.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ def _process_optimize(ctx, validation_ctx, deploy_ctx, packaged_resources_ctx, b
799799
# Proguard map from shrinking is the final output.
800800
proguard_output_map = ctx.actions.declare_file(ctx.label.name + "_proguard.map")
801801

802-
if ctx.attr._generate_proguard_outputs:
802+
if not acls.use_r8(str(ctx.label)) and ctx.attr._generate_proguard_outputs:
803803
proguard_output_jar = ctx.outputs.proguard_jar
804804
proguard_output_config = ctx.outputs.proguard_config
805805
else:

test/rules/android_binary/r8_integration/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ py_test(
1010
"//test/rules/android_binary/r8_integration/java/com/basicapp:basic_app_R8_no_shrink",
1111
"//test/rules/android_binary/r8_integration/java/com/basicapp:basic_app_R8_shrink",
1212
"//test/rules/android_binary/r8_integration/java/com/basicapp:basic_app_no_R8",
13+
"//test/rules/android_binary/r8_integration/java/com/basicapp:basic_app_select_R8_genmap",
1314
"@androidsdk//:dexdump",
1415
],
1516
)

test/rules/android_binary/r8_integration/java/com/basicapp/BUILD

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,8 @@ load("//rules:rules.bzl", "android_binary", "android_library")
44
android_binary(
55
name = name,
66
srcs = ["BasicActivity.java"],
7-
# Work around --java_runtime_version=17 and --java_language_version=11
8-
# set in the presubmit tests.
9-
javacopts = [
10-
"-target",
11-
"8",
12-
"-source",
13-
"8",
14-
],
157
manifest = "AndroidManifest.xml",
8+
proguard_generate_mapping = generate_pg_map,
169
proguard_specs = specs,
1710
resource_files = glob(["res/**"]),
1811
shrink_resources = shrink,
@@ -22,18 +15,34 @@ load("//rules:rules.bzl", "android_binary", "android_library")
2215
":lib_with_specs",
2316
],
2417
)
25-
for name, specs, shrink in [
18+
for name, specs, shrink, generate_pg_map in [
2619
(
2720
"basic_app_R8_shrink",
2821
["proguard.cfg"],
2922
True,
23+
False,
3024
),
3125
(
3226
"basic_app_R8_no_shrink",
3327
["proguard.cfg"],
3428
False,
29+
False,
30+
),
31+
(
32+
"basic_app_no_R8",
33+
[],
34+
False,
35+
False,
36+
),
37+
(
38+
"basic_app_select_R8_generate_pg_map",
39+
select({
40+
":is_c_opt": ["proguard.cfg"],
41+
"//conditions:default": [],
42+
}),
43+
True,
44+
True,
3545
),
36-
("basic_app_no_R8", [], False),
3746
]
3847
]
3948

@@ -58,3 +67,10 @@ android_library(
5867
manifest = "AndroidManifest_lib.xml",
5968
proguard_specs = ["lib2_proguard.cfg"],
6069
)
70+
71+
config_setting(
72+
name = "is_c_opt",
73+
values = {
74+
"compilation_mode": "opt",
75+
},
76+
)

test/rules/android_binary/r8_integration/r8_integration_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ def test_r8_integration(self):
8181
expect_unused_activity_class=False,
8282
)
8383

84+
# No R8 when run in default test mode (non-opt),
85+
# so unused resources and unused classes should be in the app
86+
self._r8_integration_check(
87+
"basic_app_select_R8_genmap.apk",
88+
expect_unused_activity_resource=True,
89+
expect_unused_activity_class=True,
90+
)
91+
8492

8593
if __name__ == "__main__":
8694
dexdump = sys.argv.pop()

0 commit comments

Comments
 (0)