From ae3262f1450d44fcbb1d8646b2ffac685541a0de Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 20 Nov 2024 09:10:17 -0800 Subject: [PATCH] Stop exporting java rules / providers from `@_builtins` `java_common` needs to remain (minimally exported) for private APIs PiperOrigin-RevId: 698412708 Change-Id: I58708761e7abbc63013f75276b1cd1f98c11430f --- .../java/com/google/devtools/build/lib/bazel/rules/BUILD | 5 +++-- .../devtools/build/lib/rules/java/MessageBundleInfo.java | 8 +++++--- src/main/starlark/builtins_bzl/bazel/exports.bzl | 9 +-------- src/main/starlark/builtins_bzl/common/exports.bzl | 5 +---- .../build/lib/rules/java/JavaInfoStarlarkApiTest.java | 2 ++ .../StarlarkRuleImplementationFunctionsTest.java | 1 + src/test/shell/bazel/bazel_rules_java_test.sh | 4 +++- .../integration/incompatible_autoload_externally_test.sh | 4 +++- src/test/shell/testenv.sh | 4 +++- workspace_deps.bzl | 6 +++--- 10 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BUILD b/src/main/java/com/google/devtools/build/lib/bazel/rules/BUILD index 2c4ab5e8f0258c..4837d099b8e0e7 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BUILD +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BUILD @@ -130,13 +130,14 @@ gen_workspace_stanza( name = "rules_suffix", out = "rules_suffix.WORKSPACE", postamble = """ - load("@rules_java//java:repositories.bzl", "rules_java_dependencies", "rules_java_toolchains") + load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies") rules_java_dependencies() - rules_java_toolchains() load("@rules_python//python:repositories.bzl", "py_repositories") py_repositories() load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") protobuf_deps() + load("@rules_java//java:repositories.bzl", "rules_java_toolchains") + rules_java_toolchains() """, preamble = """ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/MessageBundleInfo.java b/src/main/java/com/google/devtools/build/lib/rules/java/MessageBundleInfo.java index 2cefa4b1ed9112..c06966475e41aa 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/MessageBundleInfo.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/MessageBundleInfo.java @@ -14,7 +14,7 @@ package com.google.devtools.build.lib.rules.java; -import static com.google.devtools.build.lib.skyframe.BzlLoadValue.keyForBuiltins; +import static com.google.devtools.build.lib.skyframe.BzlLoadValue.keyForBuild; import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.actions.Artifact; @@ -42,8 +42,10 @@ public final class MessageBundleInfo { private static class Provider extends StarlarkProviderWrapper { private Provider() { super( - keyForBuiltins( - Label.parseCanonicalUnchecked("@_builtins//:common/java/message_bundle_info.bzl")), + keyForBuild( + Label.parseCanonicalUnchecked( + JavaSemantics.RULES_JAVA_PROVIDER_LABELS_PREFIX + + "java/private:message_bundle_info.bzl")), STARLARK_NAME); } diff --git a/src/main/starlark/builtins_bzl/bazel/exports.bzl b/src/main/starlark/builtins_bzl/bazel/exports.bzl index 8c8696c86d60f7..be2ebba962140e 100644 --- a/src/main/starlark/builtins_bzl/bazel/exports.bzl +++ b/src/main/starlark/builtins_bzl/bazel/exports.bzl @@ -15,17 +15,10 @@ """Exported builtins symbols that are specific to OSS Bazel.""" load("@_builtins//:common/python/py_internal.bzl", "py_internal") -load(":common/java/java_package_configuration.bzl", "java_package_configuration") -load(":common/java/java_runtime.bzl", "java_runtime") -load(":common/java/java_toolchain.bzl", "java_toolchain") exported_toplevels = { "py_internal": py_internal, "proto_common_do_not_use": struct(INCOMPATIBLE_ENABLE_PROTO_TOOLCHAIN_RESOLUTION = _builtins.toplevel.proto_common_do_not_use.incompatible_enable_proto_toolchain_resolution()), } -exported_rules = { - "java_package_configuration": java_package_configuration, - "java_runtime": java_runtime, - "java_toolchain": java_toolchain, -} +exported_rules = {} exported_to_java = {} diff --git a/src/main/starlark/builtins_bzl/common/exports.bzl b/src/main/starlark/builtins_bzl/common/exports.bzl index 1e96b1b8b1a29f..e7d0902ba6152e 100755 --- a/src/main/starlark/builtins_bzl/common/exports.bzl +++ b/src/main/starlark/builtins_bzl/common/exports.bzl @@ -37,7 +37,6 @@ load(":common/cc/fdo/fdo_profile.bzl", "fdo_profile") load(":common/cc/fdo/memprof_profile.bzl", "memprof_profile") load(":common/cc/fdo/propeller_optimize.bzl", "propeller_optimize") load(":common/java/java_common.bzl", "java_common") -load(":common/java/java_info.bzl", "JavaInfo", "JavaPluginInfo") load(":common/objc/apple_common.bzl", "apple_common") load(":common/objc/objc_common.bzl", "objc_common") @@ -49,9 +48,7 @@ exported_toplevels = { "CcSharedLibraryInfo": CcSharedLibraryInfo, "CcSharedLibraryHintInfo": CcSharedLibraryHintInfo, "cc_common": cc_common, - "+JavaPluginInfo": JavaPluginInfo, - "+JavaInfo": JavaInfo, - "java_common": java_common, + "java_common": struct(internal_DO_NOT_USE = java_common.internal_DO_NOT_USE), "apple_common": apple_common, } diff --git a/src/test/java/com/google/devtools/build/lib/rules/java/JavaInfoStarlarkApiTest.java b/src/test/java/com/google/devtools/build/lib/rules/java/JavaInfoStarlarkApiTest.java index 2aa0bf277d4e4c..5b0ef546ca65b5 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/java/JavaInfoStarlarkApiTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/java/JavaInfoStarlarkApiTest.java @@ -1277,6 +1277,7 @@ public void nativeAndStarlarkJavaOutputsCanBeAddedToADepset() throws Exception { scratch.file( "foo/extension.bzl", """ + load("@rules_java//java/common:java_info.bzl", "JavaInfo") def _impl(ctx): f = ctx.actions.declare_file(ctx.label.name + ".jar") ctx.actions.write(f, "") @@ -1313,6 +1314,7 @@ public void testNeverlinkIsStoredAsABoolean() throws Exception { scratch.file( "foo/extension.bzl", """ + load("@rules_java//java/common:java_info.bzl", "JavaInfo") def _impl(ctx): f = ctx.actions.declare_file(ctx.label.name + ".jar") ctx.actions.write(f, "") diff --git a/src/test/java/com/google/devtools/build/lib/starlark/StarlarkRuleImplementationFunctionsTest.java b/src/test/java/com/google/devtools/build/lib/starlark/StarlarkRuleImplementationFunctionsTest.java index 1ed66098c28402..a2c537ba939f38 100644 --- a/src/test/java/com/google/devtools/build/lib/starlark/StarlarkRuleImplementationFunctionsTest.java +++ b/src/test/java/com/google/devtools/build/lib/starlark/StarlarkRuleImplementationFunctionsTest.java @@ -1573,6 +1573,7 @@ public void testLacksAdvertisedBuiltinProvider() throws Exception { scratch.file( "test/foo.bzl", """ + load("@rules_java//java/common:java_info.bzl", "JavaInfo") FooInfo = provider() def _impl(ctx): MyFooInfo = FooInfo() diff --git a/src/test/shell/bazel/bazel_rules_java_test.sh b/src/test/shell/bazel/bazel_rules_java_test.sh index 54b549c817b708..eaa871d67f9054 100755 --- a/src/test/shell/bazel/bazel_rules_java_test.sh +++ b/src/test/shell/bazel/bazel_rules_java_test.sh @@ -72,9 +72,11 @@ EOF filegroup(name = 'yolo') EOF touch override/java/BUILD || fail "couldn't touch override/java/BUILD" - cat > override/java/repositories.bzl < override/java/rules_java_deps.bzl < override/java/repositories.bzl < "${rules_java_workspace}/java/repositories.bzl" < "${rules_java_workspace}/java/rules_java_deps.bzl" < "${rules_java_workspace}/java/repositories.bzl" < "${rules_java_workspace}/java/repositories.bzl" < "${rules_java_workspace}/java/rules_java_deps.bzl" < "${rules_java_workspace}/java/repositories.bzl" <