Skip to content

Commit

Permalink
Overhaul @rules_java bzl_library dep graph
Browse files Browse the repository at this point in the history
 - Construct an accurate `bzl_library` target for the compatibility proxy
 - Updates `proto_support.bzl` to use the right `java_common`
 - Work towards fixing bazelbuild/bazel#24455

PiperOrigin-RevId: 699129931
Change-Id: I55f6e744602e3760f69bc197a8f107fd119feee0
  • Loading branch information
hvadehra authored and rules_java Copybara committed Nov 22, 2024
1 parent a22cec1 commit 4bebd03
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 21 deletions.
1 change: 0 additions & 1 deletion .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ build_targets: &build_targets
- "@remote_java_tools//java_tools/..."
# TODO: Look into broken targets in //toolchains
- "-//toolchains/..."
- "-//test/repo/..."
# TODO: re-enable docs after protobuf is fixed
- "-//java/docs/..."
- "-//test:docs_up_to_date_test"
Expand Down
7 changes: 7 additions & 0 deletions java/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ bzl_library(
deps = ["//java/common"],
)

bzl_library(
name = "http_jar_bzl",
srcs = ["http_jar.bzl"],
visibility = ["//visibility:public"],
deps = ["@bazel_tools//tools:bzl_srcs"],
)

filegroup(
name = "for_bazel_tests",
testonly = 1,
Expand Down
3 changes: 2 additions & 1 deletion java/bazel/rules/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ bzl_library(
srcs = glob(["*.bzl"]),
visibility = ["//visibility:public"], # for Bazel docgen
deps = [
"//java/common",
"//java/common:semantics_bzl",
"//java/common/rules:core_rules",
"//java/common/rules/impl",
"//java/private:internals",
"@bazel_skylib//lib:paths",
"@rules_cc//cc:find_cc_toolchain_bzl",
"@rules_cc//cc/common",
Expand Down
24 changes: 21 additions & 3 deletions java/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,32 @@ filegroup(

bzl_library(
name = "common",
srcs = glob(["*.bzl"]),
srcs = glob(
["*.bzl"],
exclude = [
"java_semantics.bzl",
"proguard_spec_info.bzl",
],
),
visibility = ["//visibility:public"],
deps = ["@compatibility_proxy//:proxy_bzl"],
)

bzl_library(
name = "semantics_bzl",
srcs = ["java_semantics.bzl"],
visibility = ["//visibility:public"],
deps = [
"//java/private:internals",
"@compatibility_proxy//:proxy_bzl",
"@rules_cc//cc/common",
],
)

bzl_library(
name = "proguard_spec_info_bzl",
srcs = ["proguard_spec_info.bzl"],
visibility = ["//visibility:public"],
)

filegroup(
name = "for_bazel_tests",
testonly = 1,
Expand Down
3 changes: 2 additions & 1 deletion java/common/rules/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ bzl_library(
deps = [
":android_lint_bzl",
":rule_util_bzl",
"//java/common",
"//java/private:internals",
"@bazel_skylib//lib:paths",
"@rules_cc//cc/common",
],
Expand All @@ -53,6 +53,7 @@ bzl_library(
],
visibility = [
"//java:__subpackages__",
"@compatibility_proxy//:__pkg__",
],
)

Expand Down
1 change: 1 addition & 0 deletions java/common/rules/impl/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bzl_library(
visibility = ["//java:__subpackages__"],
deps = [
":java_helper_bzl",
"//java/common:proguard_spec_info_bzl",
"@com_google_protobuf//bazel/common:proto_info_bzl",
],
)
Expand Down
12 changes: 9 additions & 3 deletions java/private/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ bzl_library(
srcs = [
"native.bzl",
],
visibility = ["//java:__subpackages__"],
visibility = [
"//java:__subpackages__",
"@compatibility_proxy//:__pkg__",
],
)

bzl_library(
Expand All @@ -19,7 +22,10 @@ bzl_library(
"java_info.bzl",
"message_bundle_info.bzl",
],
visibility = ["//java:__subpackages__"],
visibility = [
"//java:__subpackages__",
"@compatibility_proxy//:__pkg__",
],
deps = [
":native_bzl",
"//java/common/rules:toolchain_rules",
Expand All @@ -35,7 +41,7 @@ bzl_library(
name = "proto_support",
srcs = ["proto_support.bzl"],
visibility = ["//visibility:public"],
deps = [":native_bzl"],
deps = ["@compatibility_proxy//:proxy_bzl"],
)

filegroup(
Expand Down
2 changes: 1 addition & 1 deletion java/private/proto_support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
"""Support for Java compilation of protocol buffer generated code."""

load("//java/common:java_common.bzl", "java_common")
load("@compatibility_proxy//:proxy.bzl", "java_common")

# Partial support, because internal symbols are not available in older Bazel version
# TODO: Once Java rules are moved into the rules_java, this should become a full support.
Expand Down
41 changes: 34 additions & 7 deletions java/rules_java_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,25 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
def _compatibility_proxy_repo_impl(rctx):
# TODO: use @bazel_features
bazel = native.bazel_version
rctx.file(
"BUILD.bazel",
"""
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
bzl_library(name = "proxy_bzl", srcs = ["proxy.bzl"], visibility = ["//visibility:public"])
""",
)
if not bazel or bazel >= "8":
rctx.file(
"BUILD.bazel",
"""
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
exports_files(['proxy.bzl'], visibility = ["@rules_java//test:__pkg__"])
bzl_library(
name = "proxy_bzl",
srcs = ["proxy.bzl"],
deps = [
"@rules_java//java/bazel/rules",
"@rules_java//java/common/rules:toolchain_rules",
"@rules_java//java/private:internals",
"@rules_java//java:http_jar_bzl",
],
visibility = ["//visibility:public"]
)
""",
)
rctx.file(
"proxy.bzl",
"""
Expand Down Expand Up @@ -45,6 +56,22 @@ http_jar = _http_jar
""",
)
else:
rctx.file(
"BUILD.bazel",
"""
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
exports_files(['proxy.bzl'], visibility = ["@rules_java//test:__pkg__"])
bzl_library(
name = "proxy_bzl",
srcs = ["proxy.bzl"],
deps = [
"@rules_java//java/private:native_bzl",
"@bazel_tools//tools:bzl_srcs",
],
visibility = ["//visibility:public"]
)
""",
)
rctx.file(
"proxy.bzl",
"""
Expand Down
5 changes: 1 addition & 4 deletions java/toolchains/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ bzl_library(
name = "toolchain_rules",
srcs = glob(["*.bzl"]),
visibility = ["//visibility:public"],
deps = [
"//java/private:native_bzl",
"@compatibility_proxy//:proxy_bzl",
],
deps = ["@compatibility_proxy//:proxy_bzl"],
)

filegroup(
Expand Down
6 changes: 6 additions & 0 deletions test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,9 @@ diff_test(
)

validate_configs()

starlark_doc_extract(
name = "proxy_bzl_graph",
src = "@compatibility_proxy//:proxy.bzl",
deps = ["@compatibility_proxy//:proxy_bzl"],
)

0 comments on commit 4bebd03

Please sign in to comment.