Skip to content

Commit 8e0310a

Browse files
kevinoconnor7copybara-github
authored andcommitted
Import jsinterop_annotations as a JAR only rather than the full java_library
PiperOrigin-RevId: 544347579
1 parent 4032fcc commit 8e0310a

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

java/jsinterop/annotations/BUILD

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#
44

55
load("@com_google_j2cl//build_defs:rules.bzl", "j2cl_import")
6+
load(":import_annotations_jar.bzl", "import_annotations_jar")
67
load("@bazel_common_javadoc//:javadoc.bzl", "javadoc_library")
78

89
package(
@@ -17,6 +18,17 @@ java_library(
1718
srcs = glob(["*.java"]),
1819
)
1920

21+
# Re-import only the output jar, dropping all transitive dependencies in the
22+
# process. This is important for JsInterop Annotations as these are used by
23+
# the J2CL-emulated JRE itself and thus cannot have any dependencies outside of
24+
# toolchain's bootclasspath.
25+
import_annotations_jar(
26+
name = "annotations_jar",
27+
jar = ":libannotations.jar",
28+
# No one outside of this package should _ever_ depend upon this target.
29+
visibility = ["//visibility:private"],
30+
)
31+
2032
javadoc_library(
2133
name = "annotations-javadoc",
2234
srcs = glob(["*.java"]),
@@ -28,5 +40,5 @@ javadoc_library(
2840

2941
j2cl_import(
3042
name = "annotations-j2cl",
31-
jar = ":annotations",
43+
jar = ":annotations_jar",
3244
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""import_annotations_jar build macro
2+
3+
This macro is intended for internal-use only to re-import the annotations JAR
4+
into a JavaInfo provider without keeping dependency information.
5+
"""
6+
7+
def _impl_import_annotations_jar(ctx):
8+
if ctx.file.jar.extension != "jar":
9+
fail("jar must be a file with extension .jar")
10+
return JavaInfo(output_jar = ctx.file.jar, compile_jar = ctx.file.jar)
11+
12+
import_annotations_jar = rule(
13+
implementation = _impl_import_annotations_jar,
14+
attrs = {
15+
"jar": attr.label(
16+
allow_single_file = True,
17+
),
18+
},
19+
fragments = ["java"],
20+
)

0 commit comments

Comments
 (0)