@@ -160,6 +160,74 @@ def kt_jvm_grpc_library(
160
160
features = features ,
161
161
)
162
162
163
+ def kt_jvm_grpc_no_java_library (
164
+ name ,
165
+ srcs = None ,
166
+ deps = None ,
167
+ java_grpc_dep = None ,
168
+ tags = None ,
169
+ testonly = None , # None to not override Bazel's default
170
+ compatible_with = None ,
171
+ restricted_to = None ,
172
+ visibility = None ,
173
+ deprecation = None ,
174
+ features = []):
175
+ """This rule compiles Kotlin APIs for gRPC services from the proto_library in srcs.
176
+
177
+ Unlike kt_jvm_grpc_library, this rule will not generate a java_grpc_library target
178
+ implicitly but instead expects one as an input to java_grpc_dep.
179
+
180
+ For standard attributes, see:
181
+ https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes
182
+
183
+ Args:
184
+ name: A name for the target
185
+ srcs: Exactly one proto_library target to generate Kotlin APIs for
186
+ deps: Exactly one java_proto_library target for srcs[0]
187
+ java_grpc_dep: java_grpc_library target for the java_proto_library in deps
188
+ tags: A list of string tags passed to generated targets.
189
+ testonly: Whether this target is intended only for tests.
190
+ compatible_with: Standard attribute
191
+ restricted_to: Standard attribute
192
+ visibility: A list of targets allowed to depend on this rule.
193
+ deprecation: Standard attribute
194
+ features: Features enabled.
195
+ """
196
+ srcs = srcs or []
197
+ deps = deps or []
198
+
199
+ if len (srcs ) != 1 :
200
+ fail ("Expected exactly one src" , "srcs" )
201
+ if len (deps ) != 1 :
202
+ fail ("Expected exactly one dep" , "deps" )
203
+ if not java_grpc_dep :
204
+ fail ("A java_grpc_dep is required" , "java_grpc_dep" )
205
+
206
+ kt_grpc_label = ":%s_DO_NOT_DEPEND_kt_grpc" % name
207
+ kt_grpc_name = kt_grpc_label [1 :]
208
+
209
+ _kt_grpc_generate_code (
210
+ name = kt_grpc_name ,
211
+ srcs = srcs ,
212
+ deps = deps ,
213
+ )
214
+
215
+ kt_jvm_library (
216
+ name = name ,
217
+ srcs = [kt_grpc_label ],
218
+ deps = [
219
+ java_grpc_dep ,
220
+ "@com_github_grpc_grpc_kotlin//stub/src/main/java/io/grpc/kotlin:stub" ,
221
+ "@com_github_grpc_grpc_kotlin//stub/src/main/java/io/grpc/kotlin:context" ,
222
+ ],
223
+ compatible_with = compatible_with ,
224
+ restricted_to = restricted_to ,
225
+ testonly = testonly ,
226
+ visibility = visibility ,
227
+ deprecation = deprecation ,
228
+ features = features ,
229
+ )
230
+
163
231
def _get_real_short_path (file ):
164
232
"""Returns the correct short path file name to be used by protoc."""
165
233
short_path = file .short_path
@@ -200,7 +268,6 @@ def _kt_jvm_proto_library_helper_impl(ctx):
200
268
outputs = [gen_src_dir ],
201
269
executable = ctx .executable ._protoc ,
202
270
arguments = [protoc_args ],
203
- mnemonic = "KtProtoGenerator" ,
204
271
progress_message = "Generating kotlin proto extensions for " +
205
272
", " .join ([
206
273
str (dep .label )
@@ -252,6 +319,7 @@ _kt_jvm_proto_library_helper = rule(
252
319
def kt_jvm_proto_library (
253
320
name ,
254
321
deps = None ,
322
+ java_deps = None ,
255
323
tags = None ,
256
324
testonly = None ,
257
325
compatible_with = None ,
@@ -267,15 +335,17 @@ def kt_jvm_proto_library(
267
335
See also https://developers.google.com/protocol-buffers/docs/kotlintutorial for how to interact
268
336
with the generated Kotlin representation.
269
337
270
- Note that the rule will also export the java version of the same protos as Kotlin protos depend
271
- on the java version under the hood.
338
+ If "java_deps" are set, they must be exactly the java_proto_library targets for "deps". If
339
+ "java_deps" are not set, this rule will generate and export the java protos for all "deps",
340
+ using "flavor" to determine their type.
272
341
273
342
For standard attributes, see:
274
343
https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes
275
344
276
345
Args:
277
346
name: A name for the target
278
347
deps: One or more proto_library targets to turn into Kotlin.
348
+ java_deps: (optional) java_proto_library targets corresponding to deps
279
349
tags: Standard attribute
280
350
testonly: Standard attribute
281
351
compatible_with: Standard attribute
@@ -286,40 +356,43 @@ def kt_jvm_proto_library(
286
356
deprecation: Standard attribute
287
357
features: Standard attribute
288
358
"""
289
- java_proto_target = ":%s_DO_NOT_DEPEND_java_proto" % name
290
- helper_target = ":%s_DO_NOT_DEPEND_kt_proto" % name
291
-
292
- if flavor == "lite" :
293
- native .java_lite_proto_library (
294
- name = java_proto_target [1 :],
295
- deps = deps ,
296
- testonly = testonly ,
297
- compatible_with = compatible_with ,
298
- visibility = ["//visibility:private" ],
299
- restricted_to = restricted_to ,
300
- tags = tags ,
301
- deprecation = deprecation ,
302
- features = features ,
303
- )
359
+ if (java_deps != None and len (java_deps ) > 0 ):
360
+ java_protos = java_deps
361
+ java_exports = []
304
362
else :
305
- native .java_proto_library (
306
- name = java_proto_target [1 :],
307
- deps = deps ,
308
- testonly = testonly ,
309
- compatible_with = compatible_with ,
310
- visibility = ["//visibility:private" ],
311
- restricted_to = restricted_to ,
312
- tags = tags ,
313
- deprecation = deprecation ,
314
- features = features ,
315
- )
363
+ java_proto_target = ":%s_DO_NOT_DEPEND_java_proto" % name
364
+ if flavor == "lite" :
365
+ native .java_lite_proto_library (
366
+ name = java_proto_target [1 :],
367
+ deps = deps ,
368
+ testonly = testonly ,
369
+ compatible_with = compatible_with ,
370
+ visibility = ["//visibility:private" ],
371
+ restricted_to = restricted_to ,
372
+ tags = tags ,
373
+ deprecation = deprecation ,
374
+ features = features ,
375
+ )
376
+ else :
377
+ native .java_proto_library (
378
+ name = java_proto_target [1 :],
379
+ deps = deps ,
380
+ testonly = testonly ,
381
+ compatible_with = compatible_with ,
382
+ visibility = ["//visibility:private" ],
383
+ restricted_to = restricted_to ,
384
+ tags = tags ,
385
+ deprecation = deprecation ,
386
+ features = features ,
387
+ )
388
+ java_protos = [java_proto_target ]
389
+ java_exports = [java_proto_target ]
316
390
391
+ helper_target = ":%s_DO_NOT_DEPEND_kt_proto" % name
317
392
_kt_jvm_proto_library_helper (
318
393
name = helper_target [1 :],
319
394
proto_deps = deps ,
320
- deps = [
321
- java_proto_target ,
322
- ],
395
+ deps = java_protos ,
323
396
testonly = testonly ,
324
397
compatible_with = compatible_with ,
325
398
visibility = ["//visibility:private" ],
@@ -334,11 +407,8 @@ def kt_jvm_proto_library(
334
407
srcs = [helper_target + ".srcjar" ],
335
408
deps = [
336
409
"@maven//:com_google_protobuf_protobuf_kotlin" ,
337
- java_proto_target ,
338
- ],
339
- exports = [
340
- java_proto_target ,
341
- ],
410
+ ] + java_protos ,
411
+ exports = java_exports ,
342
412
testonly = testonly ,
343
413
compatible_with = compatible_with ,
344
414
visibility = visibility ,
0 commit comments