Skip to content

Commit

Permalink
Add protobuf patch that has for_bazel_tests
Browse files Browse the repository at this point in the history
This works towards running Bazel's unit tests against rules implemented in protobuf repository.

PiperOrigin-RevId: 684767641
Change-Id: I5fbb22b5d30dcd0dbdee6ca7b3170688fd85208a
  • Loading branch information
comius authored and copybara-github committed Oct 11, 2024
1 parent 4b38f2f commit aa6d0ca
Show file tree
Hide file tree
Showing 6 changed files with 252 additions and 0 deletions.
1 change: 1 addition & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ genrule(
"//third_party/protobuf:remove_rules_rust.patch",
"//third_party/protobuf:add_python_loads.patch",
"//third_party/protobuf:add_rules_shell_loads.patch",
"//third_party/protobuf:bzl_library.patch",
],
outs = ["MODULE.bazel.lock.dist"],
cmd = " && ".join([
Expand Down
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ archive_override(
"//third_party/protobuf:remove_rules_rust.patch",
"//third_party/protobuf:add_python_loads.patch",
"//third_party/protobuf:add_rules_shell_loads.patch",
"//third_party/protobuf:bzl_library.patch",
],
strip_prefix = "protobuf-29.0-rc1",
urls = ["https://github.com/protocolbuffers/protobuf/releases/download/v29.0-rc1/protobuf-29.0-rc1.zip"],
Expand Down
1 change: 1 addition & 0 deletions src/test/shell/bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ filegroup(
"//src/test/shell:bin/bazel",
"//third_party/protobuf:add_python_loads.patch",
"//third_party/protobuf:add_rules_shell_loads.patch",
"//third_party/protobuf:bzl_library.patch",
"//third_party/protobuf:proto_info_bzl_deps.patch",
"//third_party/protobuf:remove_rules_rust.patch",
],
Expand Down
2 changes: 2 additions & 0 deletions src/test/shell/testenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ function add_protobuf() {
cp "$(rlocation io_bazel/third_party/protobuf/proto_info_bzl_deps.patch)" third_party/protobuf/proto_info_bzl_deps.patch
cp "$(rlocation io_bazel/third_party/protobuf/add_python_loads.patch)" third_party/protobuf/add_python_loads.patch
cp "$(rlocation io_bazel/third_party/protobuf/add_rules_shell_loads.patch)" third_party/protobuf/add_rules_shell_loads.patch
cp "$(rlocation io_bazel/third_party/protobuf/bzl_library.patch)" third_party/protobuf/bzl_library.patch
cat >> "$1" <<EOF
archive_override(
module_name = "protobuf",
Expand All @@ -611,6 +612,7 @@ archive_override(
"//third_party/protobuf:remove_rules_rust.patch",
"//third_party/protobuf:add_python_loads.patch",
"//third_party/protobuf:add_rules_shell_loads.patch",
"//third_party/protobuf:bzl_library.patch",
],
strip_prefix = "protobuf-29.0-rc1",
urls = ["https://github.com/protocolbuffers/protobuf/releases/download/v29.0-rc1/protobuf-29.0-rc1.zip"],
Expand Down
1 change: 1 addition & 0 deletions third_party/protobuf/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exports_files([
"remove_rules_rust.patch",
"add_python_loads.patch",
"add_rules_shell_loads.patch",
"bzl_library.patch",
])

alias(
Expand Down
246 changes: 246 additions & 0 deletions third_party/protobuf/bzl_library.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
diff --git a/bazel/BUILD.bazel b/bazel/BUILD.bazel
index d0546f9b3..71190a6ca 100644
--- a/bazel/BUILD.bazel
+++ b/bazel/BUILD.bazel
@@ -13,24 +13,31 @@ bzl_library(
name = "proto_library_bzl",
srcs = ["proto_library.bzl"],
visibility = ["//visibility:public"],
+ deps = [
+ "//bazel/private:bazel_proto_library_rule_bzl",
+ "@proto_bazel_features//:features",
+ ],
)

bzl_library(
name = "cc_proto_library_bzl",
srcs = ["cc_proto_library.bzl"],
visibility = ["//visibility:public"],
+ deps = ["//bazel/private:bazel_cc_proto_library_bzl"],
)

bzl_library(
name = "java_proto_library_bzl",
srcs = ["java_proto_library.bzl"],
visibility = ["//visibility:public"],
+ deps = ["//bazel/private:bazel_java_proto_library_rule_bzl"],
)

bzl_library(
name = "java_lite_proto_library_bzl",
srcs = ["java_lite_proto_library.bzl"],
visibility = ["//visibility:public"],
+ deps = ["//bazel/private:java_lite_proto_library_bzl"],
)

bzl_library(
@@ -56,3 +63,19 @@ bzl_library(
visibility = ["//visibility:public"],
deps = ["//bazel/private:upb_proto_library_internal_bzl"],
)
+
+# The data in this target is exposed in //bazel/private:for_bazel_tests
+filegroup(
+ name = "for_bazel_tests",
+ testonly = True,
+ srcs = [
+ "BUILD.bazel",
+ ":cc_proto_library_bzl",
+ ":java_lite_proto_library_bzl",
+ ":proto_library_bzl",
+ ":py_proto_library_bzl",
+ "//bazel/common:for_bazel_tests",
+ "//bazel/toolchains:for_bazel_tests",
+ ],
+ visibility = ["//bazel/private:__pkg__"],
+)
diff --git a/bazel/common/BUILD b/bazel/common/BUILD
index 9ab40ff05..073e56411 100644
--- a/bazel/common/BUILD
+++ b/bazel/common/BUILD
@@ -10,6 +10,7 @@ bzl_library(
visibility = ["//visibility:public"],
deps = [
":proto_lang_toolchain_info_bzl",
+ "//bazel/private:native_bzl",
"//bazel/private:toolchain_helpers_bzl",
"@proto_bazel_features//:features",
],
@@ -39,9 +40,13 @@ bzl_library(
)

filegroup(
- name = "bazel_osx_p4deps",
- srcs = glob(["**"]) + ["@proto_bazel_features//:features"],
- visibility = [
- "//bazel:__pkg__",
+ name = "for_bazel_tests",
+ testonly = True,
+ srcs = [
+ "BUILD",
+ "proto_common_bzl",
+ "proto_info_bzl",
+ "proto_lang_toolchain_info_bzl",
],
+ visibility = ["//bazel:__pkg__"],
)
diff --git a/bazel/private/BUILD b/bazel/private/BUILD
index 8e5207f3a..16c2bc536 100644
--- a/bazel/private/BUILD
+++ b/bazel/private/BUILD
@@ -1,5 +1,5 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
-load("//bazel/private:native_bool_flag.bzl", "native_bool_flag")
+load(":native_bool_flag.bzl", "native_bool_flag")

package(default_applicable_licenses = ["//:license"])

@@ -59,15 +59,60 @@ bzl_library(
],
visibility = ["//bazel:__subpackages__"],
deps = [
+ ":toolchain_helpers_bzl",
"//bazel/common:proto_common_bzl",
"//bazel/common:proto_info_bzl",
- "//bazel/private:toolchain_helpers_bzl",
"@bazel_skylib//lib:paths",
"@bazel_skylib//rules:common_settings",
"@proto_bazel_features//:features",
],
)

+bzl_library(
+ name = "bazel_java_proto_library_rule_bzl",
+ srcs = [
+ "bazel_java_proto_library_rule.bzl",
+ "java_proto_support.bzl",
+ ],
+ visibility = ["//bazel:__subpackages__"],
+ deps = [
+ ":toolchain_helpers_bzl",
+ "//bazel/common:proto_common_bzl",
+ "//bazel/common:proto_info_bzl",
+ "@rules_java//java/common",
+ ],
+)
+
+bzl_library(
+ name = "java_lite_proto_library_bzl",
+ srcs = [
+ "java_lite_proto_library.bzl",
+ "java_proto_support.bzl",
+ ],
+ visibility = ["//bazel:__subpackages__"],
+ deps = [
+ ":toolchain_helpers_bzl",
+ "//bazel/common:proto_common_bzl",
+ "//bazel/common:proto_info_bzl",
+ "@rules_java//java/common",
+ ],
+)
+
+bzl_library(
+ name = "bazel_cc_proto_library_bzl",
+ srcs = [
+ "bazel_cc_proto_library.bzl",
+ "cc_proto_support.bzl",
+ ],
+ visibility = ["//bazel:__subpackages__"],
+ deps = [
+ ":toolchain_helpers_bzl",
+ "//bazel/common:proto_common_bzl",
+ "//bazel/common:proto_info_bzl",
+ "@proto_bazel_features//:features",
+ ],
+)
+
bzl_library(
name = "proto_toolchain_rule_bzl",
srcs = [
@@ -75,9 +120,9 @@ bzl_library(
],
visibility = ["//bazel:__subpackages__"],
deps = [
+ ":toolchain_helpers_bzl",
"//bazel/common:proto_common_bzl",
"//bazel/common:proto_lang_toolchain_info_bzl",
- "//bazel/private:toolchain_helpers_bzl",
],
)

@@ -139,10 +184,21 @@ native_bool_flag(
visibility = ["//bazel:__subpackages__"],
)

+bzl_library(
+ name = "native_bool_flag_bzl",
+ srcs = ["native_bool_flag.bzl"],
+ visibility = ["//visibility:private"],
+ deps = ["@bazel_skylib//rules:common_settings"],
+)
+
filegroup(
- name = "bazel_osx_p4deps",
- srcs = glob(["**"]),
- visibility = [
- "//bazel:__pkg__",
+ name = "for_bazel_tests",
+ testonly = True,
+ srcs = [
+ "BUILD",
+ ":native_bool_flag_bzl",
+ "//bazel:for_bazel_tests",
+ "//bazel/private/toolchains:for_bazel_tests",
],
+ visibility = ["//visibility:public"],
)
diff --git a/bazel/private/toolchain_helpers.bzl b/bazel/private/toolchain_helpers.bzl
index aa49eb8cf..edf3a8b69 100644
--- a/bazel/private/toolchain_helpers.bzl
+++ b/bazel/private/toolchain_helpers.bzl
@@ -45,5 +45,5 @@ toolchains = struct(
find_toolchain = _find_toolchain,
if_legacy_toolchain = _if_legacy_toolchain,
INCOMPATIBLE_ENABLE_PROTO_TOOLCHAIN_RESOLUTION = _incompatible_toolchain_resolution,
- PROTO_TOOLCHAIN = "//bazel/private:proto_toolchain_type",
+ PROTO_TOOLCHAIN = Label("//bazel/private:proto_toolchain_type"),
)
diff --git a/bazel/private/toolchains/BUILD.bazel b/bazel/private/toolchains/BUILD.bazel
index b727a4a97..b21e46276 100644
--- a/bazel/private/toolchains/BUILD.bazel
+++ b/bazel/private/toolchains/BUILD.bazel
@@ -72,3 +72,14 @@ toolchain(
toolchain = "//java/lite:toolchain",
toolchain_type = "@rules_java//java/proto:lite_toolchain_type",
)
+
+filegroup(
+ name = "for_bazel_tests",
+ testonly = True,
+ srcs = [
+ "BUILD.bazel",
+ ],
+ visibility = [
+ "//bazel/private:__pkg__",
+ ],
+)
diff --git a/bazel/toolchains/BUILD b/bazel/toolchains/BUILD
index 6353a6544..2f629a69e 100644
--- a/bazel/toolchains/BUILD
+++ b/bazel/toolchains/BUILD
@@ -28,8 +28,13 @@ bzl_library(
)

filegroup(
- name = "bazel_osx_p4deps",
- srcs = glob(["**"]),
+ name = "for_bazel_tests",
+ testonly = True,
+ srcs = [
+ "BUILD",
+ "proto_lang_toolchain_bzl",
+ "proto_toolchain_bzl",
+ ],
visibility = [
"//bazel:__pkg__",
],

0 comments on commit aa6d0ca

Please sign in to comment.