Skip to content

Commit

Permalink
Expose gwt_module from java_library and prebuilt_jar
Browse files Browse the repository at this point in the history
Summary:
We have a couple of uses of `gwt_binary`. Those needs to get "GWT module" deps, which basically means a `.zip` of the source files and resources.

So, that's the plumbing that this adds.

Reviewed By: ianlevesque

Differential Revision: D51156123

fbshipit-source-id: 3f93649164cd71e6f0a24aa4d999ac361c7c567c
  • Loading branch information
Ian Childs authored and facebook-github-bot committed Nov 13, 2023
1 parent c2cabc0 commit bbca1ba
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
25 changes: 25 additions & 0 deletions prelude/java/java_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,30 @@ def build_java_library(
DefaultInfo(default_output = nullsafe_info.output),
]}

gwt_output = None
if (
(srcs or resources) and
not java_toolchain.is_bootstrap_toolchain and
not ctx.attrs._is_building_android_binary
):
gwt_output = ctx.actions.declare_output("gwt_module/{}.jar".format(ctx.label.name))
entries = []

if srcs or resources:
entries.append(_copy_resources(ctx.actions, "gwt_module", java_toolchain, ctx.label.package, srcs + resources, resources_root))
if outputs and outputs.annotation_processor_output:
entries.append(outputs.annotation_processor_output)

gwt_cmd_args = cmd_args(
java_toolchain.jar_builder,
"--entries-to-jar",
ctx.actions.write("gwt_entries.txt", entries),
"--output",
gwt_output.as_output(),
).hidden(entries)

ctx.actions.run(gwt_cmd_args, category = "gwt_module")

all_generated_sources = list(generated_sources)
if outputs and outputs.annotation_processor_output:
all_generated_sources.append(outputs.annotation_processor_output)
Expand All @@ -623,6 +647,7 @@ def build_java_library(
needs_desugar = source_level > 7 or target_level > 7,
generated_sources = all_generated_sources,
has_srcs = has_srcs,
gwt_module = gwt_output,
)

class_to_src_map, class_to_src_map_sub_targets = get_class_to_source_map_info(
Expand Down
13 changes: 10 additions & 3 deletions prelude/java/java_providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ JavaPackagingDep = record(
label = Label,
jar = [Artifact, None],
dex = [DexLibraryInfo, None],
gwt_module = [Artifact, None],
is_prebuilt_jar = bool,
proguard_config = [Artifact, None],

Expand Down Expand Up @@ -309,7 +310,8 @@ def create_java_packaging_dep(
is_prebuilt_jar: bool = False,
has_srcs: bool = True,
dex_weight_factor: int = 1,
proguard_config: [Artifact, None] = None) -> JavaPackagingDep:
proguard_config: [Artifact, None] = None,
gwt_module: [Artifact, None] = None) -> JavaPackagingDep:
dex_toolchain = getattr(ctx.attrs, "_dex_toolchain", None)
if library_jar != None and has_srcs and dex_toolchain != None and ctx.attrs._dex_toolchain[DexToolchainInfo].d8_command != None:
dex = get_dex_produced_from_java_library(
Expand All @@ -329,6 +331,7 @@ def create_java_packaging_dep(
label = ctx.label,
jar = library_jar,
dex = dex,
gwt_module = gwt_module,
is_prebuilt_jar = is_prebuilt_jar,
proguard_config = proguard_config or getattr(ctx.attrs, "proguard_config", None),
output_for_classpath_macro = output_for_classpath_macro or library_jar,
Expand Down Expand Up @@ -393,7 +396,8 @@ def _create_non_template_providers(
desugar_classpath: list[Artifact] = [],
is_prebuilt_jar: bool = False,
has_srcs: bool = True,
proguard_config: [Artifact, None] = None) -> (JavaLibraryInfo, JavaPackagingInfo, SharedLibraryInfo, ResourceInfo, LinkableGraph):
proguard_config: [Artifact, None] = None,
gwt_module: [Artifact, None] = None) -> (JavaLibraryInfo, JavaPackagingInfo, SharedLibraryInfo, ResourceInfo, LinkableGraph):
"""Creates java library providers of type `JavaLibraryInfo` and `JavaPackagingInfo`.
Args:
Expand All @@ -416,6 +420,7 @@ def _create_non_template_providers(
is_prebuilt_jar,
has_srcs,
proguard_config = proguard_config,
gwt_module = gwt_module,
)

java_packaging_info = get_java_packaging_info(
Expand Down Expand Up @@ -456,7 +461,8 @@ def create_java_library_providers(
has_srcs: bool = True,
generated_sources: list[Artifact] = [],
annotation_jars_dir: [Artifact, None] = None,
proguard_config: [Artifact, None] = None) -> (JavaLibraryInfo, JavaPackagingInfo, SharedLibraryInfo, ResourceInfo, LinkableGraph, TemplatePlaceholderInfo, JavaLibraryIntellijInfo):
proguard_config: [Artifact, None] = None,
gwt_module: [Artifact, None] = None) -> (JavaLibraryInfo, JavaPackagingInfo, SharedLibraryInfo, ResourceInfo, LinkableGraph, TemplatePlaceholderInfo, JavaLibraryIntellijInfo):
first_order_classpath_deps = filter(None, [x.get(JavaLibraryInfo) for x in declared_deps + exported_deps + runtime_deps])
first_order_classpath_libs = [dep.output_for_classpath_macro for dep in first_order_classpath_deps]

Expand All @@ -476,6 +482,7 @@ def create_java_library_providers(
is_prebuilt_jar = is_prebuilt_jar,
has_srcs = has_srcs,
proguard_config = proguard_config,
gwt_module = gwt_module,
)

first_order_libs = first_order_classpath_libs + [library_info.library_output.full_library] if library_info.library_output else first_order_classpath_libs
Expand Down
4 changes: 4 additions & 0 deletions prelude/java/prebuilt_jar.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def prebuilt_jar_impl(ctx: AnalysisContext) -> list[Provider]:
output = ctx.actions.declare_output("symlink/{}".format(binary_jar.short_path))
ctx.actions.symlink_file(output, binary_jar)

gwt_output = ctx.actions.declare_output("{}-gwt.jar".format(ctx.label.name))
ctx.actions.copy_file(gwt_output, ctx.attrs.source_jar if ctx.attrs.source_jar else ctx.attrs.binary_jar)

abi = None
if ctx.attrs.generate_abi:
prebuilt_jar_toolchain = ctx.attrs._prebuilt_jar_toolchain[PrebuiltJarToolchainInfo]
Expand All @@ -58,6 +61,7 @@ def prebuilt_jar_impl(ctx: AnalysisContext) -> list[Provider]:
exported_deps = ctx.attrs.deps,
needs_desugar = True,
is_prebuilt_jar = True,
gwt_module = gwt_output,
)

# TODO(T107163344) this shouldn't be in prebuilt_jar itself, use overlays to remove it.
Expand Down

0 comments on commit bbca1ba

Please sign in to comment.