Skip to content

Commit 46b7332

Browse files
committed
revert grpc-gateway to genrule
1 parent 073fa95 commit 46b7332

File tree

5 files changed

+76
-67
lines changed

5 files changed

+76
-67
lines changed

bzl/base/class.bzl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ def build_protoc_command(lang, self):
138138
self["cmd"] += ["$(location " + proto + ")" for proto in self["protos"]]
139139

140140

141+
def build_inputs(lang, self):
142+
"""Build a list of inputs to the ctx.action protoc"""
143+
#self["inputs"] += self["srcs"]
144+
self["requires"] += self["srcs"]
145+
146+
141147
def build_tools(lang, self):
142148
"""Build a list of tools required for genrule execution"""
143149

@@ -181,6 +187,7 @@ CLASS = struct(
181187
build_generated_files = build_generated_files,
182188
build_generated_filenames = build_generated_filenames,
183189
build_imports = build_imports,
190+
build_inputs = build_inputs,
184191
build_tools = build_tools,
185192
build_protobuf_invocation = build_protobuf_invocation,
186193
build_protobuf_out = build_protobuf_out,

bzl/grpc_gateway/class.bzl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ load("//bzl:go/class.bzl", GO = "CLASS")
33
load("//bzl:util.bzl", "invokesuper")
44

55

6-
def build_protobuf_out(lang, self):
7-
"""Build the --{lang}_out option"""
8-
build_plugin_out(lang.name, "protobuf", lang, self)
9-
10-
116
def build_imports(lang, self):
127
invokesuper("build_imports", lang, self)
138
self["imports"] += [
@@ -16,6 +11,12 @@ def build_imports(lang, self):
1611
".",
1712
]
1813

14+
def build_inputs(lang, self):
15+
invokesuper("build_inputs", lang, self)
16+
self["requires"] += [
17+
"@com_github_grpc_ecosystem_grpc_gateway/third_party/googleapis",
18+
]
19+
1920
def build_grpc_out(lang, self):
2021
opts = self.get("gateway_plugin_options", [])
2122
opts += ["logtostderr=true"]
@@ -64,4 +65,5 @@ CLASS = struct(
6465
build_protobuf_out = GO.build_protobuf_out,
6566
build_grpc_out = build_grpc_out,
6667
build_imports = build_imports,
68+
build_inputs = build_inputs,
6769
)

bzl/grpc_gateway/rules.bzl

Lines changed: 59 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,88 @@
1-
load("//bzl:protoc.bzl", "EXECUTABLE", "implement")
1+
load("//bzl:protoc.bzl", "EXECUTABLE", "implement", "protoc_genrule")
22
load("//bzl:grpc_gateway/class.bzl", GRPC_GATEWAY = "CLASS")
33
load("@io_bazel_rules_go//go:def.bzl", "go_library")
44

5-
grpc_gateway_proto_compile = implement(["go", "gateway"])
5+
grpc_gateway_proto_compile = implement(["gateway"])
66

77
def grpc_gateway_proto_library(
88
name,
99
protos,
10-
copy_protos_to_genfiles = True,
11-
deps = [],
12-
grpc_plugin = None,
13-
grpc_plugin_options = [],
14-
imports = [],
1510
lang = GRPC_GATEWAY,
16-
proto_compile = grpc_gateway_proto_compile,
17-
protobuf_plugin_options = [],
18-
protobuf_plugin = None,
19-
protoc = EXECUTABLE,
2011
srcs = [],
21-
verbose = 0,
12+
imports = [],
2213
visibility = None,
14+
testonly = 0,
15+
protoc = None,
16+
protobuf_plugin = None,
17+
verbose = 0,
2318
**kwargs):
2419

25-
args = {}
26-
args["name"] = name + "_pb_gw"
27-
args["copy_protos_to_genfiles"] = copy_protos_to_genfiles
28-
args["deps"] = deps
29-
args["imports"] = imports
30-
args["gen_grpc_gateway"] = True
31-
args["gen_protobuf_go_plugin"] = protobuf_plugin
32-
args["gen_go_plugin_options"] = protobuf_plugin_options
33-
#args["gen_grpc_" + lang.name + "_plugin"] = grpc_plugin
34-
args["protoc"] = protoc
35-
args["protos"] = protos
36-
args["verbose"] = verbose
37-
args["with_grpc"] = True
38-
39-
proto_compile(**args)
40-
41-
proto_deps = [str(Label(dep)) for dep in getattr(lang.grpc, "compile_deps", [])]
20+
result = protoc_genrule(
21+
spec = [lang],
22+
name = name + "_pb_gw",
23+
protos = protos,
24+
protoc = protoc,
25+
protobuf_plugin = protobuf_plugin,
26+
visibility = visibility,
27+
testonly = testonly,
28+
imports = imports,
29+
with_grpc = True,
30+
verbose = verbose,
31+
)
4232

43-
grpc_gateway_deps = list(set(deps + proto_deps))
33+
deps = [str(Label(dep)) for dep in getattr(lang.grpc, "compile_deps", [])]
4434

4535
go_library(
46-
name = name,
47-
srcs = srcs + [name + "_pb_gw"],
48-
deps = grpc_gateway_deps,
49-
**kwargs
36+
name = name,
37+
srcs = result.outs,
38+
deps = deps,
39+
**kwargs
5040
)
5141

52-
# grpc_gateway_proto_compile = implement(["grpc_gateway"])
5342

54-
# def grpc_gateway_proto_library(
43+
# Not working yet as a rule...
44+
#
45+
# def grpc_gateway_proto_library_rule(
5546
# name,
5647
# protos,
57-
# lang = GRPC_GATEWAY,
58-
# srcs = [],
48+
# copy_protos_to_genfiles = True,
49+
# deps = [],
50+
# grpc_plugin = None,
51+
# grpc_plugin_options = [],
5952
# imports = [],
60-
# visibility = None,
61-
# testonly = 0,
62-
# protoc = None,
53+
# lang = GRPC_GATEWAY,
54+
# proto_compile = grpc_gateway_proto_compile,
55+
# protobuf_plugin_options = [],
6356
# protobuf_plugin = None,
57+
# protoc = EXECUTABLE,
58+
# srcs = [],
6459
# verbose = 0,
60+
# visibility = None,
6561
# **kwargs):
6662

67-
# result = protoc_genrule(
68-
# spec = [lang],
69-
# name = name + "_pb_gw",
70-
# protos = protos,
71-
# protoc = protoc,
72-
# protobuf_plugin = protobuf_plugin,
73-
# visibility = visibility,
74-
# testonly = testonly,
75-
# imports = imports,
76-
# with_grpc = True,
77-
# verbose = verbose,
78-
# )
63+
# args = {}
64+
# args["name"] = name + "_pb_gw"
65+
# args["copy_protos_to_genfiles"] = copy_protos_to_genfiles
66+
# args["deps"] = deps
67+
# args["imports"] = imports
68+
# args["gen_grpc_gateway"] = True
69+
# args["gen_protobuf_go_plugin"] = protobuf_plugin
70+
# args["gen_go_plugin_options"] = protobuf_plugin_options
71+
# #args["gen_grpc_" + lang.name + "_plugin"] = grpc_plugin
72+
# args["protoc"] = protoc
73+
# args["protos"] = protos
74+
# args["verbose"] = verbose
75+
# args["with_grpc"] = True
76+
77+
# proto_compile(**args)
78+
79+
# proto_deps = [str(Label(dep)) for dep in getattr(lang.grpc, "compile_deps", [])]
7980

80-
# deps = [str(Label(dep)) for dep in getattr(lang.grpc, "compile_deps", [])]
81+
# grpc_gateway_deps = list(set(deps + proto_deps))
8182

8283
# go_library(
83-
# name = name,
84-
# srcs = result.outs,
85-
# deps = deps,
86-
# **kwargs
84+
# name = name,
85+
# srcs = srcs + [name + "_pb_gw"],
86+
# deps = grpc_gateway_deps,
87+
# **kwargs
8788
# )

bzl/protoc.bzl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ def _execute_rule(self):
116116
if ctx == None:
117117
fail("Bazel context required for rule execution")
118118

119-
self["requires"] += self["srcs"]
120-
121119
srcfiles = []
122120
for src in self["srcs"]:
123121
srcfiles += [src.path]
@@ -190,7 +188,7 @@ def _protoc_rule_impl(ctx):
190188
#"descriptor_set_file": descriptor_set_file,
191189
}
192190

193-
# Propogate proto deps
191+
# Propogate proto deps: TODO: this is completely untested.
194192
for dep in ctx.attr.deps:
195193
self["imports"] += dep.proto.imports
196194
self["requires"] += dep.proto.deps
@@ -211,12 +209,12 @@ def _protoc_rule_impl(ctx):
211209

212210
invoke("build_generated_files", lang, self)
213211
invoke("build_imports", lang, self)
214-
#invoke("build_tools", lang, self)
215212
invoke("build_protobuf_invocation", lang, self)
216213
invoke("build_protobuf_out", lang, self)
217214
if self["with_grpc"]:
218215
invoke("build_grpc_invocation", lang, self)
219216
invoke("build_grpc_out", lang, self)
217+
invoke("build_inputs", lang, self)
220218

221219
# Run protoc
222220
_execute_rule(self)

examples/helloworld/cpp/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ load("//bzl:cpp/class.bzl", CPP = "CLASS")
55

66
cc_test(
77
name = "test",
8+
size = "small",
89
srcs = ["greeter_client_test.cc"],
910
copts = ["-Iexternal/gtest/include"],
1011
deps = [

0 commit comments

Comments
 (0)