Skip to content

Commit b2efded

Browse files
ted-xiecopybara-github
authored andcommitted
Automated rollback of commit f270005.
PiperOrigin-RevId: 723090006 Change-Id: Ida97e6ace3210ff07c5cf46e0a38ae1afe0c5a63
1 parent 46db4db commit b2efded

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

rules/android_binary/attrs.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ ATTRS = _attrs.replace(
213213
name = "optimizing_dexer",
214214
),
215215
),
216+
_desugared_lib_config = attr.label(
217+
allow_single_file = True,
218+
default = Label("//tools/android:full_desugar_jdk_libs_config_json"),
219+
),
216220
_desugared_java8_legacy_apis = attr.label(
217221
default = Label("//tools/android:desugared_java8_legacy_apis"),
218222
allow_single_file = True,

rules/android_binary/impl.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ def _process_deploy_jar(ctx, validation_ctx, stamp_ctx, packaged_resources_ctx,
487487
bootclasspath = java_toolchain[java_common.JavaToolchainInfo].bootclasspath.to_list(),
488488
min_sdk_version = _min_sdk_version.clamp(ctx.attr.min_sdk_version),
489489
desugar_exec = get_android_toolchain(ctx).desugar.files_to_run,
490+
desugared_lib_config = ctx.file._desugared_lib_config,
490491
toolchain_type = ANDROID_TOOLCHAIN_TYPE,
491492
)
492493
desugared_jars.append(desugared_jar)

rules/desugar.bzl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def _desugar(
2626
min_sdk_version = 0,
2727
library_desugaring = True,
2828
desugar_exec = None,
29+
desugared_lib_config = None,
2930
toolchain_type = None):
3031
"""Desugars a JAR.
3132
@@ -38,6 +39,8 @@ def _desugar(
3839
min_sdk_version: Integer. The minimum targeted sdk version.
3940
library_desugaring: Boolean. Whether to enable core library desugaring.
4041
desugar_exec: File. The executable desugar file.
42+
desugared_lib_config: File. The json file containing desugarer options.
43+
toolchain_type: Label or String. The toolchain to use for running the desugar action.
4144
"""
4245

4346
args = ctx.actions.args()
@@ -50,18 +53,24 @@ def _desugar(
5053
args.add_all(classpath, before_each = "--classpath_entry")
5154
args.add_all(bootclasspath, before_each = "--bootclasspath_entry")
5255

56+
input_file_deps = [input]
5357
if library_desugaring:
5458
if ctx.fragments.android.check_desugar_deps:
5559
args.add("--emit_dependency_metadata_as_needed")
5660

57-
if ctx.fragments.android.desugar_java8_libs and library_desugaring:
61+
if ctx.fragments.android.desugar_java8_libs:
5862
args.add("--desugar_supported_core_libs")
63+
args.add("--desugared_lib_config", desugared_lib_config)
64+
if desugared_lib_config:
65+
input_file_deps.append(desugared_lib_config)
66+
else:
67+
fail("Got NoneType for desugared_lib_config")
5968

6069
if min_sdk_version > 0:
6170
args.add("--min_sdk_version", str(min_sdk_version))
6271

6372
ctx.actions.run(
64-
inputs = depset([input] + bootclasspath, transitive = [classpath]),
73+
inputs = depset(input_file_deps + bootclasspath, transitive = [classpath]),
6574
outputs = [output],
6675
executable = desugar_exec,
6776
arguments = [args],

rules/dex_desugar_aspect.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ _ATTR_ASPECTS = [
3333
"_aspect_proto_toolchain_for_javalite", # To get from proto_library through proto_lang_toolchain rule to proto runtime library.
3434
"_build_stamp_deps", # for build stamp runtime class deps
3535
"_build_stamp_mergee_manifest_lib", # for empty build stamp Service class implementation
36+
"_desugared_lib_config", # For java8 desugaring config file
3637
"_toolchain", # For _java_lite_grpc_library
3738
"deps",
3839
"exports",
@@ -122,6 +123,7 @@ def _aspect_impl(target, ctx):
122123
classpath = compiletime_classpath,
123124
min_sdk_version = min_sdk_version,
124125
desugar_exec = ctx.executable._desugar_java8,
126+
desugared_lib_config = ctx.file._desugared_lib_config,
125127
)
126128
else:
127129
desugared_jar = None
@@ -253,6 +255,10 @@ dex_desugar_aspect = aspect(
253255
cfg = "exec",
254256
executable = True,
255257
),
258+
"_desugared_lib_config": attr.label(
259+
allow_single_file = True,
260+
default = Label("//tools/android:full_desugar_jdk_libs_config_json"),
261+
),
256262
"_dexbuilder": attr.label(
257263
default = Label("//tools/android:dexbuilder"),
258264
allow_files = True,

tools/android/BUILD

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ genrule(
8686
cmd = "unzip -q -c " +
8787
"$(location @rules_android_maven//:com_android_tools_desugar_jdk_libs_configuration_nio) " +
8888
"META-INF/desugar/d8/desugar.json > $@",
89+
visibility = ["//visibility:public"],
8990
)
9091

9192
genrule(
@@ -108,6 +109,7 @@ genrule(
108109
}),
109110
outs = ["desugar_jdk_libs.json"],
110111
cmd = "cp $< $@",
112+
visibility = ["//visibility:public"],
111113
)
112114

113115
genrule(
@@ -175,13 +177,22 @@ genrule(
175177
visibility = ["//visibility:public"],
176178
)
177179

180+
_MIN_SDK_VERSION = "19"
181+
178182
genrule(
179183
name = "d8_desugar_params",
180184
outs = ["d8_desugar_params.txt"],
181-
cmd = "echo -n --min_sdk_version 19 > $@",
185+
cmd = "echo -n --min_sdk_version " + _MIN_SDK_VERSION + " > $@",
182186
visibility = ["//visibility:private"],
183187
)
184188

189+
genrule(
190+
name = "desugar_min_sdk_version_txt",
191+
outs = ["desugar_min_sdk_version.txt"],
192+
cmd = "echo -n " + _MIN_SDK_VERSION + " > $@",
193+
visibility = ["//visibility:public"],
194+
)
195+
185196
sh_binary(
186197
name = "desugar_java8",
187198
srcs = [":d8_desugar.sh"],

0 commit comments

Comments
 (0)