Skip to content

Commit

Permalink
Adds args string_list option to proto_compile
Browse files Browse the repository at this point in the history
* Also makes the `langs` attribute non-mandatory.

Closes #57
  • Loading branch information
pcj committed Jan 21, 2017
1 parent 3b478ea commit 5ec4fb2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
32 changes: 32 additions & 0 deletions examples/extra_args/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package(default_visibility = ["//visibility:public"])

# https://github.com/pubref/rules_protobuf/issues/57

load("@org_pubref_rules_protobuf//protobuf:rules.bzl", "proto_compile")
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")


filegroup(
name = "protos",
srcs = ["person.proto"],
)

proto_compile(
name = "person_proto",
protos = ["person.proto"],
args = [
"--include_imports",
"--include_source_info",
],
verbose = 0,
)

# pkg_tar rule is used in this example to provide a sink for the
# descriptor file, forcing bazel to actually execute upstream
# dependent rules.
pkg_tar(
name = "person_tar",
files = [
":person_proto.descriptor_set",
]
)
5 changes: 5 additions & 0 deletions examples/extra_args/person.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
syntax = "proto3";

message Person {
string name = 1;
}
1 change: 1 addition & 0 deletions protobuf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ proto_compile(
| `importmap` | `string_dict` | (golang specific) Optional mappings for the protoc-gen-go plugin. | `{}` |
| `root` | `string` | An optional path that shifts the directory scope of the computed execution root | `""` |
| `protoc` | executable `label` | Optional override to the default protoc binary tool. | `//external:protoc` |
| `args` | `string_list` | Optional extra arguments for the protoc command, such as `--include_source_info`. | `[]` |
| `output_to_workspace` | `boolean` | Optional flag. Under normal operation, generated code is placed in the bazel sandbox and does not need to be checked in into version control. However, your requirements may be such that is necessary to check these generated files in. Setting this flag to `True` will emit generated `*.pb.*` files into in your workspace alongside the `*.proto` source files. Please make sure you're sure you want to do this as it has the potential for unwanted overwrite of source files. | `False` |

---
Expand Down
5 changes: 3 additions & 2 deletions protobuf/internal/proto_compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ def _proto_compile_impl(ctx):
compiler = ctx.executable.protoc,
data = data,
transitive_mappings = builder.get("transitive_mappings", {}),
args = set(builder["args"]),
args = set(builder["args"] + ctx.attr.args),
imports = set(builder["imports"]),
inputs = set(builder["inputs"]),
outputs = set(builder["outputs"] + [ctx.outputs.descriptor_set]),
Expand All @@ -545,10 +545,11 @@ def _proto_compile_impl(ctx):
proto_compile = rule(
implementation = _proto_compile_impl,
attrs = {
"args": attr.string_list(),
"langs": attr.label_list(
providers = ["proto_language"],
allow_files = False,
mandatory = True,
mandatory = False,
),
"protos": attr.label_list(
allow_files = FileType([".proto"]),
Expand Down

0 comments on commit 5ec4fb2

Please sign in to comment.