11def get_generated_filename_extensions (lang , self ):
2-
3- if not hasattr (lang , "protobuf" ):
4- return
5-
6- exts = getattr (lang .protobuf , "file_extensions" , [])
7-
8- with_grpc = self .get ("with_grpc" , False )
92 ctx = self .get ("ctx" , None )
10- if ctx != None :
11- with_grpc = getattr ( ctx . attr , "gen_grpc_" + lang . name , False )
3+ with_grpc = self [ "with_grpc" ]
4+ exts = []
125
13- if with_grpc :
14- if not hasattr (lang , "grpc" ):
15- fail ("Language %s does not support gRPC" % lang .name )
16- exts += getattr (lang .grpc , "file_extensions" , [])
6+ if hasattr (lang , "protobuf" ):
7+ exts += getattr (lang .protobuf , "file_extensions" , [])
8+
9+ if with_grpc or getattr (ctx .attr , "gen_grpc_" + lang .name , False ):
10+ if hasattr (lang , "grpc" ):
11+ exts += getattr (lang .grpc , "file_extensions" , [])
1712
1813 return exts
1914
15+
2016def build_generated_files (lang , self ):
2117 """Build a list of generated filenames (used by rule)"""
2218 exts = get_generated_filename_extensions (lang , self )
2319
20+ ctx = self .get ("ctx" , None )
21+ if ctx .attr .verbose > 1 :
22+ print ("generated_file extensions for language %s: %s" % (lang .name , exts ))
23+
2424 if not exts :
2525 return
2626
27- ctx = self .get ("ctx" , None )
2827 if ctx == None :
2928 fail ("build_generated_files can only be used in bazel context" )
3029
@@ -39,26 +38,12 @@ def build_generated_files(lang, self):
3938 self ["provides" ] += [pbfile ]
4039
4140
42- def build_generated_filenames (lang , self ):
43- """Build a list of generated filenames (used by genrule)"""
44- exts = get_generated_filename_extensions (lang , self )
45-
46- protos = self .get ("protos" , [])
47- if not protos :
48- fail ("Empty proto filename input list." )
49-
50- for srcfile in protos :
51- if not srcfile .endswith ('.proto' ):
52- fail ("Non .proto source file: %s" % srcfile , "protos" )
53- for ext in exts :
54- self ["outs" ] += [srcfile .rsplit ('.' , 1 )[0 ] + ext ]
55-
56-
5741def build_imports (lang , self ):
5842 """Build the list of imports"""
5943 ctx = self ["ctx" ]
6044 self ["imports" ] = self .get ("imports" , []) + ctx .attr .imports
6145
46+
6247def build_plugin_out (name , key , lang , self ):
6348 #print("build_plugin_out(%s, %s)" % (name, key))
6449 if not hasattr (lang , key ):
@@ -142,30 +127,6 @@ def build_inputs(lang, self):
142127 self ["requires" ] += self ["srcs" ]
143128
144129
145- def build_tools (lang , self ):
146- """Build a list of tools required for genrule execution"""
147-
148- self ["tools" ] += [self ["protoc" ]]
149-
150- protobuf_plugin = self ["protobuf_plugin" ]
151- if not protobuf_plugin :
152- if hasattr (lang , "protobuf" ) and hasattr (lang .protobuf , "executable" ):
153- protobuf_plugin = lang .protobuf .executable
154-
155- if protobuf_plugin :
156- self ["tools" ] += [protobuf_plugin ]
157-
158- grpc_plugin = self ["grpc_plugin" ]
159- if self ["with_grpc" ] and not grpc_plugin :
160- if hasattr (lang , "grpc" ) and hasattr (lang .grpc , "executable" ):
161- grpc_plugin = lang .grpc .executable
162-
163- if grpc_plugin :
164- self ["tools" ] += [grpc_plugin ]
165-
166- #print("tools: %s" % self["tools"])
167-
168-
169130def post_execute (lang , self ):
170131 """No default post-execute actions"""
171132 pass
@@ -236,10 +197,8 @@ CLASS = struct(
236197 ),
237198
238199 build_generated_files = build_generated_files ,
239- build_generated_filenames = build_generated_filenames ,
240200 build_imports = build_imports ,
241201 build_inputs = build_inputs ,
242- build_tools = build_tools ,
243202 build_protobuf_invocation = build_protobuf_invocation ,
244203 build_protobuf_out = build_protobuf_out ,
245204 build_grpc_out = build_grpc_out ,
0 commit comments