Skip to content

Commit 439c57e

Browse files
douglas-reidpcj
authored andcommitted
Add support for using generated protos w/o output_to_workspace (#118)
1 parent 525f061 commit 439c57e

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

protobuf/internal/proto_compile.bzl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,17 +331,26 @@ def _build_protobuf_out(run, builder):
331331
"""Build the --{lang}_out option"""
332332
lang = run.lang
333333
name = lang.pb_plugin_name or lang.name
334-
outdir = builder.get(lang.name + "_outdir", run.outdir)
335334
options = builder.get(lang.name + "_pb_options", [])
336335

336+
if run.data.protos[0].path.startswith(run.ctx.var["GENDIR"]):
337+
outdir = "."
338+
else:
339+
outdir = builder.get(lang.name + "_outdir", run.outdir)
340+
337341
_build_plugin_out(name, outdir, options, builder)
338342

339343

340344
def _build_grpc_out(run, builder):
341345
"""Build the --{lang}_out grpc option"""
342346
lang = run.lang
343347
name = lang.grpc_plugin_name or "grpc-" + lang.name
344-
outdir = builder.get(lang.name + "_outdir", run.outdir)
348+
349+
if run.data.protos[0].path.startswith(run.ctx.var["GENDIR"]):
350+
outdir = "."
351+
else:
352+
outdir = builder.get(lang.name + "_outdir", run.outdir)
353+
345354
options = builder.get(lang.name + "_grpc_options", [])
346355

347356
_build_plugin_out(name, outdir, options, builder)

tests/generated_proto_file/BUILD

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load("//cpp:rules.bzl", "cpp_proto_library")
4+
load("//go:rules.bzl", "go_proto_library")
5+
6+
genrule(
7+
name = "copy_file",
8+
srcs = ["simple.proto"],
9+
outs = ["copy.proto"],
10+
cmd = "cat $(location simple.proto) > $@",
11+
message = "copy",
12+
)
13+
14+
cpp_proto_library(
15+
name = "default_library",
16+
protos = ["simple.proto"],
17+
)
18+
19+
cpp_proto_library(
20+
name = "copy_library",
21+
protos = ["copy.proto"],
22+
with_grpc = True,
23+
)
24+
25+
go_proto_library(
26+
name = "go_default_library",
27+
protos = ["simple.proto"],
28+
)
29+
30+
go_proto_library(
31+
name = "go_copy_library",
32+
protos = ["copy.proto"],
33+
with_grpc = True,
34+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
syntax = "proto3";
2+
3+
package simple;
4+
5+
message Test {
6+
string value = 1;
7+
}

0 commit comments

Comments
 (0)