Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Bazel 0.28.1 #20097

Merged
merged 11 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ config_setting(

config_setting(
name = "python3",
values = {"python_path": "python3"},
flag_values = {"@bazel_tools//tools/python:python_version": "PY3"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with the relationship between BUILD and BUILD.tpl. Do we need a config_setting for Python 2 here? Or we can remove this config_setting completely?

Copy link
Contributor Author

@gnossen gnossen Aug 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I'm not sure I completely understand the intent behind the config_setting system in Bazel. My hope was that the rules_python repo would define a Python 2 config setting and a Python 3 config setting which we could then reference. Unfortunately, it appears that the expectation is that each project will define its own config_settings with the flag values provided by rules_python.

An alternative would be to change all of our select statements to refer to @local_config_python//:python3 instead of //:python3. I personally don't have a preference. On the one hand, I like that it allows us to eliminate this config_setting, but on the other hand, I've had nothing but problems with repository rules, so I'd like to depend on them as little as possible. (I understand the irony that this PR is mostly an overhaul of a repository rule)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we have to add our own config_setting, I think we can add a Python 2 version of it.

I personally prefer //:python3 than the longer version, it seems the duplication of the code decouples the config_setting with generated repository rule.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, but we don't actually reference it anywhere. We use //conditions:default. I suppose we could make them explicit, but I think the way we have things now is also fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol: how about make the Python 3 the new default?

)

config_setting(
Expand Down
11 changes: 10 additions & 1 deletion bazel/grpc_build_system.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,22 @@ def grpc_sh_binary(name, srcs, data = []):
data = data,
)

def grpc_py_binary(name, srcs, data = [], deps = [], external_deps = [], testonly = False):
def grpc_py_binary(name,
srcs,
data = [],
deps = [],
external_deps = [],
testonly = False,
python_version = "PY2",
**kwargs):
native.py_binary(
name = name,
srcs = srcs,
testonly = testonly,
data = data,
deps = deps + _get_external_deps(external_deps),
python_version = python_version,
**kwargs
)

def grpc_package(name, visibility = "private", features = []):
Expand Down
15 changes: 8 additions & 7 deletions bazel/grpc_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ def grpc_deps():
if "bazel_toolchains" not in native.existing_rules():
http_archive(
name = "bazel_toolchains",
sha256 = "d968b414b32aa99c86977e1171645d31da2b52ac88060de3ac1e49932d5dcbf1",
strip_prefix = "bazel-toolchains-4bd5df80d77aa7f4fb943dfdfad5c9056a62fb47",
sha256 = "872955b658113924eb1a3594b04d43238da47f4f90c17b76e8785709490dc041",
strip_prefix = "bazel-toolchains-1083686fde6032378d52b4c98044922cebde364e",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/archive/4bd5df80d77aa7f4fb943dfdfad5c9056a62fb47.tar.gz",
"https://github.com/bazelbuild/bazel-toolchains/archive/4bd5df80d77aa7f4fb943dfdfad5c9056a62fb47.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/archive/1083686fde6032378d52b4c98044922cebde364e.tar.gz",
"https://github.com/bazelbuild/bazel-toolchains/archive/1083686fde6032378d52b4c98044922cebde364e.tar.gz",
],
)

Expand Down Expand Up @@ -221,10 +221,11 @@ def grpc_deps():
)

if "build_bazel_rules_apple" not in native.existing_rules():
git_repository(
http_archive(
name = "build_bazel_rules_apple",
remote = "https://github.com/bazelbuild/rules_apple.git",
tag = "0.17.2",
url = "https://github.com/bazelbuild/rules_apple/archive/b869b0d3868d78a1d4ffd866ccb304fb68aa12c3.tar.gz",
strip_prefix = "rules_apple-b869b0d3868d78a1d4ffd866ccb304fb68aa12c3",
sha256 = "bdc8e66e70b8a75da23b79f1f8c6207356df07d041d96d2189add7ee0780cf4e",
)

grpc_python_deps()
Expand Down
9 changes: 9 additions & 0 deletions bazel/grpc_python_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ def grpc_python_deps():
remote = "https://github.com/bazelbuild/rules_python.git",
)


