@@ -29,8 +29,9 @@ def protoc_genrule(name,
2929 spec = [],
3030 self = {},
3131 #gendir = "$(BINDIR)", Note: It *has* to be GENDIR for some reason.
32- gendir = "$(GENDIR)" ,
32+ outdir = "$(GENDIR)" ,
3333 protos = [],
34+ paths = [],
3435 protoc = EXECUTABLE ,
3536 protobuf_plugin = None ,
3637 protobuf_plugin_options = [],
@@ -51,8 +52,10 @@ def protoc_genrule(name,
5152 self += {
5253 "name" : name ,
5354 "ctx" : None ,
54- "gendir" : gendir ,
55+ "gendir" : outdir ,
56+ "outdir" : outdir ,
5557 "protos" : protos ,
58+ "paths" : paths ,
5659 "protoc" : protoc ,
5760 "protobuf_plugin" : protobuf_plugin ,
5861 "protobuf_plugin_options" : protobuf_plugin_options ,
@@ -193,14 +196,21 @@ def _protoc_rule_impl(ctx):
193196 "verbose" : getattr (ctx .attr , "verbose" , True ),
194197 "with_grpc" : getattr (ctx .attr , "with_grpc" , False ),
195198 #"descriptor_set_file": descriptor_set_file,
199+ "transitive_imports" : [],
200+ "transitive_paths" : [],
201+ "transitive_packages" : {},
202+ "transitive_requires" : [],
203+ "transitive_srcs" : [],
196204 }
197205
198- # Propogate proto deps: TODO: this is completely untested.
199- for dep in ctx .attr .deps :
200- if hasattr (dep , "proto" ):
201- self ["paths" ] += dep .proto .paths
202- self ["requires" ] += dep .proto .deps
203- self ["srcs" ] += dep .proto .srcs
206+ # Propogate proto deps:
207+ for dep in ctx .attr .proto_deps :
208+ print ("ctx.attr dep: %s" % dir (dep ))
209+ self ["transitive_imports" ] += dep .proto .transitive_imports
210+ self ["transitive_paths" ] += dep .proto .transitive_paths
211+ self ["transitive_packages" ] += dep .proto .transitive_packages
212+ self ["transitive_requires" ] += dep .proto .transitive_requires
213+ self ["transitive_srcs" ] += dep .proto .transitive_srcs
204214
205215 # Copy source files over to outdir
206216 _build_source_files (ctx , self )
@@ -232,21 +242,36 @@ def _protoc_rule_impl(ctx):
232242 for lang in spec :
233243 invoke ("post_execute" , lang , self )
234244
245+ self ["packages" ] = {
246+ ctx .label .package + ':' + ctx .label .name : self ["srcs" ],
247+ }
248+
235249 return struct (
236250 files = set (self ["provides" ]),
237251 proto = struct (
238- srcs = set ( self [ "srcs" ]),
252+
239253 imports = self ["imports" ],
240254 paths = self ["paths" ],
241- deps = self ["requires" ],
255+ packages = self ["packages" ],
256+ srcs = set (self ["srcs" ]),
257+ requires = self ["requires" ],
258+
259+ transitive_requires = self ["requires" ] + self ["transitive_requires" ],
260+ transitive_imports = self ["imports" ] + self ["transitive_imports" ],
261+ transitive_paths = self ["paths" ] + self ["transitive_paths" ],
262+ transitive_packages = self ["packages" ] + self ["transitive_packages" ],
263+ transitive_srcs = self ["srcs" ] + self ["transitive_srcs" ],
242264 ),
243265 )
244266
245267
246268def implement (spec ):
247269
248270 attrs = {}
249- outputs = {}
271+
272+ outputs = {
273+ #"proto": "%{name}.proto",
274+ }
250275
251276 # Language descriptor has an opportunity to override this.
252277 output_to_genfiles = False
@@ -260,11 +285,11 @@ def implement(spec):
260285 allow_files = FileType ([".proto" ]),
261286 )
262287
263- # ? How to deps interact here? Don't understand this. Provider
264- # aspect is "proto".
265288 #attrs["deps"] = attr.label_list(providers = ["proto"])
266289 attrs ["deps" ] = attr .label_list ()
267290
291+ attrs ["proto_deps" ] = attr .label_list (providers = ["proto" ])
292+
268293 # Options to be passed to protoc as --proto_path. Differs from
269294 # imports in that these are raw strings rather than labels.
270295 attrs ["paths" ] = attr .string_list ()
@@ -365,6 +390,17 @@ def implement(spec):
365390 default = output_to_genfiles ,
366391 )
367392
393+ # Get the go_prefox
394+ attrs ["go_prefix" ] = attr .label (
395+ providers = ["go_prefix" ],
396+ default = Label (
397+ "//:go_prefix" ,
398+ relative_to_caller_repository = True ,
399+ ),
400+ allow_files = False ,
401+ cfg = HOST_CFG ,
402+ )
403+
368404 return rule (
369405 implementation = _protoc_rule_impl ,
370406 attrs = attrs ,
0 commit comments