blob: 6aed44a4f32d59c51f1263bb25773a30cd8f0f4a [file] [log] [blame]
Damien Martin-Guillerez76547e52016-01-15 14:01:37 +01001def _GetPath(ctx, path):
2 if ctx.label.workspace_root:
3 return ctx.label.workspace_root + '/' + path
4 else:
5 return path
6
Kristina Chodorow4e7ecde2017-01-25 14:10:56 -05007def _IsNewExternal(ctx):
8 # Bazel 0.4.4 and older have genfiles paths that look like:
9 # bazel-out/local-fastbuild/genfiles/external/repo/foo
10 # After the exec root rearrangement, they look like:
11 # ../repo/bazel-out/local-fastbuild/genfiles/foo
12 return ctx.label.workspace_root.startswith("../")
13
Jisi Liu993fb702015-10-19 17:19:49 -070014def _GenDir(ctx):
Kristina Chodorow4e7ecde2017-01-25 14:10:56 -050015 if _IsNewExternal(ctx):
16 # We are using the fact that Bazel 0.4.4+ provides repository-relative paths
17 # for ctx.genfiles_dir.
18 return ctx.genfiles_dir.path + (
19 "/" + ctx.attr.includes[0] if ctx.attr.includes and ctx.attr.includes[0] else "")
20 # This means that we're either in the old version OR the new version in the local repo.
21 # Either way, appending the source path to the genfiles dir works.
22 return ctx.var["GENDIR"] + "/" + _SourceDir(ctx)
23
24def _SourceDir(ctx):
Jisi Liu53a56be2015-10-20 15:18:20 -070025 if not ctx.attr.includes:
Damien Martin-Guillerez76547e52016-01-15 14:01:37 +010026 return ctx.label.workspace_root
Jisi Liu53a56be2015-10-20 15:18:20 -070027 if not ctx.attr.includes[0]:
Damien Martin-Guillerez76547e52016-01-15 14:01:37 +010028 return _GetPath(ctx, ctx.label.package)
Jisi Liu39362b32015-10-14 17:12:11 -070029 if not ctx.label.package:
Damien Martin-Guillerez76547e52016-01-15 14:01:37 +010030 return _GetPath(ctx, ctx.attr.includes[0])
31 return _GetPath(ctx, ctx.label.package + '/' + ctx.attr.includes[0])
Jisi Liu39362b32015-10-14 17:12:11 -070032
Andreas Bergmeierbbeb9832016-08-15 16:57:30 +020033def _CcHdrs(srcs, use_grpc_plugin=False):
34 ret = [s[:-len(".proto")] + ".pb.h" for s in srcs]
Manjunath Kudlurf5c73632016-02-25 08:50:50 -080035 if use_grpc_plugin:
Andreas Bergmeierbbeb9832016-08-15 16:57:30 +020036 ret += [s[:-len(".proto")] + ".grpc.pb.h" for s in srcs]
Manjunath Kudlurf5c73632016-02-25 08:50:50 -080037 return ret
Jisi Liu39362b32015-10-14 17:12:11 -070038
Andreas Bergmeierbbeb9832016-08-15 16:57:30 +020039def _CcSrcs(srcs, use_grpc_plugin=False):
40 ret = [s[:-len(".proto")] + ".pb.cc" for s in srcs]
41 if use_grpc_plugin:
42 ret += [s[:-len(".proto")] + ".grpc.pb.cc" for s in srcs]
43 return ret
44
45def _CcOuts(srcs, use_grpc_plugin=False):
46 return _CcHdrs(srcs, use_grpc_plugin) + _CcSrcs(srcs, use_grpc_plugin)
47
Jisi Liu993fb702015-10-19 17:19:49 -070048def _PyOuts(srcs):
Jisi Liu125a91b2015-10-14 17:37:39 -070049 return [s[:-len(".proto")] + "_pb2.py" for s in srcs]
Jisi Liu39362b32015-10-14 17:12:11 -070050
David Z. Chen02cd45c2016-05-20 16:49:04 -070051def _RelativeOutputPath(path, include, dest=""):
Jisi Liu993fb702015-10-19 17:19:49 -070052 if include == None:
53 return path
54
55 if not path.startswith(include):
56 fail("Include path %s isn't part of the path %s." % (include, path))
57
58 if include and include[-1] != '/':
59 include = include + '/'
David Z. Chen02cd45c2016-05-20 16:49:04 -070060 if dest and dest[-1] != '/':
61 dest = dest + '/'
Jisi Liu993fb702015-10-19 17:19:49 -070062
63 path = path[len(include):]
David Z. Chen02cd45c2016-05-20 16:49:04 -070064 return dest + path
Jisi Liu993fb702015-10-19 17:19:49 -070065
Jisi Liu9c7d9c02015-10-15 10:51:32 -070066def _proto_gen_impl(ctx):
67 """General implementation for generating protos"""
Jisi Liu39362b32015-10-14 17:12:11 -070068 srcs = ctx.files.srcs
69 deps = []
70 deps += ctx.files.srcs
Kristina Chodorow4e7ecde2017-01-25 14:10:56 -050071 source_dir = _SourceDir(ctx)
Jisi Liu993fb702015-10-19 17:19:49 -070072 gen_dir = _GenDir(ctx)
Kristina Chodorow4e7ecde2017-01-25 14:10:56 -050073 if source_dir:
74 import_flags = ["-I" + source_dir, "-I" + gen_dir]
Jisi Liu53a56be2015-10-20 15:18:20 -070075 else:
76 import_flags = ["-I."]
77
Jisi Liu39362b32015-10-14 17:12:11 -070078 for dep in ctx.attr.deps:
79 import_flags += dep.proto.import_flags
80 deps += dep.proto.deps
81
82 args = []
83 if ctx.attr.gen_cc:
Kristina Chodorow4e7ecde2017-01-25 14:10:56 -050084 args += ["--cpp_out=" + gen_dir]
Jisi Liu39362b32015-10-14 17:12:11 -070085 if ctx.attr.gen_py:
Kristina Chodorow4e7ecde2017-01-25 14:10:56 -050086 args += ["--python_out=" + gen_dir]
Jisi Liu39362b32015-10-14 17:12:11 -070087
Florian Weikertc2b3e702016-10-12 14:03:07 +020088 inputs = srcs + deps
Yuki Yugui Sonoda5977fb02016-06-01 16:23:15 +090089 if ctx.executable.plugin:
90 plugin = ctx.executable.plugin
91 lang = ctx.attr.plugin_language
92 if not lang and plugin.basename.startswith('protoc-gen-'):
93 lang = plugin.basename[len('protoc-gen-'):]
94 if not lang:
95 fail("cannot infer the target language of plugin", "plugin_language")
96
Kristina Chodorow4e7ecde2017-01-25 14:10:56 -050097 outdir = gen_dir
Yuki Yugui Sonoda5977fb02016-06-01 16:23:15 +090098 if ctx.attr.plugin_options:
99 outdir = ",".join(ctx.attr.plugin_options) + ":" + outdir
100 args += ["--plugin=protoc-gen-%s=%s" % (lang, plugin.path)]
101 args += ["--%s_out=%s" % (lang, outdir)]
Florian Weikertc2b3e702016-10-12 14:03:07 +0200102 inputs += [plugin]
Manjunath Kudlurf0966a72016-02-22 14:30:43 -0800103
Jisi Liu39362b32015-10-14 17:12:11 -0700104 if args:
105 ctx.action(
Florian Weikertc2b3e702016-10-12 14:03:07 +0200106 inputs=inputs,
Jisi Liu39362b32015-10-14 17:12:11 -0700107 outputs=ctx.outputs.outs,
Jisi Liu125a91b2015-10-14 17:37:39 -0700108 arguments=args + import_flags + [s.path for s in srcs],
Jisi Liu9c7d9c02015-10-15 10:51:32 -0700109 executable=ctx.executable.protoc,
Yuki Yugui Sonoda5977fb02016-06-01 16:23:15 +0900110 mnemonic="ProtoCompile",
Marco A. Harrendorfdd04ffb2017-04-03 17:01:36 +0200111 use_default_shell_env=True,
Jisi Liu39362b32015-10-14 17:12:11 -0700112 )
113
114 return struct(
115 proto=struct(
Jisi Liu125a91b2015-10-14 17:37:39 -0700116 srcs=srcs,
117 import_flags=import_flags,
118 deps=deps,
119 ),
120 )
Jisi Liu39362b32015-10-14 17:12:11 -0700121
Yuki Yugui Sonoda5977fb02016-06-01 16:23:15 +0900122proto_gen = rule(
Jisi Liu39362b32015-10-14 17:12:11 -0700123 attrs = {
Jisi Liuee8131a2015-10-14 17:20:05 -0700124 "srcs": attr.label_list(allow_files = True),
125 "deps": attr.label_list(providers = ["proto"]),
Jisi Liu53a56be2015-10-20 15:18:20 -0700126 "includes": attr.string_list(),
Jisi Liuee8131a2015-10-14 17:20:05 -0700127 "protoc": attr.label(
Vladimir Moskvaa86e6d82016-09-09 13:21:35 +0200128 cfg = "host",
Jisi Liuee8131a2015-10-14 17:20:05 -0700129 executable = True,
130 single_file = True,
131 mandatory = True,
132 ),
Yuki Yugui Sonoda5977fb02016-06-01 16:23:15 +0900133 "plugin": attr.label(
Vladimir Moskvaa86e6d82016-09-09 13:21:35 +0200134 cfg = "host",
Yuki Yugui Sonoda5977fb02016-06-01 16:23:15 +0900135 allow_files = True,
Manjunath Kudlurf0966a72016-02-22 14:30:43 -0800136 executable = True,
Manjunath Kudlurf0966a72016-02-22 14:30:43 -0800137 ),
Yuki Yugui Sonoda5977fb02016-06-01 16:23:15 +0900138 "plugin_language": attr.string(),
139 "plugin_options": attr.string_list(),
Jisi Liuee8131a2015-10-14 17:20:05 -0700140 "gen_cc": attr.bool(),
141 "gen_py": attr.bool(),
142 "outs": attr.output_list(),
143 },
144 output_to_genfiles = True,
Jisi Liu9c7d9c02015-10-15 10:51:32 -0700145 implementation = _proto_gen_impl,
Jisi Liu39362b32015-10-14 17:12:11 -0700146)
Yuki Yugui Sonoda5977fb02016-06-01 16:23:15 +0900147"""Generates codes from Protocol Buffers definitions.
148
149This rule helps you to implement Skylark macros specific to the target
150language. You should prefer more specific `cc_proto_library `,
151`py_proto_library` and others unless you are adding such wrapper macros.
152
153Args:
154 srcs: Protocol Buffers definition files (.proto) to run the protocol compiler
155 against.
156 deps: a list of dependency labels; must be other proto libraries.
157 includes: a list of include paths to .proto files.
158 protoc: the label of the protocol compiler to generate the sources.
159 plugin: the label of the protocol compiler plugin to be passed to the protocol
160 compiler.
161 plugin_language: the language of the generated sources
162 plugin_options: a list of options to be passed to the plugin
Kristina Chodorow4e7ecde2017-01-25 14:10:56 -0500163 gen_cc: generates C++ sources in addition to the ones from the plugin.
Yuki Yugui Sonoda5977fb02016-06-01 16:23:15 +0900164 gen_py: generates Python sources in addition to the ones from the plugin.
165 outs: a list of labels of the expected outputs from the protocol compiler.
166"""
Jisi Liu39362b32015-10-14 17:12:11 -0700167
168def cc_proto_library(
Jisi Liu125a91b2015-10-14 17:37:39 -0700169 name,
170 srcs=[],
Jisi Liu125a91b2015-10-14 17:37:39 -0700171 deps=[],
Jisi Liud8701b52015-10-16 11:44:21 -0700172 cc_libs=[],
Jisi Liu6dac0822015-10-19 14:41:00 -0700173 include=None,
David Z. Chen985c9682016-02-11 18:11:10 -0800174 protoc="//:protoc",
Jisi Liu3101e732015-10-16 12:46:26 -0700175 internal_bootstrap_hack=False,
Manjunath Kudlurf0966a72016-02-22 14:30:43 -0800176 use_grpc_plugin=False,
David Z. Chen985c9682016-02-11 18:11:10 -0800177 default_runtime="//:protobuf",
Jisi Liu125a91b2015-10-14 17:37:39 -0700178 **kargs):
Jisi Liu3101e732015-10-16 12:46:26 -0700179 """Bazel rule to create a C++ protobuf library from proto source files
180
Jisi Liud4bef7d2015-11-02 12:24:32 -0800181 NOTE: the rule is only an internal workaround to generate protos. The
182 interface may change and the rule may be removed when bazel has introduced
183 the native rule.
184
Jisi Liu3101e732015-10-16 12:46:26 -0700185 Args:
186 name: the name of the cc_proto_library.
187 srcs: the .proto files of the cc_proto_library.
188 deps: a list of dependency labels; must be cc_proto_library.
189 cc_libs: a list of other cc_library targets depended by the generated
190 cc_library.
191 include: a string indicating the include path of the .proto files.
192 protoc: the label of the protocol compiler to generate the sources.
193 internal_bootstrap_hack: a flag indicate the cc_proto_library is used only
194 for bootstraping. When it is set to True, no files will be generated.
195 The rule will simply be a provider for .proto files, so that other
196 cc_proto_library can depend on it.
Manjunath Kudlurf0966a72016-02-22 14:30:43 -0800197 use_grpc_plugin: a flag to indicate whether to call the grpc C++ plugin
198 when processing the proto files.
Jisi Liube92ffb2015-10-27 15:11:38 -0700199 default_runtime: the implicitly default runtime which will be depended on by
200 the generated cc_library target.
Jisi Liu3101e732015-10-16 12:46:26 -0700201 **kargs: other keyword arguments that are passed to cc_library.
202
203 """
Jisi Liu39362b32015-10-14 17:12:11 -0700204
Jisi Liu53a56be2015-10-20 15:18:20 -0700205 includes = []
206 if include != None:
207 includes = [include]
208
Jisi Liu39362b32015-10-14 17:12:11 -0700209 if internal_bootstrap_hack:
210 # For pre-checked-in generated files, we add the internal_bootstrap_hack
211 # which will skip the codegen action.
Yuki Yugui Sonoda5977fb02016-06-01 16:23:15 +0900212 proto_gen(
Jisi Liu125a91b2015-10-14 17:37:39 -0700213 name=name + "_genproto",
214 srcs=srcs,
Jisi Liud8701b52015-10-16 11:44:21 -0700215 deps=[s + "_genproto" for s in deps],
Jisi Liu53a56be2015-10-20 15:18:20 -0700216 includes=includes,
Jisi Liu125a91b2015-10-14 17:37:39 -0700217 protoc=protoc,
Martin Maly8e0c9a32015-12-04 17:44:58 -0800218 visibility=["//visibility:public"],
Jisi Liu39362b32015-10-14 17:12:11 -0700219 )
220 # An empty cc_library to make rule dependency consistent.
221 native.cc_library(
Jisi Liu125a91b2015-10-14 17:37:39 -0700222 name=name,
Jisi Liud8701b52015-10-16 11:44:21 -0700223 **kargs)
Jisi Liu39362b32015-10-14 17:12:11 -0700224 return
225
Manjunath Kudlurf0966a72016-02-22 14:30:43 -0800226 grpc_cpp_plugin = None
227 if use_grpc_plugin:
228 grpc_cpp_plugin = "//external:grpc_cpp_plugin"
229
Andreas Bergmeierbbeb9832016-08-15 16:57:30 +0200230 gen_srcs = _CcSrcs(srcs, use_grpc_plugin)
231 gen_hdrs = _CcHdrs(srcs, use_grpc_plugin)
232 outs = gen_srcs + gen_hdrs
Manjunath Kudlurf5c73632016-02-25 08:50:50 -0800233
Yuki Yugui Sonoda5977fb02016-06-01 16:23:15 +0900234 proto_gen(
Jisi Liu125a91b2015-10-14 17:37:39 -0700235 name=name + "_genproto",
236 srcs=srcs,
Jisi Liud8701b52015-10-16 11:44:21 -0700237 deps=[s + "_genproto" for s in deps],
Jisi Liu53a56be2015-10-20 15:18:20 -0700238 includes=includes,
Jisi Liu125a91b2015-10-14 17:37:39 -0700239 protoc=protoc,
Yuki Yugui Sonoda5977fb02016-06-01 16:23:15 +0900240 plugin=grpc_cpp_plugin,
241 plugin_language="grpc",
Jisi Liu125a91b2015-10-14 17:37:39 -0700242 gen_cc=1,
243 outs=outs,
Martin Maly8e0c9a32015-12-04 17:44:58 -0800244 visibility=["//visibility:public"],
Jisi Liu39362b32015-10-14 17:12:11 -0700245 )
246
Jisi Liube92ffb2015-10-27 15:11:38 -0700247 if default_runtime and not default_runtime in cc_libs:
Vladimir Moskva4fc93042017-08-07 13:33:03 +0200248 cc_libs = cc_libs + [default_runtime]
Manjunath Kudlurf5c73632016-02-25 08:50:50 -0800249 if use_grpc_plugin:
Vladimir Moskva4fc93042017-08-07 13:33:03 +0200250 cc_libs = cc_libs + ["//external:grpc_lib"]
Jisi Liu6dac0822015-10-19 14:41:00 -0700251
Jisi Liu39362b32015-10-14 17:12:11 -0700252 native.cc_library(
Jisi Liu125a91b2015-10-14 17:37:39 -0700253 name=name,
Andreas Bergmeierbbeb9832016-08-15 16:57:30 +0200254 srcs=gen_srcs,
255 hdrs=gen_hdrs,
Jisi Liud8701b52015-10-16 11:44:21 -0700256 deps=cc_libs + deps,
Jisi Liu6dac0822015-10-19 14:41:00 -0700257 includes=includes,
Jisi Liud8701b52015-10-16 11:44:21 -0700258 **kargs)
Jisi Liu993fb702015-10-19 17:19:49 -0700259
Steven Parkesea188662016-02-25 07:53:19 -0800260def internal_gen_well_known_protos_java(srcs):
261 """Bazel rule to generate the gen_well_known_protos_java genrule
262
263 Args:
264 srcs: the well known protos
265 """
266 root = Label("%s//protobuf_java" % (REPOSITORY_NAME)).workspace_root
cgrushko6fffd4a2017-02-08 12:19:40 -0500267 pkg = PACKAGE_NAME + "/" if PACKAGE_NAME else ""
Steven Parkesea188662016-02-25 07:53:19 -0800268 if root == "":
cgrushko6fffd4a2017-02-08 12:19:40 -0500269 include = " -I%ssrc " % pkg
Steven Parkesea188662016-02-25 07:53:19 -0800270 else:
cgrushko6fffd4a2017-02-08 12:19:40 -0500271 include = " -I%s/%ssrc " % (root, pkg)
Steven Parkesea188662016-02-25 07:53:19 -0800272 native.genrule(
273 name = "gen_well_known_protos_java",
274 srcs = srcs,
275 outs = [
276 "wellknown.srcjar",
277 ],
278 cmd = "$(location :protoc) --java_out=$(@D)/wellknown.jar" +
279 " %s $(SRCS) " % include +
280 " && mv $(@D)/wellknown.jar $(@D)/wellknown.srcjar",
281 tools = [":protoc"],
282 )
283
David Z. Chen02cd45c2016-05-20 16:49:04 -0700284def internal_copied_filegroup(name, srcs, strip_prefix, dest, **kwargs):
285 """Macro to copy files to a different directory and then create a filegroup.
286
287 This is used by the //:protobuf_python py_proto_library target to work around
288 an issue caused by Python source files that are part of the same Python
289 package being in separate directories.
290
291 Args:
292 srcs: The source files to copy and add to the filegroup.
293 strip_prefix: Path to the root of the files to copy.
294 dest: The directory to copy the source files into.
295 **kwargs: extra arguments that will be passesd to the filegroup.
296 """
297 outs = [_RelativeOutputPath(s, strip_prefix, dest) for s in srcs]
298
299 native.genrule(
300 name = name + "_genrule",
301 srcs = srcs,
302 outs = outs,
303 cmd = " && ".join(
304 ["cp $(location %s) $(location %s)" %
305 (s, _RelativeOutputPath(s, strip_prefix, dest)) for s in srcs]),
306 )
307
308 native.filegroup(
309 name = name,
310 srcs = outs,
311 **kwargs)
312
Jisi Liu993fb702015-10-19 17:19:49 -0700313def py_proto_library(
314 name,
315 srcs=[],
316 deps=[],
317 py_libs=[],
318 py_extra_srcs=[],
319 include=None,
David Z. Chen985c9682016-02-11 18:11:10 -0800320 default_runtime="//:protobuf_python",
321 protoc="//:protoc",
Wiktor Tomczak0fa31b22016-11-22 20:18:46 +0100322 use_grpc_plugin=False,
Jisi Liu993fb702015-10-19 17:19:49 -0700323 **kargs):
Jisi Liu7b948cc2015-10-19 17:56:27 -0700324 """Bazel rule to create a Python protobuf library from proto source files
325
Jisi Liud4bef7d2015-11-02 12:24:32 -0800326 NOTE: the rule is only an internal workaround to generate protos. The
327 interface may change and the rule may be removed when bazel has introduced
328 the native rule.
329
Jisi Liu7b948cc2015-10-19 17:56:27 -0700330 Args:
331 name: the name of the py_proto_library.
332 srcs: the .proto files of the py_proto_library.
333 deps: a list of dependency labels; must be py_proto_library.
334 py_libs: a list of other py_library targets depended by the generated
335 py_library.
336 py_extra_srcs: extra source files that will be added to the output
337 py_library. This attribute is used for internal bootstrapping.
338 include: a string indicating the include path of the .proto files.
Jisi Liube92ffb2015-10-27 15:11:38 -0700339 default_runtime: the implicitly default runtime which will be depended on by
340 the generated py_library target.
Jisi Liu7b948cc2015-10-19 17:56:27 -0700341 protoc: the label of the protocol compiler to generate the sources.
Wiktor Tomczak0fa31b22016-11-22 20:18:46 +0100342 use_grpc_plugin: a flag to indicate whether to call the Python C++ plugin
343 when processing the proto files.
Jisi Liu7b948cc2015-10-19 17:56:27 -0700344 **kargs: other keyword arguments that are passed to cc_library.
345
346 """
Jisi Liu993fb702015-10-19 17:19:49 -0700347 outs = _PyOuts(srcs)
Jisi Liu53a56be2015-10-20 15:18:20 -0700348
349 includes = []
350 if include != None:
351 includes = [include]
352
Wiktor Tomczak0fa31b22016-11-22 20:18:46 +0100353 grpc_python_plugin = None
354 if use_grpc_plugin:
355 grpc_python_plugin = "//external:grpc_python_plugin"
356 # Note: Generated grpc code depends on Python grpc module. This dependency
357 # is not explicitly listed in py_libs. Instead, host system is assumed to
358 # have grpc installed.
359
Yuki Yugui Sonoda5977fb02016-06-01 16:23:15 +0900360 proto_gen(
Jisi Liu993fb702015-10-19 17:19:49 -0700361 name=name + "_genproto",
362 srcs=srcs,
363 deps=[s + "_genproto" for s in deps],
Jisi Liu53a56be2015-10-20 15:18:20 -0700364 includes=includes,
Jisi Liu993fb702015-10-19 17:19:49 -0700365 protoc=protoc,
366 gen_py=1,
367 outs=outs,
Martin Maly8e0c9a32015-12-04 17:44:58 -0800368 visibility=["//visibility:public"],
Wiktor Tomczak0fa31b22016-11-22 20:18:46 +0100369 plugin=grpc_python_plugin,
370 plugin_language="grpc"
Jisi Liu993fb702015-10-19 17:19:49 -0700371 )
372
Jisi Liube92ffb2015-10-27 15:11:38 -0700373 if default_runtime and not default_runtime in py_libs + deps:
Vladimir Moskva4fc93042017-08-07 13:33:03 +0200374 py_libs = py_libs + [default_runtime]
Jisi Liube92ffb2015-10-27 15:11:38 -0700375
Jisi Liu993fb702015-10-19 17:19:49 -0700376 native.py_library(
377 name=name,
Jisi Liua33fa8e2015-10-20 15:30:44 -0700378 srcs=outs+py_extra_srcs,
379 deps=py_libs+deps,
David Z. Chen985c9682016-02-11 18:11:10 -0800380 imports=includes,
Jisi Liu993fb702015-10-19 17:19:49 -0700381 **kargs)
382
383def internal_protobuf_py_tests(
384 name,
385 modules=[],
386 **kargs):
Jisi Liu7b948cc2015-10-19 17:56:27 -0700387 """Bazel rules to create batch tests for protobuf internal.
388
389 Args:
390 name: the name of the rule.
391 modules: a list of modules for tests. The macro will create a py_test for
392 each of the parameter with the source "google/protobuf/%s.py"
393 kargs: extra parameters that will be passed into the py_test.
394
395 """
Jisi Liu993fb702015-10-19 17:19:49 -0700396 for m in modules:
David Z. Chen985c9682016-02-11 18:11:10 -0800397 s = "python/google/protobuf/internal/%s.py" % m
Jisi Liu993fb702015-10-19 17:19:49 -0700398 native.py_test(
399 name="py_%s" % m,
Jisi Liu7b948cc2015-10-19 17:56:27 -0700400 srcs=[s],
401 main=s,
Jisi Liu993fb702015-10-19 17:19:49 -0700402 **kargs)
Fahrzin Hemmati35119e32017-11-28 14:24:53 -0800403
404
405def check_protobuf_required_bazel_version():
406 """For WORKSPACE files, to check the installed version of bazel.
407
408 This ensures bazel supports our approach to proto_library() depending on a
409 copied filegroup. (Fixed in bazel 0.5.4)
410 """
411 expected = apple_common.dotted_version("0.5.4")
412 current = apple_common.dotted_version(native.bazel_version)
413 if current.compare_to(expected) < 0:
414 fail("Bazel must be newer than 0.5.4")