Skip to content

Commit

Permalink
Import jsinterop_annotations as a JAR only rather than the full java_…
Browse files Browse the repository at this point in the history
…library

PiperOrigin-RevId: 544347579
  • Loading branch information
kevinoconnor7 authored and copybara-github committed Jun 29, 2023
1 parent 4032fcc commit 8e0310a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
14 changes: 13 additions & 1 deletion java/jsinterop/annotations/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

load("@com_google_j2cl//build_defs:rules.bzl", "j2cl_import")
load(":import_annotations_jar.bzl", "import_annotations_jar")
load("@bazel_common_javadoc//:javadoc.bzl", "javadoc_library")

package(
Expand All @@ -17,6 +18,17 @@ java_library(
srcs = glob(["*.java"]),
)

# Re-import only the output jar, dropping all transitive dependencies in the
# process. This is important for JsInterop Annotations as these are used by
# the J2CL-emulated JRE itself and thus cannot have any dependencies outside of
# toolchain's bootclasspath.
import_annotations_jar(
name = "annotations_jar",
jar = ":libannotations.jar",
# No one outside of this package should _ever_ depend upon this target.
visibility = ["//visibility:private"],
)

javadoc_library(
name = "annotations-javadoc",
srcs = glob(["*.java"]),
Expand All @@ -28,5 +40,5 @@ javadoc_library(

j2cl_import(
name = "annotations-j2cl",
jar = ":annotations",
jar = ":annotations_jar",
)
20 changes: 20 additions & 0 deletions java/jsinterop/annotations/import_annotations_jar.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""import_annotations_jar build macro
This macro is intended for internal-use only to re-import the annotations JAR
into a JavaInfo provider without keeping dependency information.
"""

def _impl_import_annotations_jar(ctx):
if ctx.file.jar.extension != "jar":
fail("jar must be a file with extension .jar")
return JavaInfo(output_jar = ctx.file.jar, compile_jar = ctx.file.jar)

import_annotations_jar = rule(
implementation = _impl_import_annotations_jar,
attrs = {
"jar": attr.label(
allow_single_file = True,
),
},
fragments = ["java"],
)

0 comments on commit 8e0310a

Please sign in to comment.