@@ -2,48 +2,85 @@ load("//bzl:base/class.bzl", BASE = "CLASS", "build_plugin_out")
22load ("//bzl:go/class.bzl" , GO = "CLASS" )
33load ("//bzl:util.bzl" , "invokesuper" )
44
5+ # https://github.com/bazelbuild/bazel/blame/master/src/main/java/com/google/devtools/build/lib/packages/BuildType.java#L227
6+ # NPE at BuildType.java:227 when str() is used to wrap Label i.e. attr.label_list(default = [str(Label("...")])
7+
8+ def implement_compile_attributes (lang , self ):
9+ """Override attributes for the X_proto_compile rule"""
10+ GO .implement_compile_attributes (lang , self )
11+ #invokesuper("implement_compile_attributes", lang, self)
12+
13+ attrs = self ["attrs" ]
14+
15+ attrs ["_googleapi_protos" ] = attr .label (
16+ default = Label (
17+ "@com_github_grpc_ecosystem_grpc_gateway//:googleapi_protos" ,
18+ ),
19+ )
20+
21+ attrs ["logtostderr" ] = attr .bool (default = True )
22+ attrs ["alsologtostderr" ] = attr .bool ()
23+ attrs ["stderrthreshold" ] = attr .int ()
24+ attrs ["log_backtrace_at" ] = attr .int ()
25+ attrs ["log_dir" ] = attr .string ()
26+ attrs ["log_level" ] = attr .int ()
27+ # TODO:-vmodule value: what does this mean?
28+
29+ attrs ["import_prefix" ] = attr .string ()
30+
531
632def build_imports (lang , self ):
733 invokesuper ("build_imports" , lang , self )
34+
835 self ["imports" ] += [
9- "external/com_github_grpc_ecosystem_grpc_gateway/third_party/googleapis" ,
10- "external/com_github_google_protobuf/src" ,
11- "." ,
36+ "external/com_github_grpc_ecosystem_grpc_gateway/third_party/googleapis/" ,
37+ "external/com_github_google_protobuf/src/" ,
1238 ]
1339
1440def build_inputs (lang , self ):
1541 invokesuper ("build_inputs" , lang , self )
16- self ["requires" ] += [
17- "@com_github_grpc_ecosystem_grpc_gateway/third_party/googleapis" ,
18- ]
42+ ctx = self ["ctx" ]
43+ self ["requires" ] += list (ctx .attr ._googleapi_protos .files )
44+
45+
46+ def build_protobuf_out (lang , self ):
47+ # Standard protobuf outputs are implemented by the GO.class, so
48+ # there is no additional work to be done here.
49+ pass
50+
1951
2052def build_grpc_out (lang , self ):
53+ ctx = self ["ctx" ]
54+ outdir = self ["outdir" ]
2155 opts = self .get ("gateway_plugin_options" , [])
22- opts += ["logtostderr=true" ]
23- outdir = self ["gendir" ]
24- if opts :
25- outdir = "," .join (opts ) + ":" + outdir
26- self ["args" ] += ["--grpc-gateway_out=%s" % (outdir )]
56+
57+ if ctx .attr .logtostderr :
58+ opts += ["logtostderr=true" ]
59+ if ctx .attr .alsologtostderr :
60+ opts += ["alsologtostderr=true" ]
61+ if ctx .attr .log_backtrace_at :
62+ opts += ["log_backtrace_at=%s" % ctx .attr .log_backtrace_at ]
63+ if ctx .attr .stderrthreshold :
64+ opts += ["stderrthreshold=%s" % ctx .attr .stderrthreshold ]
65+ if ctx .attr .log_dir :
66+ opts += ["log_dir=%s" % ctx .attr .log_dir ]
67+ if ctx .attr .log_level :
68+ opts += ["v=%s" % ctx .attr .log_level ]
69+ if ctx .attr .import_prefix :
70+ opts += ["import_prefix=%s" % ctx .attr .import_prefix ]
71+
72+ params = "," .join (opts ) + ":" + outdir
73+
74+ self ["args" ] += ["--grpc-gateway_out=%s" % params ]
2775
2876
2977CLASS = struct (
3078 parent = BASE ,
31- name = "go" , # Left as "go" to implement gen_go and hence --protoc-gen-go=...
32- short_name = "gateway" ,
33-
34- protobuf = struct (
35- name = GO .protobuf .name ,
36- file_extensions = GO .protobuf .file_extensions ,
37- executable = GO .protobuf .executable ,
38- tools = [
39- "@com_github_grpc_ecosystem_grpc_gateway//:googleapis" ,
40- ],
41- default_options = [
42- "Mgoogle/api/annotations.proto=github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis/google/api" ,
43- ],
44- requires = GO .protobuf .requires ,
45- compile_deps = GO .protobuf .compile_deps ,
46- ),
79+ name = "gateway" ,
80+
81+ default_go_import_map = {
82+ "google/api/annotations.proto" : "github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis/google/api"
83+ },
4784
4885 grpc = struct (
4986 name = 'protoc-gen-grpc-gateway' ,
@@ -62,8 +99,11 @@ CLASS = struct(
6299 ],
63100 ),
64101
65- build_protobuf_out = GO .build_protobuf_out ,
102+ build_protobuf_out = build_protobuf_out ,
103+ implement_compile_attributes = implement_compile_attributes ,
104+
66105 build_grpc_out = build_grpc_out ,
67106 build_imports = build_imports ,
68107 build_inputs = build_inputs ,
108+
69109)
0 commit comments