Jisi Liu | 39362b3 | 2015-10-14 17:12:11 -0700 | [diff] [blame] | 1 | # -*- mode: python; -*- PYTHON-PREPROCESSING-REQUIRED |
| 2 | |
Damien Martin-Guillerez | 76547e5 | 2016-01-15 14:01:37 +0100 | [diff] [blame] | 3 | def _GetPath(ctx, path): |
| 4 | if ctx.label.workspace_root: |
| 5 | return ctx.label.workspace_root + '/' + path |
| 6 | else: |
| 7 | return path |
| 8 | |
Jisi Liu | 993fb70 | 2015-10-19 17:19:49 -0700 | [diff] [blame] | 9 | def _GenDir(ctx): |
Jisi Liu | 53a56be | 2015-10-20 15:18:20 -0700 | [diff] [blame] | 10 | if not ctx.attr.includes: |
Damien Martin-Guillerez | 76547e5 | 2016-01-15 14:01:37 +0100 | [diff] [blame] | 11 | return ctx.label.workspace_root |
Jisi Liu | 53a56be | 2015-10-20 15:18:20 -0700 | [diff] [blame] | 12 | if not ctx.attr.includes[0]: |
Damien Martin-Guillerez | 76547e5 | 2016-01-15 14:01:37 +0100 | [diff] [blame] | 13 | return _GetPath(ctx, ctx.label.package) |
Jisi Liu | 39362b3 | 2015-10-14 17:12:11 -0700 | [diff] [blame] | 14 | if not ctx.label.package: |
Damien Martin-Guillerez | 76547e5 | 2016-01-15 14:01:37 +0100 | [diff] [blame] | 15 | return _GetPath(ctx, ctx.attr.includes[0]) |
| 16 | return _GetPath(ctx, ctx.label.package + '/' + ctx.attr.includes[0]) |
Jisi Liu | 39362b3 | 2015-10-14 17:12:11 -0700 | [diff] [blame] | 17 | |
Manjunath Kudlur | f5c7363 | 2016-02-25 08:50:50 -0800 | [diff] [blame^] | 18 | def _CcOuts(srcs, use_grpc_plugin=False): |
| 19 | ret = [s[:-len(".proto")] + ".pb.h" for s in srcs] + \ |
| 20 | [s[:-len(".proto")] + ".pb.cc" for s in srcs] |
| 21 | if use_grpc_plugin: |
| 22 | ret += [s[:-len(".proto")] + ".grpc.pb.h" for s in srcs] + \ |
| 23 | [s[:-len(".proto")] + ".grpc.pb.cc" for s in srcs] |
| 24 | return ret |
Jisi Liu | 39362b3 | 2015-10-14 17:12:11 -0700 | [diff] [blame] | 25 | |
Jisi Liu | 993fb70 | 2015-10-19 17:19:49 -0700 | [diff] [blame] | 26 | def _PyOuts(srcs): |
Jisi Liu | 125a91b | 2015-10-14 17:37:39 -0700 | [diff] [blame] | 27 | return [s[:-len(".proto")] + "_pb2.py" for s in srcs] |
Jisi Liu | 39362b3 | 2015-10-14 17:12:11 -0700 | [diff] [blame] | 28 | |
Jisi Liu | 993fb70 | 2015-10-19 17:19:49 -0700 | [diff] [blame] | 29 | def _RelativeOutputPath(path, include): |
| 30 | if include == None: |
| 31 | return path |
| 32 | |
| 33 | if not path.startswith(include): |
| 34 | fail("Include path %s isn't part of the path %s." % (include, path)) |
| 35 | |
| 36 | if include and include[-1] != '/': |
| 37 | include = include + '/' |
| 38 | |
| 39 | path = path[len(include):] |
| 40 | |
| 41 | if not path.startswith(PACKAGE_NAME): |
| 42 | fail("The package %s is not within the path %s" % (PACKAGE_NAME, path)) |
| 43 | |
| 44 | if not PACKAGE_NAME: |
| 45 | return path |
| 46 | |
| 47 | return path[len(PACKAGE_NAME)+1:] |
| 48 | |
Jisi Liu | 9c7d9c0 | 2015-10-15 10:51:32 -0700 | [diff] [blame] | 49 | def _proto_gen_impl(ctx): |
| 50 | """General implementation for generating protos""" |
Jisi Liu | 39362b3 | 2015-10-14 17:12:11 -0700 | [diff] [blame] | 51 | srcs = ctx.files.srcs |
| 52 | deps = [] |
| 53 | deps += ctx.files.srcs |
Jisi Liu | 993fb70 | 2015-10-19 17:19:49 -0700 | [diff] [blame] | 54 | gen_dir = _GenDir(ctx) |
Jisi Liu | 53a56be | 2015-10-20 15:18:20 -0700 | [diff] [blame] | 55 | if gen_dir: |
| 56 | import_flags = ["-I" + gen_dir] |
| 57 | else: |
| 58 | import_flags = ["-I."] |
| 59 | |
Jisi Liu | 39362b3 | 2015-10-14 17:12:11 -0700 | [diff] [blame] | 60 | for dep in ctx.attr.deps: |
| 61 | import_flags += dep.proto.import_flags |
| 62 | deps += dep.proto.deps |
| 63 | |
| 64 | args = [] |
| 65 | if ctx.attr.gen_cc: |
| 66 | args += ["--cpp_out=" + ctx.var["GENDIR"] + "/" + gen_dir] |
| 67 | if ctx.attr.gen_py: |
| 68 | args += ["--python_out=" + ctx.var["GENDIR"] + "/" + gen_dir] |
| 69 | |
Manjunath Kudlur | f0966a7 | 2016-02-22 14:30:43 -0800 | [diff] [blame] | 70 | if ctx.executable.grpc_cpp_plugin: |
| 71 | args += ["--plugin=protoc-gen-grpc=" + ctx.executable.grpc_cpp_plugin.path] |
| 72 | args += ["--grpc_out=" + ctx.var["GENDIR"] + "/" + gen_dir] |
| 73 | |
Jisi Liu | 39362b3 | 2015-10-14 17:12:11 -0700 | [diff] [blame] | 74 | if args: |
| 75 | ctx.action( |
Jisi Liu | 125a91b | 2015-10-14 17:37:39 -0700 | [diff] [blame] | 76 | inputs=srcs + deps, |
Jisi Liu | 39362b3 | 2015-10-14 17:12:11 -0700 | [diff] [blame] | 77 | outputs=ctx.outputs.outs, |
Jisi Liu | 125a91b | 2015-10-14 17:37:39 -0700 | [diff] [blame] | 78 | arguments=args + import_flags + [s.path for s in srcs], |
Jisi Liu | 9c7d9c0 | 2015-10-15 10:51:32 -0700 | [diff] [blame] | 79 | executable=ctx.executable.protoc, |
Jisi Liu | 39362b3 | 2015-10-14 17:12:11 -0700 | [diff] [blame] | 80 | ) |
| 81 | |
| 82 | return struct( |
| 83 | proto=struct( |
Jisi Liu | 125a91b | 2015-10-14 17:37:39 -0700 | [diff] [blame] | 84 | srcs=srcs, |
| 85 | import_flags=import_flags, |
| 86 | deps=deps, |
| 87 | ), |
| 88 | ) |
Jisi Liu | 39362b3 | 2015-10-14 17:12:11 -0700 | [diff] [blame] | 89 | |
Jisi Liu | 9c7d9c0 | 2015-10-15 10:51:32 -0700 | [diff] [blame] | 90 | _proto_gen = rule( |
Jisi Liu | 39362b3 | 2015-10-14 17:12:11 -0700 | [diff] [blame] | 91 | attrs = { |
Jisi Liu | ee8131a | 2015-10-14 17:20:05 -0700 | [diff] [blame] | 92 | "srcs": attr.label_list(allow_files = True), |
| 93 | "deps": attr.label_list(providers = ["proto"]), |
Jisi Liu | 53a56be | 2015-10-20 15:18:20 -0700 | [diff] [blame] | 94 | "includes": attr.string_list(), |
Jisi Liu | ee8131a | 2015-10-14 17:20:05 -0700 | [diff] [blame] | 95 | "protoc": attr.label( |
Andrew Harp | 38f131f | 2015-11-03 16:39:32 -0500 | [diff] [blame] | 96 | cfg = HOST_CFG, |
Jisi Liu | ee8131a | 2015-10-14 17:20:05 -0700 | [diff] [blame] | 97 | executable = True, |
| 98 | single_file = True, |
| 99 | mandatory = True, |
| 100 | ), |
Manjunath Kudlur | f0966a7 | 2016-02-22 14:30:43 -0800 | [diff] [blame] | 101 | "grpc_cpp_plugin": attr.label( |
| 102 | cfg = HOST_CFG, |
| 103 | executable = True, |
| 104 | single_file = True, |
| 105 | ), |
Jisi Liu | ee8131a | 2015-10-14 17:20:05 -0700 | [diff] [blame] | 106 | "gen_cc": attr.bool(), |
| 107 | "gen_py": attr.bool(), |
| 108 | "outs": attr.output_list(), |
| 109 | }, |
| 110 | output_to_genfiles = True, |
Jisi Liu | 9c7d9c0 | 2015-10-15 10:51:32 -0700 | [diff] [blame] | 111 | implementation = _proto_gen_impl, |
Jisi Liu | 39362b3 | 2015-10-14 17:12:11 -0700 | [diff] [blame] | 112 | ) |
| 113 | |
| 114 | def cc_proto_library( |
Jisi Liu | 125a91b | 2015-10-14 17:37:39 -0700 | [diff] [blame] | 115 | name, |
| 116 | srcs=[], |
Jisi Liu | 125a91b | 2015-10-14 17:37:39 -0700 | [diff] [blame] | 117 | deps=[], |
Jisi Liu | d8701b5 | 2015-10-16 11:44:21 -0700 | [diff] [blame] | 118 | cc_libs=[], |
Jisi Liu | 6dac082 | 2015-10-19 14:41:00 -0700 | [diff] [blame] | 119 | include=None, |
Jisi Liu | 04658a3 | 2015-10-20 15:00:13 -0700 | [diff] [blame] | 120 | protoc="//google/protobuf:protoc", |
Jisi Liu | 3101e73 | 2015-10-16 12:46:26 -0700 | [diff] [blame] | 121 | internal_bootstrap_hack=False, |
Manjunath Kudlur | f0966a7 | 2016-02-22 14:30:43 -0800 | [diff] [blame] | 122 | use_grpc_plugin=False, |
Jisi Liu | be92ffb | 2015-10-27 15:11:38 -0700 | [diff] [blame] | 123 | default_runtime="//google/protobuf:protobuf", |
Jisi Liu | 125a91b | 2015-10-14 17:37:39 -0700 | [diff] [blame] | 124 | **kargs): |
Jisi Liu | 3101e73 | 2015-10-16 12:46:26 -0700 | [diff] [blame] | 125 | """Bazel rule to create a C++ protobuf library from proto source files |
| 126 | |
Jisi Liu | d4bef7d | 2015-11-02 12:24:32 -0800 | [diff] [blame] | 127 | NOTE: the rule is only an internal workaround to generate protos. The |
| 128 | interface may change and the rule may be removed when bazel has introduced |
| 129 | the native rule. |
| 130 | |
Jisi Liu | 3101e73 | 2015-10-16 12:46:26 -0700 | [diff] [blame] | 131 | Args: |
| 132 | name: the name of the cc_proto_library. |
| 133 | srcs: the .proto files of the cc_proto_library. |
| 134 | deps: a list of dependency labels; must be cc_proto_library. |
| 135 | cc_libs: a list of other cc_library targets depended by the generated |
| 136 | cc_library. |
| 137 | include: a string indicating the include path of the .proto files. |
| 138 | protoc: the label of the protocol compiler to generate the sources. |
| 139 | internal_bootstrap_hack: a flag indicate the cc_proto_library is used only |
| 140 | for bootstraping. When it is set to True, no files will be generated. |
| 141 | The rule will simply be a provider for .proto files, so that other |
| 142 | cc_proto_library can depend on it. |
Manjunath Kudlur | f0966a7 | 2016-02-22 14:30:43 -0800 | [diff] [blame] | 143 | use_grpc_plugin: a flag to indicate whether to call the grpc C++ plugin |
| 144 | when processing the proto files. |
Jisi Liu | be92ffb | 2015-10-27 15:11:38 -0700 | [diff] [blame] | 145 | default_runtime: the implicitly default runtime which will be depended on by |
| 146 | the generated cc_library target. |
Jisi Liu | 3101e73 | 2015-10-16 12:46:26 -0700 | [diff] [blame] | 147 | **kargs: other keyword arguments that are passed to cc_library. |
| 148 | |
| 149 | """ |
Jisi Liu | 39362b3 | 2015-10-14 17:12:11 -0700 | [diff] [blame] | 150 | |
Jisi Liu | 53a56be | 2015-10-20 15:18:20 -0700 | [diff] [blame] | 151 | includes = [] |
| 152 | if include != None: |
| 153 | includes = [include] |
| 154 | |
Jisi Liu | 39362b3 | 2015-10-14 17:12:11 -0700 | [diff] [blame] | 155 | if internal_bootstrap_hack: |
| 156 | # For pre-checked-in generated files, we add the internal_bootstrap_hack |
| 157 | # which will skip the codegen action. |
Jisi Liu | 9c7d9c0 | 2015-10-15 10:51:32 -0700 | [diff] [blame] | 158 | _proto_gen( |
Jisi Liu | 125a91b | 2015-10-14 17:37:39 -0700 | [diff] [blame] | 159 | name=name + "_genproto", |
| 160 | srcs=srcs, |
Jisi Liu | d8701b5 | 2015-10-16 11:44:21 -0700 | [diff] [blame] | 161 | deps=[s + "_genproto" for s in deps], |
Jisi Liu | 53a56be | 2015-10-20 15:18:20 -0700 | [diff] [blame] | 162 | includes=includes, |
Jisi Liu | 125a91b | 2015-10-14 17:37:39 -0700 | [diff] [blame] | 163 | protoc=protoc, |
Martin Maly | 8e0c9a3 | 2015-12-04 17:44:58 -0800 | [diff] [blame] | 164 | visibility=["//visibility:public"], |
Jisi Liu | 39362b3 | 2015-10-14 17:12:11 -0700 | [diff] [blame] | 165 | ) |
| 166 | # An empty cc_library to make rule dependency consistent. |
| 167 | native.cc_library( |
Jisi Liu | 125a91b | 2015-10-14 17:37:39 -0700 | [diff] [blame] | 168 | name=name, |
Jisi Liu | d8701b5 | 2015-10-16 11:44:21 -0700 | [diff] [blame] | 169 | **kargs) |
Jisi Liu | 39362b3 | 2015-10-14 17:12:11 -0700 | [diff] [blame] | 170 | return |
| 171 | |
Manjunath Kudlur | f0966a7 | 2016-02-22 14:30:43 -0800 | [diff] [blame] | 172 | grpc_cpp_plugin = None |
| 173 | if use_grpc_plugin: |
| 174 | grpc_cpp_plugin = "//external:grpc_cpp_plugin" |
| 175 | |
Manjunath Kudlur | f5c7363 | 2016-02-25 08:50:50 -0800 | [diff] [blame^] | 176 | outs = _CcOuts(srcs, use_grpc_plugin) |
| 177 | |
Jisi Liu | 9c7d9c0 | 2015-10-15 10:51:32 -0700 | [diff] [blame] | 178 | _proto_gen( |
Jisi Liu | 125a91b | 2015-10-14 17:37:39 -0700 | [diff] [blame] | 179 | name=name + "_genproto", |
| 180 | srcs=srcs, |
Jisi Liu | d8701b5 | 2015-10-16 11:44:21 -0700 | [diff] [blame] | 181 | deps=[s + "_genproto" for s in deps], |
Jisi Liu | 53a56be | 2015-10-20 15:18:20 -0700 | [diff] [blame] | 182 | includes=includes, |
Jisi Liu | 125a91b | 2015-10-14 17:37:39 -0700 | [diff] [blame] | 183 | protoc=protoc, |
Manjunath Kudlur | f0966a7 | 2016-02-22 14:30:43 -0800 | [diff] [blame] | 184 | grpc_cpp_plugin=grpc_cpp_plugin, |
Jisi Liu | 125a91b | 2015-10-14 17:37:39 -0700 | [diff] [blame] | 185 | gen_cc=1, |
| 186 | outs=outs, |
Martin Maly | 8e0c9a3 | 2015-12-04 17:44:58 -0800 | [diff] [blame] | 187 | visibility=["//visibility:public"], |
Jisi Liu | 39362b3 | 2015-10-14 17:12:11 -0700 | [diff] [blame] | 188 | ) |
| 189 | |
Jisi Liu | be92ffb | 2015-10-27 15:11:38 -0700 | [diff] [blame] | 190 | if default_runtime and not default_runtime in cc_libs: |
| 191 | cc_libs += [default_runtime] |
Manjunath Kudlur | f5c7363 | 2016-02-25 08:50:50 -0800 | [diff] [blame^] | 192 | if use_grpc_plugin: |
| 193 | cc_libs += ["//external:grpc_lib"] |
Jisi Liu | 6dac082 | 2015-10-19 14:41:00 -0700 | [diff] [blame] | 194 | |
Jisi Liu | 39362b3 | 2015-10-14 17:12:11 -0700 | [diff] [blame] | 195 | native.cc_library( |
Jisi Liu | 125a91b | 2015-10-14 17:37:39 -0700 | [diff] [blame] | 196 | name=name, |
| 197 | srcs=outs, |
Jisi Liu | d8701b5 | 2015-10-16 11:44:21 -0700 | [diff] [blame] | 198 | deps=cc_libs + deps, |
Jisi Liu | 6dac082 | 2015-10-19 14:41:00 -0700 | [diff] [blame] | 199 | includes=includes, |
Jisi Liu | d8701b5 | 2015-10-16 11:44:21 -0700 | [diff] [blame] | 200 | **kargs) |
Jisi Liu | 993fb70 | 2015-10-19 17:19:49 -0700 | [diff] [blame] | 201 | |
Jisi Liu | bc4fd15 | 2015-10-20 16:02:58 -0700 | [diff] [blame] | 202 | def internal_copied_filegroup( |
Jisi Liu | 993fb70 | 2015-10-19 17:19:49 -0700 | [diff] [blame] | 203 | name, |
| 204 | srcs, |
| 205 | include, |
| 206 | **kargs): |
Jisi Liu | 7b948cc | 2015-10-19 17:56:27 -0700 | [diff] [blame] | 207 | """Bazel rule to fix sources file to workaround with python path issues. |
| 208 | |
| 209 | Args: |
Jisi Liu | bc4fd15 | 2015-10-20 16:02:58 -0700 | [diff] [blame] | 210 | name: the name of the internal_copied_filegroup rule, which will be the |
| 211 | name of the generated filegroup. |
Jisi Liu | 7b948cc | 2015-10-19 17:56:27 -0700 | [diff] [blame] | 212 | srcs: the source files to be copied. |
| 213 | include: the expected import root of the source. |
| 214 | **kargs: extra arguments that will be passed into the filegroup. |
| 215 | """ |
Jisi Liu | 993fb70 | 2015-10-19 17:19:49 -0700 | [diff] [blame] | 216 | outs = [_RelativeOutputPath(s, include) for s in srcs] |
| 217 | |
| 218 | native.genrule( |
| 219 | name=name+"_genrule", |
| 220 | srcs=srcs, |
| 221 | outs=outs, |
Jisi Liu | 6ddcae2 | 2015-10-21 10:48:33 -0700 | [diff] [blame] | 222 | cmd=" && ".join(["cp $(location %s) $(location %s)" % |
| 223 | (s, _RelativeOutputPath(s, include)) |
| 224 | for s in srcs])) |
Jisi Liu | 993fb70 | 2015-10-19 17:19:49 -0700 | [diff] [blame] | 225 | |
| 226 | native.filegroup( |
| 227 | name=name, |
| 228 | srcs=outs, |
| 229 | **kargs) |
| 230 | |
Jisi Liu | 993fb70 | 2015-10-19 17:19:49 -0700 | [diff] [blame] | 231 | def py_proto_library( |
| 232 | name, |
| 233 | srcs=[], |
| 234 | deps=[], |
| 235 | py_libs=[], |
| 236 | py_extra_srcs=[], |
| 237 | include=None, |
Jisi Liu | be92ffb | 2015-10-27 15:11:38 -0700 | [diff] [blame] | 238 | default_runtime="//google/protobuf:protobuf_python", |
Jisi Liu | 04658a3 | 2015-10-20 15:00:13 -0700 | [diff] [blame] | 239 | protoc="//google/protobuf:protoc", |
Jisi Liu | 993fb70 | 2015-10-19 17:19:49 -0700 | [diff] [blame] | 240 | **kargs): |
Jisi Liu | 7b948cc | 2015-10-19 17:56:27 -0700 | [diff] [blame] | 241 | """Bazel rule to create a Python protobuf library from proto source files |
| 242 | |
Jisi Liu | d4bef7d | 2015-11-02 12:24:32 -0800 | [diff] [blame] | 243 | NOTE: the rule is only an internal workaround to generate protos. The |
| 244 | interface may change and the rule may be removed when bazel has introduced |
| 245 | the native rule. |
| 246 | |
Jisi Liu | 7b948cc | 2015-10-19 17:56:27 -0700 | [diff] [blame] | 247 | Args: |
| 248 | name: the name of the py_proto_library. |
| 249 | srcs: the .proto files of the py_proto_library. |
| 250 | deps: a list of dependency labels; must be py_proto_library. |
| 251 | py_libs: a list of other py_library targets depended by the generated |
| 252 | py_library. |
| 253 | py_extra_srcs: extra source files that will be added to the output |
| 254 | py_library. This attribute is used for internal bootstrapping. |
| 255 | include: a string indicating the include path of the .proto files. |
Jisi Liu | be92ffb | 2015-10-27 15:11:38 -0700 | [diff] [blame] | 256 | default_runtime: the implicitly default runtime which will be depended on by |
| 257 | the generated py_library target. |
Jisi Liu | 7b948cc | 2015-10-19 17:56:27 -0700 | [diff] [blame] | 258 | protoc: the label of the protocol compiler to generate the sources. |
| 259 | **kargs: other keyword arguments that are passed to cc_library. |
| 260 | |
| 261 | """ |
Jisi Liu | 993fb70 | 2015-10-19 17:19:49 -0700 | [diff] [blame] | 262 | outs = _PyOuts(srcs) |
Jisi Liu | 53a56be | 2015-10-20 15:18:20 -0700 | [diff] [blame] | 263 | |
| 264 | includes = [] |
| 265 | if include != None: |
| 266 | includes = [include] |
| 267 | |
Jisi Liu | 993fb70 | 2015-10-19 17:19:49 -0700 | [diff] [blame] | 268 | _proto_gen( |
| 269 | name=name + "_genproto", |
| 270 | srcs=srcs, |
| 271 | deps=[s + "_genproto" for s in deps], |
Jisi Liu | 53a56be | 2015-10-20 15:18:20 -0700 | [diff] [blame] | 272 | includes=includes, |
Jisi Liu | 993fb70 | 2015-10-19 17:19:49 -0700 | [diff] [blame] | 273 | protoc=protoc, |
| 274 | gen_py=1, |
| 275 | outs=outs, |
Martin Maly | 8e0c9a3 | 2015-12-04 17:44:58 -0800 | [diff] [blame] | 276 | visibility=["//visibility:public"], |
Jisi Liu | 993fb70 | 2015-10-19 17:19:49 -0700 | [diff] [blame] | 277 | ) |
| 278 | |
Jisi Liu | 993fb70 | 2015-10-19 17:19:49 -0700 | [diff] [blame] | 279 | if include != None: |
Jisi Liu | 7b948cc | 2015-10-19 17:56:27 -0700 | [diff] [blame] | 280 | # Copy the output files to the desired location to make the import work. |
Jisi Liu | bc4fd15 | 2015-10-20 16:02:58 -0700 | [diff] [blame] | 281 | internal_copied_filegroup_name=name + "_internal_copied_filegroup" |
| 282 | internal_copied_filegroup( |
| 283 | name=internal_copied_filegroup_name, |
Jisi Liu | 993fb70 | 2015-10-19 17:19:49 -0700 | [diff] [blame] | 284 | srcs=outs, |
| 285 | include=include) |
Jisi Liu | bc4fd15 | 2015-10-20 16:02:58 -0700 | [diff] [blame] | 286 | outs=[internal_copied_filegroup_name] |
Jisi Liu | 993fb70 | 2015-10-19 17:19:49 -0700 | [diff] [blame] | 287 | |
Jisi Liu | be92ffb | 2015-10-27 15:11:38 -0700 | [diff] [blame] | 288 | if default_runtime and not default_runtime in py_libs + deps: |
| 289 | py_libs += [default_runtime] |
| 290 | |
Jisi Liu | 993fb70 | 2015-10-19 17:19:49 -0700 | [diff] [blame] | 291 | native.py_library( |
| 292 | name=name, |
Jisi Liu | a33fa8e | 2015-10-20 15:30:44 -0700 | [diff] [blame] | 293 | srcs=outs+py_extra_srcs, |
| 294 | deps=py_libs+deps, |
Jisi Liu | 993fb70 | 2015-10-19 17:19:49 -0700 | [diff] [blame] | 295 | **kargs) |
| 296 | |
| 297 | def internal_protobuf_py_tests( |
| 298 | name, |
| 299 | modules=[], |
| 300 | **kargs): |
Jisi Liu | 7b948cc | 2015-10-19 17:56:27 -0700 | [diff] [blame] | 301 | """Bazel rules to create batch tests for protobuf internal. |
| 302 | |
| 303 | Args: |
| 304 | name: the name of the rule. |
| 305 | modules: a list of modules for tests. The macro will create a py_test for |
| 306 | each of the parameter with the source "google/protobuf/%s.py" |
| 307 | kargs: extra parameters that will be passed into the py_test. |
| 308 | |
| 309 | """ |
Jisi Liu | 993fb70 | 2015-10-19 17:19:49 -0700 | [diff] [blame] | 310 | for m in modules: |
Jisi Liu | 7b948cc | 2015-10-19 17:56:27 -0700 | [diff] [blame] | 311 | s = _RelativeOutputPath( |
| 312 | "python/google/protobuf/internal/%s.py" % m, "python") |
Jisi Liu | 993fb70 | 2015-10-19 17:19:49 -0700 | [diff] [blame] | 313 | native.py_test( |
| 314 | name="py_%s" % m, |
Jisi Liu | 7b948cc | 2015-10-19 17:56:27 -0700 | [diff] [blame] | 315 | srcs=[s], |
| 316 | main=s, |
Jisi Liu | 993fb70 | 2015-10-19 17:19:49 -0700 | [diff] [blame] | 317 | **kargs) |