1- load ("//bzl:protoc.bzl" , "protoc_genrule " , "implement " )
1+ load ("//bzl:protoc.bzl" , "implement " , "EXECUTABLE " )
22load ("//bzl:go/class.bzl" , GO = "CLASS" )
33load ("@io_bazel_rules_go//go:def.bzl" , "go_library" )
44
@@ -7,38 +7,49 @@ go_proto_compile = implement(["go"])
77def go_proto_library (
88 name ,
99 protos ,
10+ copy_protos_to_genfiles = True ,
11+ deps = [],
12+ grpc_plugin = None ,
13+ grpc_plugin_options = [],
14+ imports = [],
1015 lang = GO ,
16+ proto_compile = go_proto_compile ,
17+ protobuf_plugin_options = [],
18+ protobuf_plugin = None ,
19+ protoc = EXECUTABLE ,
1120 srcs = [],
12- imports = [] ,
21+ verbose = 0 ,
1322 visibility = None ,
14- testonly = 0 ,
15- protoc = None ,
16- protobuf_plugin = None ,
1723 with_grpc = False ,
18- verbose = 0 ,
1924 ** kwargs ):
2025
21- result = protoc_genrule (
22- spec = [lang ],
23- name = name + "_pb" ,
24- protos = protos ,
25- protoc = protoc ,
26- protobuf_plugin = protobuf_plugin ,
27- visibility = visibility ,
28- testonly = testonly ,
29- imports = imports ,
30- with_grpc = with_grpc ,
31- verbose = verbose ,
32- )
26+ args = {}
27+ args ["name" ] = name + "_pb"
28+ args ["copy_protos_to_genfiles" ] = copy_protos_to_genfiles
29+ args ["deps" ] = deps
30+ args ["imports" ] = imports
31+ args ["gen_" + lang .name ] = True
32+ args ["gen_grpc_" + lang .name ] = with_grpc
33+ args ["gen_protobuf_" + lang .name + "_plugin" ] = protobuf_plugin
34+ args ["gen_" + lang .name + "_plugin_options" ] = protobuf_plugin_options
35+ args ["gen_grpc_" + lang .name + "_plugin" ] = grpc_plugin
36+ args ["protoc" ] = protoc
37+ args ["protos" ] = protos
38+ args ["verbose" ] = verbose
39+ args ["with_grpc" ] = with_grpc
40+
41+ proto_compile (** args )
42+
43+ if with_grpc and hasattr (lang , "grpc" ):
44+ proto_deps = [str (Label (dep )) for dep in getattr (lang .grpc , "compile_deps" , [])]
45+ elif hasattr (lang , "protobuf" ):
46+ proto_deps = [str (Label (dep )) for dep in getattr (lang .protobuf , "compile_deps" , [])]
3347
34- if with_grpc :
35- deps = [str (Label (dep )) for dep in getattr (lang .grpc , "compile_deps" , [])]
36- else :
37- deps = [str (Label (dep )) for dep in getattr (lang .protobuf , "compile_deps" , [])]
48+ go_deps = list (set (deps + proto_deps ))
3849
3950 go_library (
40- name = name ,
41- srcs = result . outs ,
42- deps = deps ,
43- ** kwargs
51+ name = name ,
52+ srcs = srcs + [ name + "_pb" ] ,
53+ deps = go_deps ,
54+ ** kwargs
4455 )
0 commit comments