aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar apolcyn <apolcyn@google.com>2017-12-22 11:41:52 -0800
committerGravatar GitHub <noreply@github.com>2017-12-22 11:41:52 -0800
commit4233cf20c4e31cb12adafc12b2630ae5ee766a20 (patch)
treea00f04c0609700e8fdab9f228d64dc8f1da5f241
parentb04499e5f00660b5818c4a3ca2de1afaf794fee1 (diff)
parent9f01ae0052ded63a8b4907ae4ebb4b7fdb3532fe (diff)
Merge pull request #13829 from apolcyn/backport_bazel_changes
Backport bazel changes from #13468 to 1.8.x
-rw-r--r--WORKSPACE119
-rw-r--r--bazel/grpc_build_system.bzl35
-rw-r--r--bazel/grpc_deps.bzl118
-rw-r--r--third_party/BUILD6
-rw-r--r--third_party/cares/BUILD9
-rw-r--r--third_party/cares/cares.BUILD38
-rw-r--r--third_party/cares/cares_local_files.BUILD57
-rwxr-xr-xtools/run_tests/sanity/check_bazel_workspace.py76
8 files changed, 247 insertions, 211 deletions
diff --git a/WORKSPACE b/WORKSPACE
index cead0bc877..adce809162 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -1,117 +1,4 @@
-bind(
- name = "nanopb",
- actual = "//third_party/nanopb",
-)
+workspace(name = "com_github_grpc_grpc")
-bind(
- name = "libssl",
- actual = "@boringssl//:ssl",
-)
-
-bind(
- name = "zlib",
- actual = "@com_github_madler_zlib//:z",
-)
-
-bind(
- name = "protobuf",
- actual = "@com_google_protobuf//:protobuf",
-)
-
-bind(
- name = "protobuf_clib",
- actual = "@com_google_protobuf//:protoc_lib",
-)
-
-bind(
- name = "protobuf_headers",
- actual = "@com_google_protobuf//:protobuf_headers",
-)
-
-bind(
- name = "protocol_compiler",
- actual = "@com_google_protobuf//:protoc",
-)
-
-bind(
- name = "cares",
- actual = "@com_github_cares_cares//:ares",
-)
-
-bind(
- name = "gtest",
- actual = "@com_github_google_googletest//:gtest",
-)
-
-bind(
- name = "gmock",
- actual = "@com_github_google_googletest//:gmock",
-)
-
-bind(
- name = "benchmark",
- actual = "@com_github_google_benchmark//:benchmark",
-)
-
-bind(
- name = "gflags",
- actual = "@com_github_gflags_gflags//:gflags",
-)
-
-http_archive(
- name = "boringssl",
- # on the master-with-bazel branch
- url = "https://boringssl.googlesource.com/boringssl/+archive/886e7d75368e3f4fab3f4d0d3584e4abfc557755.tar.gz",
-)
-
-new_http_archive(
- name = "com_github_madler_zlib",
- build_file = "third_party/zlib.BUILD",
- strip_prefix = "zlib-cacf7f1d4e3d44d871b605da3b647f07d718623f",
- url = "https://github.com/madler/zlib/archive/cacf7f1d4e3d44d871b605da3b647f07d718623f.tar.gz",
-)
-
-http_archive(
- name = "com_google_protobuf",
- strip_prefix = "protobuf-2761122b810fe8861004ae785cc3ab39f384d342",
- url = "https://github.com/google/protobuf/archive/2761122b810fe8861004ae785cc3ab39f384d342.tar.gz",
-)
-
-new_http_archive(
- name = "com_github_google_googletest",
- build_file = "third_party/gtest.BUILD",
- strip_prefix = "googletest-ec44c6c1675c25b9827aacd08c02433cccde7780",
- url = "https://github.com/google/googletest/archive/ec44c6c1675c25b9827aacd08c02433cccde7780.tar.gz",
-)
-
-http_archive(
- name = "com_github_gflags_gflags",
- strip_prefix = "gflags-30dbc81fb5ffdc98ea9b14b1918bfe4e8779b26e",
- url = "https://github.com/gflags/gflags/archive/30dbc81fb5ffdc98ea9b14b1918bfe4e8779b26e.tar.gz",
-)
-
-new_http_archive(
- name = "com_github_google_benchmark",
- build_file = "third_party/benchmark.BUILD",
- strip_prefix = "benchmark-5b7683f49e1e9223cf9927b24f6fd3d6bd82e3f8",
- url = "https://github.com/google/benchmark/archive/5b7683f49e1e9223cf9927b24f6fd3d6bd82e3f8.tar.gz",
-)
-
-new_local_repository(
- name = "cares_local_files",
- build_file = "third_party/cares/cares_local_files.BUILD",
- path = "third_party/cares",
-)
-
-new_http_archive(
- name = "com_github_cares_cares",
- build_file = "third_party/cares/cares.BUILD",
- strip_prefix = "c-ares-3be1924221e1326df520f8498d704a5c4c8d0cce",
- url = "https://github.com/c-ares/c-ares/archive/3be1924221e1326df520f8498d704a5c4c8d0cce.tar.gz",
-)
-
-http_archive(
- name = "com_google_absl",
- strip_prefix = "abseil-cpp-cc4bed2d74f7c8717e31f9579214ab52a9c9c610",
- url = "https://github.com/abseil/abseil-cpp/archive/cc4bed2d74f7c8717e31f9579214ab52a9c9c610.tar.gz",
-)
+load("//bazel:grpc_deps.bzl", "grpc_deps")
+grpc_deps()
diff --git a/bazel/grpc_build_system.bzl b/bazel/grpc_build_system.bzl
index b35ca73745..60ae9d6502 100644
--- a/bazel/grpc_build_system.bzl
+++ b/bazel/grpc_build_system.bzl
@@ -23,6 +23,27 @@
# each change must be ported from one to the other.
#
+def _get_external_deps(external_deps):
+ ret = []
+ for dep in external_deps:
+ if dep == "nanopb":
+ ret.append("//third_party/nanopb")
+ else:
+ ret.append("//external:" + dep)
+ return ret
+
+def _maybe_update_cc_library_hdrs(hdrs):
+ ret = []
+ hdrs_to_update = {
+ "third_party/objective_c/Cronet/bidirectional_stream_c.h": "//third_party:objective_c/Cronet/bidirectional_stream_c.h",
+ }
+ for h in hdrs:
+ if h in hdrs_to_update.keys():
+ ret.append(hdrs_to_update[h])
+ else:
+ ret.append(h)
+ return ret
+
def grpc_cc_library(name, srcs = [], public_hdrs = [], hdrs = [],
external_deps = [], deps = [], standalone = False,
language = "C++", testonly = False, visibility = None,
@@ -33,12 +54,10 @@ def grpc_cc_library(name, srcs = [], public_hdrs = [], hdrs = [],
native.cc_library(
name = name,
srcs = srcs,
- defines = select({
- "//:grpc_no_ares": ["GRPC_ARES=0"],
- "//conditions:default": [],
- }),
- hdrs = hdrs + public_hdrs,
- deps = deps + ["//external:" + dep for dep in external_deps],
+ defines = select({"//:grpc_no_ares": ["GRPC_ARES=0"],
+ "//conditions:default": [],}),
+ hdrs = _maybe_update_cc_library_hdrs(hdrs + public_hdrs),
+ deps = deps + _get_external_deps(external_deps),
copts = copts,
visibility = visibility,
testonly = testonly,
@@ -79,7 +98,7 @@ def grpc_cc_test(name, srcs = [], deps = [], external_deps = [], args = [], data
srcs = srcs,
args = args,
data = data,
- deps = deps + ["//external:" + dep for dep in external_deps],
+ deps = deps + _get_external_deps(external_deps),
copts = copts,
linkopts = ["-pthread"],
)
@@ -95,7 +114,7 @@ def grpc_cc_binary(name, srcs = [], deps = [], external_deps = [], args = [], da
data = data,
testonly = testonly,
linkshared = linkshared,
- deps = deps + ["//external:" + dep for dep in external_deps],
+ deps = deps + _get_external_deps(external_deps),
copts = copts,
linkopts = ["-pthread"] + linkopts,
)
diff --git a/bazel/grpc_deps.bzl b/bazel/grpc_deps.bzl
new file mode 100644
index 0000000000..fcbef49fc1
--- /dev/null
+++ b/bazel/grpc_deps.bzl
@@ -0,0 +1,118 @@
+"""Load dependencies needed to compile and test the grpc library as a 3rd-party consumer."""
+
+def grpc_deps():
+ """Loads dependencies need to compile and test the grpc library."""
+ native.bind(
+ name = "libssl",
+ actual = "@boringssl//:ssl",
+ )
+
+ native.bind(
+ name = "zlib",
+ actual = "@com_github_madler_zlib//:z",
+ )
+
+ native.bind(
+ name = "protobuf",
+ actual = "@com_google_protobuf//:protobuf",
+ )
+
+ native.bind(
+ name = "protobuf_clib",
+ actual = "@com_google_protobuf//:protoc_lib",
+ )
+
+ native.bind(
+ name = "protobuf_headers",
+ actual = "@com_google_protobuf//:protobuf_headers",
+ )
+
+ native.bind(
+ name = "protocol_compiler",
+ actual = "@com_google_protobuf//:protoc",
+ )
+
+ native.bind(
+ name = "cares",
+ actual = "@com_github_cares_cares//:ares",
+ )
+
+ native.bind(
+ name = "gtest",
+ actual = "@com_github_google_googletest//:gtest",
+ )
+
+ native.bind(
+ name = "gmock",
+ actual = "@com_github_google_googletest//:gmock",
+ )
+
+ native.bind(
+ name = "benchmark",
+ actual = "@com_github_google_benchmark//:benchmark",
+ )
+
+ native.bind(
+ name = "gflags",
+ actual = "@com_github_gflags_gflags//:gflags",
+ )
+
+ if "boringssl" not in native.existing_rules():
+ native.http_archive(
+ name = "boringssl",
+ # on the master-with-bazel branch
+ url = "https://boringssl.googlesource.com/boringssl/+archive/886e7d75368e3f4fab3f4d0d3584e4abfc557755.tar.gz",
+ )
+
+ if "com_github_madler_zlib" not in native.existing_rules():
+ native.new_http_archive(
+ name = "com_github_madler_zlib",
+ build_file = "@com_github_grpc_grpc//third_party:zlib.BUILD",
+ strip_prefix = "zlib-cacf7f1d4e3d44d871b605da3b647f07d718623f",
+ url = "https://github.com/madler/zlib/archive/cacf7f1d4e3d44d871b605da3b647f07d718623f.tar.gz",
+ )
+
+ if "com_google_protobuf" not in native.existing_rules():
+ native.http_archive(
+ name = "com_google_protobuf",
+ strip_prefix = "protobuf-2761122b810fe8861004ae785cc3ab39f384d342",
+ url = "https://github.com/google/protobuf/archive/2761122b810fe8861004ae785cc3ab39f384d342.tar.gz",
+ )
+
+ if "com_github_google_googletest" not in native.existing_rules():
+ native.new_http_archive(
+ name = "com_github_google_googletest",
+ build_file = "@com_github_grpc_grpc//third_party:gtest.BUILD",
+ strip_prefix = "googletest-ec44c6c1675c25b9827aacd08c02433cccde7780",
+ url = "https://github.com/google/googletest/archive/ec44c6c1675c25b9827aacd08c02433cccde7780.tar.gz",
+ )
+
+ if "com_github_gflags_gflags" not in native.existing_rules():
+ native.http_archive(
+ name = "com_github_gflags_gflags",
+ strip_prefix = "gflags-30dbc81fb5ffdc98ea9b14b1918bfe4e8779b26e",
+ url = "https://github.com/gflags/gflags/archive/30dbc81fb5ffdc98ea9b14b1918bfe4e8779b26e.tar.gz",
+ )
+
+ if "com_github_google_benchmark" not in native.existing_rules():
+ native.new_http_archive(
+ name = "com_github_google_benchmark",
+ build_file = "@com_github_grpc_grpc//third_party:benchmark.BUILD",
+ strip_prefix = "benchmark-5b7683f49e1e9223cf9927b24f6fd3d6bd82e3f8",
+ url = "https://github.com/google/benchmark/archive/5b7683f49e1e9223cf9927b24f6fd3d6bd82e3f8.tar.gz",
+ )
+
+ if "com_github_cares_cares" not in native.existing_rules():
+ native.new_http_archive(
+ name = "com_github_cares_cares",
+ build_file = "@com_github_grpc_grpc//third_party:cares/cares.BUILD",
+ strip_prefix = "c-ares-3be1924221e1326df520f8498d704a5c4c8d0cce",
+ url = "https://github.com/c-ares/c-ares/archive/3be1924221e1326df520f8498d704a5c4c8d0cce.tar.gz",
+ )
+
+ if "com_google_absl" not in native.existing_rules():
+ native.http_archive(
+ name = "com_google_absl",
+ strip_prefix = "abseil-cpp-cc4bed2d74f7c8717e31f9579214ab52a9c9c610",
+ url = "https://github.com/abseil/abseil-cpp/archive/cc4bed2d74f7c8717e31f9579214ab52a9c9c610.tar.gz",
+ )
diff --git a/third_party/BUILD b/third_party/BUILD
new file mode 100644
index 0000000000..dea1229684
--- /dev/null
+++ b/third_party/BUILD
@@ -0,0 +1,6 @@
+exports_files([
+ "benchmark.BUILD",
+ "gtest.BUILD",
+ "objective_c/Cronet/bidirectional_stream_c.h",
+ "zlib.BUILD",
+])
diff --git a/third_party/cares/BUILD b/third_party/cares/BUILD
new file mode 100644
index 0000000000..ad27d93c0f
--- /dev/null
+++ b/third_party/cares/BUILD
@@ -0,0 +1,9 @@
+exports_files([
+ "ares_build.h",
+ "cares.BUILD",
+ "config_android/ares_config.h",
+ "config_darwin/ares_config.h",
+ "config_freebsd/ares_config.h",
+ "config_linux/ares_config.h",
+ "config_openbsd/ares_config.h",
+])
diff --git a/third_party/cares/cares.BUILD b/third_party/cares/cares.BUILD
index 85ca506ab0..3ac02875e6 100644
--- a/third_party/cares/cares.BUILD
+++ b/third_party/cares/cares.BUILD
@@ -35,33 +35,27 @@ config_setting(
)
genrule(
- name = "ares_build",
- srcs = ["@cares_local_files//:ares_build_h"],
+ name = "ares_build_h",
+ srcs = ["@com_github_grpc_grpc//third_party/cares:ares_build.h"],
outs = ["ares_build.h"],
- cmd = "cat $(location @cares_local_files//:ares_build_h) > $@",
+ cmd = "cat $< > $@",
)
-# cc_library(
-# name = "ares_build_h",
-# hdrs = ["ares_build.h"],
-# data = [":ares_build"],
-# includes = ["."],
-# )
-
genrule(
- name = "ares_config",
- srcs = ["@cares_local_files//:ares_config_h"],
+ name = "ares_config_h",
+ srcs = select({
+ ":ios_x86_64": ["@com_github_grpc_grpc//third_party/cares:config_darwin/ares_config.h"],
+ ":ios_armv7": ["@com_github_grpc_grpc//third_party/cares:config_darwin/ares_config.h"],
+ ":ios_armv7s": ["@com_github_grpc_grpc//third_party/cares:config_darwin/ares_config.h"],
+ ":ios_arm64": ["@com_github_grpc_grpc//third_party/cares:config_darwin/ares_config.h"],
+ ":darwin": ["@com_github_grpc_grpc//third_party/cares:config_darwin/ares_config.h"],
+ ":android": ["@com_github_grpc_grpc//third_party/cares:config_android/ares_config.h"],
+ "//conditions:default": ["@com_github_grpc_grpc//third_party/cares:config_linux/ares_config.h"],
+ }),
outs = ["ares_config.h"],
- cmd = "cat $(location @cares_local_files//:ares_config_h) > $@",
+ cmd = "cat $< > $@",
)
-# cc_library(
-# name = "ares_config_h",
-# hdrs = ["ares_config.h"],
-# data = [":ares_config"],
-# includes = ["."],
-# )
-
cc_library(
name = "ares",
srcs = [
@@ -147,10 +141,6 @@ cc_library(
"-DNOMINMAX",
"-DHAVE_CONFIG_H",
],
- data = [
- ":ares_build",
- ":ares_config",
- ],
includes = ["."],
linkstatic = 1,
visibility = [
diff --git a/third_party/cares/cares_local_files.BUILD b/third_party/cares/cares_local_files.BUILD
deleted file mode 100644
index fe59447beb..0000000000
--- a/third_party/cares/cares_local_files.BUILD
+++ /dev/null
@@ -1,57 +0,0 @@
-package(
- default_visibility = ["//visibility:public"],
-)
-
-config_setting(
- name = "darwin",
- values = {"cpu": "darwin"},
-)
-
-# Android is not officially supported through C++.
-# This just helps with the build for now.
-config_setting(
- name = "android",
- values = {
- "crosstool_top": "//external:android/crosstool",
- },
-)
-
-# iOS is not officially supported through C++.
-# This just helps with the build for now.
-config_setting(
- name = "ios_x86_64",
- values = {"cpu": "ios_x86_64"},
-)
-
-config_setting(
- name = "ios_armv7",
- values = {"cpu": "ios_armv7"},
-)
-
-config_setting(
- name = "ios_armv7s",
- values = {"cpu": "ios_armv7s"},
-)
-
-config_setting(
- name = "ios_arm64",
- values = {"cpu": "ios_arm64"},
-)
-
-filegroup(
- name = "ares_build_h",
- srcs = ["ares_build.h"],
-)
-
-filegroup(
- name = "ares_config_h",
- srcs = select({
- ":ios_x86_64": ["config_darwin/ares_config.h"],
- ":ios_armv7": ["config_darwin/ares_config.h"],
- ":ios_armv7s": ["config_darwin/ares_config.h"],
- ":ios_arm64": ["config_darwin/ares_config.h"],
- ":darwin": ["config_darwin/ares_config.h"],
- ":android": ["config_android/ares_config.h"],
- "//conditions:default": ["config_linux/ares_config.h"],
- }),
-)
diff --git a/tools/run_tests/sanity/check_bazel_workspace.py b/tools/run_tests/sanity/check_bazel_workspace.py
index 776c78b03f..c7c4e86176 100755
--- a/tools/run_tests/sanity/check_bazel_workspace.py
+++ b/tools/run_tests/sanity/check_bazel_workspace.py
@@ -30,13 +30,66 @@ git_hash_pattern = re.compile('[0-9a-f]{40}')
git_submodules = subprocess.check_output('git submodule', shell=True).strip().split('\n')
git_submodule_hashes = {re.search(git_hash_pattern, s).group() for s in git_submodules}
-# Parse git hashes from Bazel WORKSPACE {new_}http_archive rules
-with open('WORKSPACE', 'r') as f:
- workspace_rules = [expr.value for expr in ast.parse(f.read()).body]
+_GRPC_DEP_NAMES = [
+ 'boringssl',
+ 'com_github_madler_zlib',
+ 'com_google_protobuf',
+ 'com_github_google_googletest',
+ 'com_github_gflags_gflags',
+ 'com_github_google_benchmark',
+ 'com_github_cares_cares',
+ 'com_google_absl',
+]
-http_archive_rules = [rule for rule in workspace_rules if rule.func.id.endswith('http_archive')]
-archive_urls = [kw.value.s for rule in http_archive_rules for kw in rule.keywords if kw.arg == 'url']
-workspace_git_hashes = {re.search(git_hash_pattern, url).group() for url in archive_urls}
+
+class BazelEvalState(object):
+
+ def __init__(self, names_and_urls, overridden_name=None):
+ self.names_and_urls = names_and_urls
+ self.overridden_name = overridden_name
+
+ def http_archive(self, **args):
+ self.archive(**args)
+
+ def new_http_archive(self, **args):
+ self.archive(**args)
+
+ def bind(self, **args):
+ pass
+
+ def existing_rules(self):
+ if self.overridden_name:
+ return [self.overridden_name]
+ return []
+
+ def archive(self, **args):
+ self.names_and_urls[args['name']] = args['url']
+
+
+# Parse git hashes from bazel/grpc_deps.bzl {new_}http_archive rules
+with open(os.path.join('bazel', 'grpc_deps.bzl'), 'r') as f:
+ names_and_urls = {}
+ eval_state = BazelEvalState(names_and_urls)
+ bazel_file = f.read()
+
+# grpc_deps.bzl only defines 'grpc_deps', add this to call it
+bazel_file += '\ngrpc_deps()\n'
+build_rules = {
+ 'native': eval_state,
+}
+exec bazel_file in build_rules
+for name in _GRPC_DEP_NAMES:
+ assert name in names_and_urls.keys()
+assert len(_GRPC_DEP_NAMES) == len(names_and_urls.keys())
+
+archive_urls = [names_and_urls[name] for name in names_and_urls.keys()]
+workspace_git_hashes = {
+ re.search(git_hash_pattern, url).group()
+ for url in archive_urls
+}
+if len(workspace_git_hashes) == 0:
+ print("(Likely) parse error, did not find any bazel git dependencies.")
+ sys.exit(1)
# Validate the equivalence of the git submodules and Bazel git dependencies. The
# condition we impose is that there is a git submodule for every dependency in
@@ -46,4 +99,15 @@ if len(workspace_git_hashes - git_submodule_hashes) > 0:
print("Found discrepancies between git submodules and Bazel WORKSPACE dependencies")
sys.exit(1)
+# Also check that we can override each dependency
+for name in _GRPC_DEP_NAMES:
+ names_and_urls_with_overridden_name = {}
+ state = BazelEvalState(
+ names_and_urls_with_overridden_name, overridden_name=name)
+ rules = {
+ 'native': state,
+ }
+ exec bazel_file in rules
+ assert name not in names_and_urls_with_overridden_name.keys()
+
sys.exit(0)