Skip to content

Commit 57d28b9

Browse files
committed
Check R8 usage before grabbing proguard outputs from ctx.outputs
Fixes #343 stacked-branch: fix-proguard-outputs
1 parent 4c56502 commit 57d28b9

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,41 @@ load("//rules:rules.bzl", "android_binary", "android_library")
1616
proguard_specs = specs,
1717
resource_files = glob(["res/**"]),
1818
shrink_resources = shrink,
19+
proguard_generate_mapping = genmap,
1920
visibility = ["//test/rules/android_binary/r8_integration:__pkg__"],
2021
deps = [
2122
":basic_lib",
2223
":lib_with_specs",
2324
],
2425
)
25-
for name, specs, shrink in [
26+
for name, specs, shrink, genmap in [
2627
(
2728
"basic_app_R8_shrink",
2829
["proguard.cfg"],
2930
True,
31+
False,
3032
),
3133
(
3234
"basic_app_R8_no_shrink",
3335
["proguard.cfg"],
3436
False,
37+
False,
38+
),
39+
(
40+
"basic_app_no_R8",
41+
[],
42+
False,
43+
False,
44+
),
45+
(
46+
"basic_app_select_R8_genmap",
47+
select({
48+
":is_c_opt": ["proguard.cfg"],
49+
"//conditions:default": [],
50+
}),
51+
True,
52+
True,
3553
),
36-
("basic_app_no_R8", [], False),
3754
]
3855
]
3956

@@ -58,3 +75,10 @@ android_library(
5875
manifest = "AndroidManifest_lib.xml",
5976
proguard_specs = ["lib2_proguard.cfg"],
6077
)
78+
79+
config_setting(
80+
name = "is_c_opt",
81+
values = {
82+
"compilation_mode": "opt",
83+
},
84+
)

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)