Skip to content

Commit

Permalink
[bazel] Add fixes for --incompatible_load_proto_rules_from_bzl
Browse files Browse the repository at this point in the history
Starting soon, Protobuf rules will require explicit load statements
bazelbuild/bazel#8922
  • Loading branch information
Yannic committed Oct 24, 2019
1 parent d555967 commit f328ac6
Show file tree
Hide file tree
Showing 23 changed files with 66 additions and 52 deletions.
3 changes: 3 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ workspace(name = "com_github_grpc_grpc")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("//bazel:grpc_deps.bzl", "grpc_deps", "grpc_test_only_deps")
load("//bazel:grpc_python_deps.bzl", "grpc_python_deps")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

grpc_deps()

grpc_test_only_deps()

grpc_python_deps()

register_execution_platforms(
"//third_party/toolchains:local",
"//third_party/toolchains:local_large",
Expand Down
3 changes: 2 additions & 1 deletion bazel/cc_grpc_library.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Generates and compiles C++ grpc stubs from proto_library rules."""

load("@rules_proto//proto:defs.bzl", "proto_library")
load("//bazel:generate_cc.bzl", "generate_cc")
load("//bazel:protobuf.bzl", "well_known_proto_libs")

Expand Down Expand Up @@ -64,7 +65,7 @@ def cc_grpc_library(
if well_known_protos:
proto_deps += well_known_proto_libs()

native.proto_library(
proto_library(
name = proto_target,
srcs = srcs,
deps = proto_deps,
Expand Down
8 changes: 4 additions & 4 deletions bazel/grpc_build_system.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def grpc_cc_library(
testonly = testonly,
linkopts = linkopts,
includes = [
"include",
"include",
"src/core/ext/upb-generated", # Once upb code-gen issue is resolved, remove this.
],
alwayslink = alwayslink,
Expand Down Expand Up @@ -181,7 +181,7 @@ def grpc_cc_test(name, srcs = [], deps = [], external_deps = [], args = [], data
"exec_compatible_with": exec_compatible_with,
}
if uses_polling:
# the vanilla version of the test should run on platforms that only
# the vanilla version of the test should run on platforms that only
# support a single poller
native.cc_test(
name = name,
Expand Down Expand Up @@ -317,7 +317,7 @@ def grpc_objc_library(
deps: dependencies
visibility: visibility, default to public
"""

native.objc_library(
name = name,
hdrs = hdrs,
Expand All @@ -329,7 +329,7 @@ def grpc_objc_library(
includes = includes,
visibility = visibility,
)

def grpc_upb_proto_library(name, deps):
upb_proto_library(name = name, deps = deps)

Expand Down
8 changes: 4 additions & 4 deletions bazel/grpc_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def grpc_deps():
name = "gtest",
actual = "@com_github_google_googletest//:gtest",
)

native.bind(
name = "benchmark",
actual = "@com_github_google_benchmark//:benchmark",
Expand Down Expand Up @@ -117,9 +117,9 @@ def grpc_deps():
if "com_google_protobuf" not in native.existing_rules():
http_archive(
name = "com_google_protobuf",
sha256 = "416212e14481cff8fd4849b1c1c1200a7f34808a54377e22d7447efdf54ad758",
strip_prefix = "protobuf-09745575a923640154bcf307fba8aedff47f240a",
url = "https://github.com/google/protobuf/archive/09745575a923640154bcf307fba8aedff47f240a.tar.gz",
sha256 = "758249b537abba2f21ebc2d02555bf080917f0f2f88f4cbe2903e0e28c4187ed",
strip_prefix = "protobuf-3.10.0",
url = "https://github.com/google/protobuf/archive/v3.10.0.tar.gz",
)

if "com_github_google_googletest" not in native.existing_rules():
Expand Down
15 changes: 3 additions & 12 deletions bazel/grpc_python_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,12 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@com_github_grpc_grpc//third_party/py:python_configure.bzl", "python_configure")

def grpc_python_deps():
native.bind(
name = "six",
actual = "@six_archive//:six",
)

# protobuf binds to the name "six", so we can't use it here.
# See https://github.com/bazelbuild/bazel/issues/1952 for why bind is
# horrible.
if "six_archive" not in native.existing_rules():
if "six" not in native.existing_rules():
http_archive(
name = "six_archive",
strip_prefix = "six-1.12.0",
name = "six",
build_file = "@com_github_grpc_grpc//third_party:six.BUILD",
sha256 = "d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73",
urls = ["https://files.pythonhosted.org/packages/dd/bf/4138e7bfb757de47d1f4b6994648ec67a51efe58fa907c1e11e350cddfca/six-1.12.0.tar.gz"],
urls = ["https://pypi.python.org/packages/source/s/six/six-1.12.0.tar.gz"],
)

if "enum34" not in native.existing_rules():
Expand Down
2 changes: 1 addition & 1 deletion src/objective-c/examples/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ licenses(["notice"]) # 3-clause BSD
package(default_visibility = ["//visibility:public"])

load(
"//src/objective-c:grpc_objc_internal_library.bzl",
"//src/objective-c:grpc_objc_internal_library.bzl",
"grpc_objc_examples_library",
"local_objc_grpc_library",
"proto_library_objc_wrapper",
Expand Down
3 changes: 2 additions & 1 deletion src/objective-c/grpc_objc_internal_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# each change must be ported from one to the other.
#

load("@rules_proto//proto:defs.bzl", "proto_library")
load(
"//bazel:generate_objc.bzl",
"generate_objc",
Expand All @@ -39,7 +40,7 @@ def proto_library_objc_wrapper(
"""proto_library for adding dependencies to google/protobuf protos
use_well_known_protos - ignored in open source version
"""
native.proto_library(
proto_library(
name = name,
srcs = srcs,
deps = deps,
Expand Down
5 changes: 3 additions & 2 deletions src/proto/grpc/channelz/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

licenses(["notice"]) # Apache v2

load("@rules_proto//proto:defs.bzl", "proto_library")
load("//bazel:grpc_build_system.bzl", "grpc_proto_library", "grpc_package")

licenses(["notice"]) # Apache v2

grpc_package(name = "channelz", visibility = "public")

grpc_proto_library(
Expand Down
5 changes: 3 additions & 2 deletions src/proto/grpc/core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

licenses(["notice"]) # Apache v2

load("@rules_proto//proto:defs.bzl", "proto_library")
load("//bazel:grpc_build_system.bzl", "grpc_proto_library", "grpc_package")

licenses(["notice"]) # Apache v2

grpc_package(name = "core", visibility = "public")

grpc_proto_library(
Expand Down
2 changes: 2 additions & 0 deletions src/proto/grpc/gcp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_proto//proto:defs.bzl", "proto_library")

licenses(["notice"]) # Apache v2

proto_library(
Expand Down
5 changes: 3 additions & 2 deletions src/proto/grpc/health/v1/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

licenses(["notice"]) # Apache v2

load("@rules_proto//proto:defs.bzl", "proto_library")
load("//bazel:grpc_build_system.bzl", "grpc_proto_library", "grpc_package")

licenses(["notice"]) # Apache v2

grpc_package(name = "health", visibility = "public")

grpc_proto_library(
Expand Down
5 changes: 3 additions & 2 deletions src/proto/grpc/lb/v1/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

licenses(["notice"]) # Apache v2

load("@rules_proto//proto:defs.bzl", "proto_library")
load("//bazel:grpc_build_system.bzl", "grpc_package", "grpc_proto_library")

licenses(["notice"]) # Apache v2

grpc_package(
name = "lb",
visibility = "public",
Expand Down
5 changes: 3 additions & 2 deletions src/proto/grpc/reflection/v1alpha/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

licenses(["notice"]) # Apache v2

load("@rules_proto//proto:defs.bzl", "proto_library")
load("//bazel:grpc_build_system.bzl", "grpc_proto_library", "grpc_package")

licenses(["notice"]) # Apache v2

grpc_package(name = "reflection", visibility = "public")

grpc_proto_library(
Expand Down
5 changes: 3 additions & 2 deletions src/proto/grpc/status/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

licenses(["notice"]) # Apache v2

load("@rules_proto//proto:defs.bzl", "proto_library")
load("//bazel:grpc_build_system.bzl", "grpc_proto_library", "grpc_package")

licenses(["notice"]) # Apache v2

grpc_package(name = "status", visibility = "public")

grpc_proto_library(
Expand Down
5 changes: 3 additions & 2 deletions src/proto/grpc/testing/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

licenses(["notice"]) # Apache v2

load("@rules_proto//proto:defs.bzl", "proto_library")
load("//bazel:grpc_build_system.bzl", "grpc_proto_library", "grpc_package")
load("@grpc_python_dependencies//:requirements.bzl", "requirement")
load("//bazel:python_rules.bzl", "py_proto_library", "py_grpc_library")

licenses(["notice"]) # Apache v2

grpc_package(
name = "testing",
visibility = "public",
Expand Down
4 changes: 2 additions & 2 deletions src/proto/grpc/testing/duplicate/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

licenses(["notice"]) # Apache v2

load("//bazel:grpc_build_system.bzl", "grpc_proto_library", "grpc_package")

licenses(["notice"]) # Apache v2

grpc_package(name = "duplicate", visibility = "public")

grpc_proto_library(
Expand Down
3 changes: 2 additions & 1 deletion src/proto/grpc/testing/proto2/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@grpc_python_dependencies//:requirements.bzl", "requirement")
load("//bazel:python_rules.bzl", "py_proto_library")

package(default_visibility = ["//visibility:public"])
load("//bazel:python_rules.bzl", "py_proto_library")

proto_library(
name = "empty2_proto_descriptor",
Expand Down
5 changes: 3 additions & 2 deletions src/proto/grpc/testing/xds/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

licenses(["notice"]) # Apache v2

load("@rules_proto//proto:defs.bzl", "proto_library")
load("//bazel:grpc_build_system.bzl", "grpc_package", "grpc_proto_library")

licenses(["notice"]) # Apache v2

grpc_package(
name = "xds",
visibility = "public",
Expand Down
2 changes: 1 addition & 1 deletion src/python/grpcio/grpc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ py_library(
"//src/python/grpcio/grpc/_cython:cygrpc",
"//src/python/grpcio/grpc/experimental",
"//src/python/grpcio/grpc/framework",
"@six_archive//:six",
"@six",
] + select({
"//conditions:default": ["@enum34//:enum34",],
"//:python3": [],
Expand Down
6 changes: 3 additions & 3 deletions src/python/grpcio/grpc/framework/foundation/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ py_library(
name = "callable_util",
srcs = ["callable_util.py"],
deps = [
"//external:six",
"@six",
] + select({
"//conditions:default": ["@enum34//:enum34",],
"//:python3": [],
Expand All @@ -33,7 +33,7 @@ py_library(
name = "future",
srcs = ["future.py"],
deps = [
"//external:six",
"@six",
],
)

Expand All @@ -58,6 +58,6 @@ py_library(
name = "stream",
srcs = ["stream.py"],
deps = [
"//external:six",
"@six",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ py_library(
srcs = ["base.py"],
deps = [
"//src/python/grpcio/grpc/framework/foundation:abandonment",
"//external:six",
"@six",
] + select({
"//conditions:default": ["@enum34//:enum34",],
"//:python3": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ py_library(
deps = [
"//src/python/grpcio/grpc/framework/foundation",
"//src/python/grpcio/grpc/framework/common",
"//external:six",
"@six",
] + select({
"//conditions:default": ["@enum34//:enum34",],
"//:python3": [],
Expand Down
15 changes: 11 additions & 4 deletions third_party/six.BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
genrule(
name = "copy_six",
srcs = ["six-1.12.0/six.py"],
outs = ["__init__.py"],
cmd = "cp $< $(@)",
)

py_library(
name = "six",
srcs = ["six.py"],
srcs_version = "PY2AND3",
visibility = ["//visibility:public"],
name = "six",
srcs = ["__init__.py"],
srcs_version = "PY2AND3",
visibility = ["//visibility:public"],
)

0 comments on commit f328ac6

Please sign in to comment.