Skip to content

Commit aa56034

Browse files
committed
Add python bazel deps needed to run resolver component tests
1 parent 86accb1 commit aa56034

10 files changed

+150
-10
lines changed

WORKSPACE

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
workspace(name = "com_github_grpc_grpc")
22

3-
load("//bazel:grpc_deps.bzl", "grpc_deps")
3+
load("//bazel:grpc_deps.bzl", "grpc_deps", "grpc_test_only_deps")
44
grpc_deps()
5+
grpc_test_only_deps()

bazel/grpc_build_system.bzl

+4-2
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,10 @@ def grpc_sh_binary(name, srcs, data = []):
165165

166166
def grpc_py_binary(name, srcs, data = [], deps = []):
167167
if name == "test_dns_server":
168-
# TODO: allow running test_dns_server in oss bazel test suite
169-
deps = []
168+
deps = _get_external_deps([
169+
"twisted",
170+
"yaml",
171+
])
170172
native.py_binary(
171173
name = name,
172174
srcs = srcs,

bazel/grpc_deps.bzl

+54
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,57 @@ def grpc_deps():
127127
],
128128
sha256 = "ed829b5eea8af1f405f4cc3d6ecfc3b1365bb7843171036030a31b5127002311",
129129
)
130+
131+
# TODO: move some dependencies from "grpc_deps" here?
132+
def grpc_test_only_deps():
133+
"""Internal, not intended for use by packages that are consuming grpc.
134+
Loads dependencies that are only needed to run grpc library's tests."""
135+
native.bind(
136+
name = "twisted",
137+
actual = "@com_github_twisted_twisted//:twisted",
138+
)
139+
140+
native.bind(
141+
name = "yaml",
142+
actual = "@com_github_yaml_pyyaml//:yaml",
143+
)
144+
145+
if "com_github_twisted_twisted" not in native.existing_rules():
146+
native.new_http_archive(
147+
name = "com_github_twisted_twisted",
148+
strip_prefix = "twisted-twisted-17.5.0",
149+
url = "https://github.com/twisted/twisted/archive/twisted-17.5.0.zip",
150+
build_file = "@com_github_grpc_grpc//third_party:twisted.BUILD",
151+
)
152+
153+
if "com_github_yaml_pyyaml" not in native.existing_rules():
154+
native.new_http_archive(
155+
name = "com_github_yaml_pyyaml",
156+
strip_prefix = "pyyaml-3.12",
157+
url = "https://github.com/yaml/pyyaml/archive/3.12.zip",
158+
build_file = "@com_github_grpc_grpc//third_party:yaml.BUILD",
159+
)
160+
161+
if "com_github_twisted_incremental" not in native.existing_rules():
162+
native.new_http_archive(
163+
name = "com_github_twisted_incremental",
164+
strip_prefix = "incremental-incremental-17.5.0",
165+
url = "https://github.com/twisted/incremental/archive/incremental-17.5.0.zip",
166+
build_file = "@com_github_grpc_grpc//third_party:incremental.BUILD",
167+
)
168+
169+
if "com_github_zopefoundation_zope_interface" not in native.existing_rules():
170+
native.new_http_archive(
171+
name = "com_github_zopefoundation_zope_interface",
172+
strip_prefix = "zope.interface-4.4.3",
173+
url = "https://github.com/zopefoundation/zope.interface/archive/4.4.3.zip",
174+
build_file = "@com_github_grpc_grpc//third_party:zope_interface.BUILD",
175+
)
176+
177+
if "com_github_twisted_constantly" not in native.existing_rules():
178+
native.new_http_archive(
179+
name = "com_github_twisted_constantly",
180+
strip_prefix = "constantly-15.1.0",
181+
url = "https://github.com/twisted/constantly/archive/15.1.0.zip",
182+
build_file = "@com_github_grpc_grpc//third_party:constantly.BUILD",
183+
)

third_party/BUILD

+5
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@ exports_files([
33
"gtest.BUILD",
44
"objective_c/Cronet/bidirectional_stream_c.h",
55
"zlib.BUILD",
6+
"twisted.BUILD",
7+
"yaml.BUILD",
8+
"incremental.BUILD",
9+
"zope_interface.BUILD",
10+
"constantly.BUILD",
611
])

third_party/constantly.BUILD

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
py_library(
2+
name = "constantly",
3+
srcs = glob(["constantly/*.py"]),
4+
visibility = [
5+
"//visibility:public",
6+
],
7+
)

third_party/incremental.BUILD

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
py_library(
2+
name = "incremental",
3+
srcs = glob(["src/incremental/*.py"]),
4+
imports = [
5+
"src",
6+
],
7+
visibility = [
8+
"//visibility:public",
9+
],
10+
)

third_party/twisted.BUILD

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
py_library(
2+
name = "twisted",
3+
srcs = glob(["src/twisted/**/*.py"]),
4+
imports = [
5+
"src",
6+
],
7+
visibility = [
8+
"//visibility:public",
9+
],
10+
deps = [
11+
"@com_github_twisted_incremental//:incremental",
12+
"@com_github_twisted_constantly//:constantly",
13+
"@com_github_zopefoundation_zope_interface//:zope_interface",
14+
],
15+
)

