[bazel] Update gtest and deprecate //external:{gtest,gtest_main} (#7237)

This change updates the gtest-version used by Bazel.
Also, `//external:{gtest,gtest_main}` is deprecated so we can remove some
of the uses of the discouraged `bind` function.

RELNOTES[bazel]: Starting with Protobuf 3.13.0, building and running
Protobuf tests requires `@com_google_googletest//:{gtest,gtest_main}`
instead of `//external:{gtest,gtest_main}`. Use
`--@com_google_protobuf//:incompatible_use_com_google_googletest=true`
to verify your workspace is not affected by this change.
pull/7276/head
Yannic 5 years ago committed by GitHub
parent 398b801355
commit 2e51ad6344
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      .bazelignore
  2. 46
      BUILD
  3. 19
      WORKSPACE

@ -0,0 +1,3 @@
# These are fetched as external repositories.
third_party/benchmark
third_party/googletest

46
BUILD

@ -1,5 +1,6 @@
# Bazel (https://bazel.build/) BUILD file for Protobuf. # Bazel (https://bazel.build/) BUILD file for Protobuf.
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test", "objc_library", native_cc_proto_library = "cc_proto_library") load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test", "objc_library", native_cc_proto_library = "cc_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library") load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library")
load("@rules_proto//proto/private:native.bzl", "native_proto_common") load("@rules_proto//proto/private:native.bzl", "native_proto_common")
@ -10,6 +11,42 @@ licenses(["notice"])
exports_files(["LICENSE"]) exports_files(["LICENSE"])
################################################################################
# build configuration
################################################################################
string_flag(
name = "incompatible_use_com_google_googletest",
# TODO(yannic): Flip to `true` for `3.13.0`.
build_setting_default = "false",
values = ["true", "false"]
)
config_setting(
name = "use_com_google_googletest",
flag_values = {
"//:incompatible_use_com_google_googletest": "true"
},
)
GTEST = select({
"//:use_com_google_googletest": [
"@com_google_googletest//:gtest",
],
"//conditions:default": [
"//external:gtest",
],
})
GTEST_MAIN = select({
"//:use_com_google_googletest": [
"@com_google_googletest//:gtest_main",
],
"//conditions:default": [
"//external:gtest_main",
],
})
################################################################################ ################################################################################
# ZLIB configuration # ZLIB configuration
################################################################################ ################################################################################
@ -533,8 +570,7 @@ cc_binary(
deps = [ deps = [
":protobuf", ":protobuf",
":protoc_lib", ":protoc_lib",
"//external:gtest", ] + GTEST,
],
) )
cc_test( cc_test(
@ -546,8 +582,7 @@ cc_test(
], ],
deps = [ deps = [
":protobuf_lite", ":protobuf_lite",
"//external:gtest_main", ] + GTEST_MAIN,
],
) )
cc_test( cc_test(
@ -650,8 +685,7 @@ cc_test(
":cc_test_protos", ":cc_test_protos",
":protobuf", ":protobuf",
":protoc_lib", ":protoc_lib",
"//external:gtest_main", ] + PROTOBUF_DEPS + GTEST_MAIN,
] + PROTOBUF_DEPS,
) )
################################################################################ ################################################################################

@ -1,13 +1,20 @@
workspace(name = "com_google_protobuf") workspace(name = "com_google_protobuf")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
local_repository( local_repository(
name = "com_google_protobuf_examples", name = "com_google_protobuf_examples",
path = "examples", path = "examples",
) )
local_repository( http_archive(
name = "submodule_gmock", name = "com_google_googletest",
path = "third_party/googletest", sha256 = "9dc9157a9a1551ec7a7e43daea9a694a0bb5fb8bec81235d8a1e6ef64c716dcb",
strip_prefix = "googletest-release-1.10.0",
urls = [
"https://mirror.bazel.build/github.com/google/googletest/archive/release-1.10.0.tar.gz",
"https://github.com/google/googletest/archive/release-1.10.0.tar.gz",
],
) )
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
@ -22,14 +29,16 @@ bind(
actual = "//util/python:python_headers", actual = "//util/python:python_headers",
) )
# TODO(yannic): Remove in 3.13.0.
bind( bind(
name = "gtest", name = "gtest",
actual = "@submodule_gmock//:gtest", actual = "@com_google_googletest//:gtest",
) )
# TODO(yannic): Remove in 3.13.0.
bind( bind(
name = "gtest_main", name = "gtest_main",
actual = "@submodule_gmock//:gtest_main", actual = "@com_google_googletest//:gtest_main",
) )
jvm_maven_import_external( jvm_maven_import_external(

Loading…
Cancel
Save