From c231b7d370a7cce4a3461eb1c50ca834c07e3edf Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 6 Jul 2023 10:02:20 -0700 Subject: [PATCH] Move `merge` from `java_common_internal_for_builtins.bzl` to `java_info.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 --- .../builtins_bzl/common/java/java_common.bzl | 13 ++++++++-- .../java_common_internal_for_builtins.bzl | 21 ---------------- .../builtins_bzl/common/java/java_info.bzl | 25 ++++++++++++++++--- .../common/java/proto/java_proto_library.bzl | 3 +-- 4 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/main/starlark/builtins_bzl/common/java/java_common.bzl b/src/main/starlark/builtins_bzl/common/java/java_common.bzl index fff7ada0291919..64fd0f97fd11bd 100644 --- a/src/main/starlark/builtins_bzl/common/java/java_common.bzl +++ b/src/main/starlark/builtins_bzl/common/java/java_common.bzl @@ -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") @@ -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. diff --git a/src/main/starlark/builtins_bzl/common/java/java_common_internal_for_builtins.bzl b/src/main/starlark/builtins_bzl/common/java/java_common_internal_for_builtins.bzl index 663c103571b35a..837c380da13413 100644 --- a/src/main/starlark/builtins_bzl/common/java/java_common_internal_for_builtins.bzl +++ b/src/main/starlark/builtins_bzl/common/java/java_common_internal_for_builtins.bzl @@ -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 diff --git a/src/main/starlark/builtins_bzl/common/java/java_info.bzl b/src/main/starlark/builtins_bzl/common/java/java_info.bzl index 1710699228a062..ff1e19773c18c2 100644 --- a/src/main/starlark/builtins_bzl/common/java/java_info.bzl +++ b/src/main/starlark/builtins_bzl/common/java/java_info.bzl @@ -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 @@ -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 @@ -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(), diff --git a/src/main/starlark/builtins_bzl/common/java/proto/java_proto_library.bzl b/src/main/starlark/builtins_bzl/common/java/proto/java_proto_library.bzl index c4ed89c0e187d1..e48bba14a862b6 100644 --- a/src/main/starlark/builtins_bzl/common/java/proto/java_proto_library.bzl +++ b/src/main/starlark/builtins_bzl/common/java/proto/java_proto_library.bzl @@ -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.