Extract legacy native symbols to a separate bzl file `legacy_native.bzl` will only be used by the compatibility proxy for Bazel versions < 8, and will thus allow removing these symbols from Bazel@HEAD. `native.bzl` now only exposes the `java_common` private APIs. PiperOrigin-RevId: 726035093 Change-Id: I8c78164b2b7ce9b647b2a7d195850213a85a8b86
diff --git a/java/private/BUILD b/java/private/BUILD index 020a4a7..27be00d 100644 --- a/java/private/BUILD +++ b/java/private/BUILD
@@ -7,10 +7,15 @@ srcs = [ "native.bzl", ], - visibility = [ - "//java:__subpackages__", - "@compatibility_proxy//:__pkg__", + visibility = ["//java:__subpackages__"], +) + +bzl_library( + name = "legacy_native_bzl", + srcs = [ + "legacy_native.bzl", ], + visibility = ["@compatibility_proxy//:__pkg__"], ) bzl_library(
diff --git a/java/private/legacy_native.bzl b/java/private/legacy_native.bzl new file mode 100644 index 0000000..7a9e62f --- /dev/null +++ b/java/private/legacy_native.bzl
@@ -0,0 +1,29 @@ +# Copyright 2022 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Redefine native symbols with a new name as a workaround for +# exporting them in @compatibility_proxy//:proxy.bzl with their original name. + +"""Lovely workaround to be able to expose native constants pretending to be Starlark.""" + +# Unused with Bazel@HEAD, only used by the compatibility layer for older Bazel versions + +# buildifier: disable=native-java-common +native_java_common = java_common + +# buildifier: disable=native-java-info +NativeJavaInfo = JavaInfo + +# buildifier: disable=native-java-plugin-info +NativeJavaPluginInfo = JavaPluginInfo
diff --git a/java/private/native.bzl b/java/private/native.bzl index e6be6f7..be7ae68 100644 --- a/java/private/native.bzl +++ b/java/private/native.bzl
@@ -12,29 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Redefine native symbols with a new name as a workaround for -# exporting them in `//third_party/bazel_rules/rules_proto/proto:defs.bzl` with their original name. -# -# While we cannot force users to load these symbol due to the lack of a -# allowlisting mechanism, we can still export them and tell users to -# load it to make a future migration to pure Starlark easier. - -"""Lovely workaround to be able to expose native constants pretending to be Starlark.""" - -# Unused with Bazel@HEAD, used by the compatibility layer for older Bazel versions - -# buildifier: disable=native-java-common -native_java_common = java_common - -# buildifier: disable=native-java-info -NativeJavaInfo = JavaInfo - -# buildifier: disable=native-java-plugin-info -NativeJavaPluginInfo = JavaPluginInfo +"""Redirects for private native APIs""" # Used for some private native APIs that we can't replicate just yet in Starlark -# getattr() for loading this file with Bazel 6, where we won't use this def get_internal_java_common(): - if hasattr(native_java_common, "internal_DO_NOT_USE"): - return native_java_common.internal_DO_NOT_USE() - return None + return java_common.internal_DO_NOT_USE() # buildifier: disable=native-java-common
diff --git a/java/rules_java_deps.bzl b/java/rules_java_deps.bzl index 1929bc8..b088f4d 100644 --- a/java/rules_java_deps.bzl +++ b/java/rules_java_deps.bzl
@@ -69,7 +69,7 @@ name = "proxy_bzl", srcs = ["proxy.bzl"], deps = [ - "@rules_java//java/private:native_bzl", + "@rules_java//java/private:legacy_native_bzl", "@bazel_tools//tools:bzl_srcs", ], visibility = ["//visibility:public"] @@ -80,7 +80,7 @@ "proxy.bzl", """ load("@bazel_tools//tools/build_defs/repo:http.bzl", _http_jar = "http_jar") -load("@rules_java//java/private:native.bzl", "native_java_common", "NativeJavaInfo", "NativeJavaPluginInfo") +load("@rules_java//java/private:legacy_native.bzl", "native_java_common", "NativeJavaInfo", "NativeJavaPluginInfo") java_binary = native.java_binary java_import = native.java_import