third_party/yaml.BUILD

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
py_library(
2+
name = "yaml",
3+
srcs = glob(["lib/yaml/*.py"]),
4+
imports = [
5+
"lib",
6+
],
7+
visibility = [
8+
"//visibility:public",
9+
],
10+
)

third_party/zope_interface.BUILD

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
py_library(
2+
name = "zope_interface",
3+
srcs = glob([
4+
"src/zope/interface/*.py",
5+
"src/zope/interface/common/*.py",
6+
]),
7+
imports = [
8+
"src",
9+
],
10+
visibility = [
11+
"//visibility:public",
12+
],
13+
)

tools/run_tests/sanity/check_bazel_workspace.py

+30-7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
}
3636

3737
_BAZEL_TOOLCHAINS_DEP_NAME = 'com_github_bazelbuild_bazeltoolchains'
38+
_TWISTED_TWISTED_DEP_NAME = 'com_github_twisted_twisted'
39+
_YAML_PYYAML_DEP_NAME = 'com_github_yaml_pyyaml'
40+
_TWISTED_INCREMENTAL_DEP_NAME = 'com_github_twisted_incremental'
41+
_ZOPEFOUNDATION_ZOPE_INTERFACE_DEP_NAME = 'com_github_zopefoundation_zope_interface'
42+
_TWISTED_CONSTANTLY_DEP_NAME = 'com_github_twisted_constantly'
3843

3944
_GRPC_DEP_NAMES = [
4045
'boringssl',
@@ -46,6 +51,20 @@
4651
'com_github_cares_cares',
4752
'com_google_absl',
4853
_BAZEL_TOOLCHAINS_DEP_NAME,
54+
_TWISTED_TWISTED_DEP_NAME,
55+
_YAML_PYYAML_DEP_NAME,
56+
_TWISTED_INCREMENTAL_DEP_NAME,
57+
_ZOPEFOUNDATION_ZOPE_INTERFACE_DEP_NAME,
58+
_TWISTED_CONSTANTLY_DEP_NAME,
59+
]
60+
61+
_GRPC_BAZEL_ONLY_DEPS = [
62+
_BAZEL_TOOLCHAINS_DEP_NAME,
63+
_TWISTED_TWISTED_DEP_NAME,
64+
_YAML_PYYAML_DEP_NAME,
65+
_TWISTED_INCREMENTAL_DEP_NAME,
66+
_ZOPEFOUNDATION_ZOPE_INTERFACE_DEP_NAME,
67+
_TWISTED_CONSTANTLY_DEP_NAME,
4968
]
5069

5170

@@ -70,7 +89,8 @@ def existing_rules(self):
7089
return []
7190

7291
def archive(self, **args):
73-
if args['name'] == _BAZEL_TOOLCHAINS_DEP_NAME:
92+
assert self.names_and_urls.get(args['name']) is None
93+
if args['name'] in _GRPC_BAZEL_ONLY_DEPS:
7494
self.names_and_urls[args['name']] = 'dont care'
7595
return
7696
self.names_and_urls[args['name']] = args['url']
@@ -82,8 +102,10 @@ def archive(self, **args):
82102
eval_state = BazelEvalState(names_and_urls)
83103
bazel_file = f.read()
84104

85-
# grpc_deps.bzl only defines 'grpc_deps', add this to call it
105+
# grpc_deps.bzl only defines 'grpc_deps' and 'grpc_test_only_deps', add these
106+
# lines to call them.
86107
bazel_file += '\ngrpc_deps()\n'
108+
bazel_file += '\ngrpc_test_only_deps()\n'
87109
build_rules = {
88110
'native': eval_state,
89111
}
@@ -92,11 +114,12 @@ def archive(self, **args):
92114
assert name in names_and_urls.keys()
93115
assert len(_GRPC_DEP_NAMES) == len(names_and_urls.keys())
94116

95-
# bazeltoolschains is an exception to this sanity check,
96-
# we don't require that there is a corresponding git module.
97-
names_without_bazeltoolchains = names_and_urls.keys()
98-
names_without_bazeltoolchains.remove(_BAZEL_TOOLCHAINS_DEP_NAME)
99-
archive_urls = [names_and_urls[name] for name in names_without_bazeltoolchains]
117+
# There are some "bazel-only" deps that are exceptions to this sanity check,
118+
# we don't require that there is a corresponding git module for these.
119+
names_without_bazel_only_deps = names_and_urls.keys()
120+
for dep_name in _GRPC_BAZEL_ONLY_DEPS:
121+
names_without_bazel_only_deps.remove(dep_name)
122+
archive_urls = [names_and_urls[name] for name in names_without_bazel_only_deps]
100123
workspace_git_hashes = {
101124
re.search(git_hash_pattern, url).group()
102125
for url in archive_urls

0 commit comments

Comments
 (0)