Skip to content

Commit

Permalink
Move merge from java_common_internal_for_builtins.bzl to `java_in…
Browse files Browse the repository at this point in the history
…fo.bzl`

Just a refactoring change that is a no-op. Split off from the change that implements `merge` in Starlark for easier review.

PiperOrigin-RevId: 546020116
Change-Id: I3dad53ceac43a7d241e2a772cfcf97d59cf73a08
  • Loading branch information
hvadehra authored and copybara-github committed Jul 6, 2023
1 parent 6a23ac4 commit c231b7d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 28 deletions.
13 changes: 11 additions & 2 deletions src/main/starlark/builtins_bzl/common/java/java_common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ load(
"JavaPluginInfo",
_java_info_add_constraints = "add_constraints",
_java_info_make_non_strict = "make_non_strict",
_java_info_merge = "merge",
_java_info_set_annotation_processing = "set_annotation_processing",
)
load(":common/java/message_bundle_info.bzl", "MessageBundleInfo")
load(":common/java/java_common_internal_for_builtins.bzl", "compile", "merge", "run_ijar")
load(":common/java/java_common_internal_for_builtins.bzl", "compile", "run_ijar")
load(":common/java/java_semantics.bzl", "semantics")
load(":common/paths.bzl", "paths")
load(":common/java/java_helper.bzl", "helper")
Expand Down Expand Up @@ -165,7 +166,15 @@ def _default_javac_opts(java_toolchain):
return _java_common_internal.default_javac_opts(java_toolchain = java_toolchain)

def _merge(providers):
return merge(providers)
"""Merges the given providers into a single JavaInfo.
Args:
providers: ([JavaInfo]) The list of providers to merge.
Returns:
(JavaInfo) The merged JavaInfo
"""
return _java_info_merge(providers)

def _make_non_strict(java_info):
"""Returns a new JavaInfo instance whose direct-jars part is the union of both the direct and indirect jars of the given Java provider.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,27 +176,6 @@ def run_ijar(
)
return output

def merge(
providers,
# private to @_builtins:
merge_java_outputs = True,
merge_source_jars = True):
"""Merges the given providers into a single JavaInfo.
Args:
providers: ([JavaInfo]) The list of providers to merge.
merge_java_outputs: (bool)
merge_source_jars: (bool)
Returns:
(JavaInfo) The merged JavaInfo
"""
return _java_common_internal.merge(
providers,
merge_java_outputs = merge_java_outputs,
merge_source_jars = merge_source_jars,
)

def target_kind(target, dereference_aliases = False):
"""Get the rule class string for a target
Expand Down
25 changes: 22 additions & 3 deletions src/main/starlark/builtins_bzl/common/java/java_info.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Definition of JavaInfo and JavaPluginInfo provider.

load(":common/cc/cc_common.bzl", "cc_common")
load(":common/cc/cc_info.bzl", "CcInfo")
load(":common/java/java_common_internal_for_builtins.bzl", _merge_private_for_builtins = "merge")

# TODO(hvd): remove this when:
# - we have a general provider-type checking API
Expand Down Expand Up @@ -88,6 +87,27 @@ _EMPTY_COMPILATION_INFO = _JavaCompilationInfo(
javac_options = [],
)

def merge(
providers,
# private to @_builtins:
merge_java_outputs = True,
merge_source_jars = True):
"""Merges the given providers into a single JavaInfo.
Args:
providers: ([JavaInfo]) The list of providers to merge.
merge_java_outputs: (bool)
merge_source_jars: (bool)
Returns:
(JavaInfo) The merged JavaInfo
"""
return _java_common_internal.merge(
providers,
merge_java_outputs = merge_java_outputs,
merge_source_jars = merge_source_jars,
)

def to_java_binary_info(java_info):
"""Get a copy of the given JavaInfo with minimal info returned by a java_binary
Expand Down Expand Up @@ -567,8 +587,7 @@ def _javaplugininfo_init(
(JavaPluginInfo)
"""

# we don't need the private API but java_common needs JavaPluginInfo which would be a cycle
java_infos = _merge_private_for_builtins(runtime_deps)
java_infos = merge(runtime_deps)
processor_data = data if type(data) == "depset" else depset(data)
plugins = _JavaPluginDataInfo(
processor_classes = depset([processor_class]) if processor_class else depset(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
load(":common/java/java_semantics.bzl", "semantics")
load(":common/proto/proto_common.bzl", "ProtoLangToolchainInfo", proto_common = "proto_common_do_not_use")
load(":common/proto/proto_info.bzl", "ProtoInfo")
load(":common/java/java_info.bzl", "JavaInfo")
load(":common/java/java_info.bzl", "JavaInfo", _merge_private_for_builtins = "merge")
load(
":common/java/java_common_internal_for_builtins.bzl",
_compile_private_for_builtins = "compile",
_merge_private_for_builtins = "merge",
)

# The provider is used to collect source and runtime jars in the `proto_library` dependency graph.
Expand Down

0 comments on commit c231b7d

Please sign in to comment.