if "rules_python" not in native.existing_rules():
http_archive(
name = "rules_python",
url = "https://github.com/bazelbuild/rules_python/archive/9d68f24659e8ce8b736590ba1e4418af06ec2552.zip",
sha256 = "f7402f11691d657161f871e11968a984e5b48b023321935f5a55d7e56cf4758a",
strip_prefix = "rules_python-9d68f24659e8ce8b736590ba1e4418af06ec2552",
)

python_configure(name = "local_config_python")

native.bind(
Expand Down
26 changes: 26 additions & 0 deletions bazel/python_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,29 @@ def py_grpc_library(
deps = [Label("//src/python/grpcio/grpc:grpcio")] + deps,
**kwargs
)


def py2and3_test(name,
py_test = native.py_test,
**kwargs):
if "python_version" in kwargs:
fail("Cannot specify 'python_version' in py2and3_test.")

names = [name + suffix for suffix in (".python2", ".python3")]
python_versions = ["PY2", "PY3"]
for case_name, python_version in zip(names, python_versions):
py_test(
name = case_name,
python_version = python_version,
**kwargs
)

suite_kwargs = {}
if "visibility" in kwargs:
suite_kwargs["visibility"] = kwargs["visibility"]

native.test_suite(
name = name,
tests = names,
**suite_kwargs
)
3 changes: 3 additions & 0 deletions examples/python/auth/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ py_binary(
"//examples:helloworld_py_pb2",
"//examples:helloworld_py_pb2_grpc",
],
python_version = "PY3",
)

py_binary(
Expand All @@ -51,6 +52,7 @@ py_binary(
"//examples:helloworld_py_pb2",
"//examples:helloworld_py_pb2_grpc",
],
python_version = "PY3",
)

py_test(
Expand All @@ -63,4 +65,5 @@ py_test(
":customized_auth_server",
":_credentials",
],
python_version = "PY3",
)
3 changes: 3 additions & 0 deletions examples/python/cancellation/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ py_binary(
"//external:six"
],
srcs_version = "PY2AND3",
python_version = "PY3",
)

py_library(
Expand All @@ -68,6 +69,7 @@ py_binary(
"//:python3": [],
}),
srcs_version = "PY2AND3",
python_version = "PY3",
)

py_test(
Expand All @@ -78,4 +80,5 @@ py_test(
":server"
],
size = "small",
python_version = "PY3",
)
3 changes: 3 additions & 0 deletions examples/python/compression/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ py_binary(
"//examples:helloworld_py_pb2_grpc",
],
srcs_version = "PY2AND3",
python_version = "PY3",
)

py_binary(
Expand All @@ -32,6 +33,7 @@ py_binary(
"//examples:helloworld_py_pb2_grpc",
],
srcs_version = "PY2AND3",
python_version = "PY3",
)

py_test(
Expand All @@ -43,4 +45,5 @@ py_test(
":server",
],
size = "small",
python_version = "PY3",
)
3 changes: 3 additions & 0 deletions examples/python/debug/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ py_binary(
"//examples:helloworld_py_pb2",
"//examples:helloworld_py_pb2_grpc",
],
python_version = "PY3",
)

py_binary(
Expand All @@ -45,6 +46,7 @@ py_binary(
"//src/python/grpcio/grpc:grpcio",
"//src/python/grpcio_channelz/grpc_channelz/v1:grpc_channelz",
],
python_version = "PY3",
)

py_test(
Expand All @@ -59,4 +61,5 @@ py_test(
":send_message",
":get_stats",
],
python_version = "PY3",
)
1 change: 1 addition & 0 deletions examples/python/errors/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ py_test(
"../../../src/python/grpcio_status",
"../../../src/python/grpcio_tests",
],
python_version = "PY3",
)
3 changes: 3 additions & 0 deletions examples/python/multiprocessing/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ py_binary(
":prime_proto_pb2_grpc",
],
srcs_version = "PY3",
python_version = "PY3",
)

py_binary(
Expand All @@ -57,6 +58,7 @@ py_binary(
"//:python3": [],
}),
srcs_version = "PY3",
python_version = "PY3",
)

py_test(
Expand All @@ -67,4 +69,5 @@ py_test(
":server"
],
size = "small",
python_version = "PY3",
)
1 change: 1 addition & 0 deletions examples/python/wait_for_ready/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ py_test(
srcs = ["test/_wait_for_ready_example_test.py"],
deps = [":wait_for_ready_example",],
size = "small",
python_version = "PY3",
)
4 changes: 3 additions & 1 deletion src/python/grpcio_tests/tests/channelz/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package(default_visibility = ["//visibility:public"])

py_test(
load("//bazel:python_rules.bzl", "py2and3_test")

py2and3_test(
name = "channelz_servicer_test",
srcs = ["_channelz_servicer_test.py"],
main = "_channelz_servicer_test.py",
Expand Down
3 changes: 2 additions & 1 deletion src/python/grpcio_tests/tests/health_check/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package(default_visibility = ["//visibility:public"])
load("//bazel:python_rules.bzl", "py2and3_test")

py_test(
py2and3_test(
name = "health_servicer_test",
srcs = ["_health_servicer_test.py"],
main = "_health_servicer_test.py",
Expand Down
5 changes: 3 additions & 2 deletions src/python/grpcio_tests/tests/interop/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@grpc_python_dependencies//:requirements.bzl", "requirement")
load("//bazel:python_rules.bzl", "py2and3_test")

package(default_visibility = ["//visibility:public"])

Expand Down Expand Up @@ -80,7 +81,7 @@ py_library(
],
)

py_test(
py2and3_test(
name = "_insecure_intraop_test",
size = "small",
srcs = ["_insecure_intraop_test.py"],
Expand All @@ -99,7 +100,7 @@ py_test(
],
)

py_test(
py2and3_test(
name = "_secure_intraop_test",
size = "small",
srcs = ["_secure_intraop_test.py"],
Expand Down
3 changes: 2 additions & 1 deletion src/python/grpcio_tests/tests/reflection/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
load("@grpc_python_dependencies//:requirements.bzl", "requirement")
load("//bazel:python_rules.bzl", "py2and3_test")

package(default_visibility = ["//visibility:public"])

py_test(
py2and3_test(
name="_reflection_servicer_test",
size="small",
timeout="moderate",
Expand Down
3 changes: 2 additions & 1 deletion src/python/grpcio_tests/tests/status/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
load("@grpc_python_dependencies//:requirements.bzl", "requirement")
load("//bazel:python_rules.bzl", "py2and3_test")

package(default_visibility = ["//visibility:public"])

py_test(
py2and3_test(
name = "grpc_status_test",
srcs = ["_grpc_status_test.py"],
main = "_grpc_status_test.py",
Expand Down
4 changes: 3 additions & 1 deletion src/python/grpcio_tests/tests/unit/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("//bazel:python_rules.bzl", "py2and3_test")

package(default_visibility = ["//visibility:public"])

GRPCIO_TESTS_UNIT = [
Expand Down Expand Up @@ -80,7 +82,7 @@ py_library(
)

[
py_test(
py2and3_test(
name=test_file_name[:-3],
size="small",
srcs=[test_file_name],
Expand Down
3 changes: 2 additions & 1 deletion src/python/grpcio_tests/tests/unit/_cython/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@grpc_python_dependencies//:requirements.bzl", "requirement")
load("//bazel:python_rules.bzl", "py2and3_test")

package(default_visibility = ["//visibility:public"])

Expand All @@ -23,7 +24,7 @@ py_library(
)

[
py_test(
py2and3_test(
name=test_file_name[:-3],
size="small",
srcs=[test_file_name],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package(default_visibility = ["//visibility:public"])
load("//bazel:python_rules.bzl", "py2and3_test")

py_library(
name = "stream_testing",
srcs = ["stream_testing.py"],
)

py_test(
py2and3_test(
name = "logging_pool_test",
srcs = ["_logging_pool_test.py"],
main = "_logging_pool_test.py",
Expand Down
2 changes: 1 addition & 1 deletion templates/tools/dockerfile/bazel.include
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Bazel installation

# Must be in sync with tools/bazel
ENV BAZEL_VERSION 0.26.0
ENV BAZEL_VERSION 0.28.1

# The correct bazel version is already preinstalled, no need to use //tools/bazel wrapper.
ENV DISABLE_BAZEL_WRAPPER 1
Expand Down