Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
643a02bc
Commit
643a02bc
authored
Sep 09, 2016
by
Jisi Liu
Committed by
GitHub
Sep 09, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1636 from yugui/feature/generic-plugin
Generalize plugin support in Bazel Skylark rule
parents
53387e5f
5977fb0a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
10 deletions
+44
-10
protobuf.bzl
protobuf.bzl
+44
-10
No files found.
protobuf.bzl
View file @
643a02bc
...
...
@@ -62,9 +62,19 @@ def _proto_gen_impl(ctx):
if
ctx
.
attr
.
gen_py
:
args
+=
[
"--python_out="
+
ctx
.
var
[
"GENDIR"
]
+
"/"
+
gen_dir
]
if
ctx
.
executable
.
grpc_cpp_plugin
:
args
+=
[
"--plugin=protoc-gen-grpc="
+
ctx
.
executable
.
grpc_cpp_plugin
.
path
]
args
+=
[
"--grpc_out="
+
ctx
.
var
[
"GENDIR"
]
+
"/"
+
gen_dir
]
if
ctx
.
executable
.
plugin
:
plugin
=
ctx
.
executable
.
plugin
lang
=
ctx
.
attr
.
plugin_language
if
not
lang
and
plugin
.
basename
.
startswith
(
'protoc-gen-'
):
lang
=
plugin
.
basename
[
len
(
'protoc-gen-'
):]
if
not
lang
:
fail
(
"cannot infer the target language of plugin"
,
"plugin_language"
)
outdir
=
ctx
.
var
[
"GENDIR"
]
+
"/"
+
gen_dir
if
ctx
.
attr
.
plugin_options
:
outdir
=
","
.
join
(
ctx
.
attr
.
plugin_options
)
+
":"
+
outdir
args
+=
[
"--plugin=protoc-gen-
%
s=
%
s"
%
(
lang
,
plugin
.
path
)]
args
+=
[
"--
%
s_out=
%
s"
%
(
lang
,
outdir
)]
if
args
:
ctx
.
action
(
...
...
@@ -72,6 +82,7 @@ def _proto_gen_impl(ctx):
outputs
=
ctx
.
outputs
.
outs
,
arguments
=
args
+
import_flags
+
[
s
.
path
for
s
in
srcs
],
executable
=
ctx
.
executable
.
protoc
,
mnemonic
=
"ProtoCompile"
,
)
return
struct
(
...
...
@@ -82,7 +93,7 @@ def _proto_gen_impl(ctx):
),
)
_
proto_gen
=
rule
(
proto_gen
=
rule
(
attrs
=
{
"srcs"
:
attr
.
label_list
(
allow_files
=
True
),
"deps"
:
attr
.
label_list
(
providers
=
[
"proto"
]),
...
...
@@ -93,11 +104,13 @@ _proto_gen = rule(
single_file
=
True
,
mandatory
=
True
,
),
"
grpc_cpp_
plugin"
:
attr
.
label
(
"plugin"
:
attr
.
label
(
cfg
=
HOST_CFG
,
allow_files
=
True
,
executable
=
True
,
single_file
=
True
,
),
"plugin_language"
:
attr
.
string
(),
"plugin_options"
:
attr
.
string_list
(),
"gen_cc"
:
attr
.
bool
(),
"gen_py"
:
attr
.
bool
(),
"outs"
:
attr
.
output_list
(),
...
...
@@ -105,6 +118,26 @@ _proto_gen = rule(
output_to_genfiles
=
True
,
implementation
=
_proto_gen_impl
,
)
"""Generates codes from Protocol Buffers definitions.
This rule helps you to implement Skylark macros specific to the target
language. You should prefer more specific `cc_proto_library `,
`py_proto_library` and others unless you are adding such wrapper macros.
Args:
srcs: Protocol Buffers definition files (.proto) to run the protocol compiler
against.
deps: a list of dependency labels; must be other proto libraries.
includes: a list of include paths to .proto files.
protoc: the label of the protocol compiler to generate the sources.
plugin: the label of the protocol compiler plugin to be passed to the protocol
compiler.
plugin_language: the language of the generated sources
plugin_options: a list of options to be passed to the plugin
gen_cc: generates C++ sources in addition to the ones from the plugin.
gen_py: generates Python sources in addition to the ones from the plugin.
outs: a list of labels of the expected outputs from the protocol compiler.
"""
def
cc_proto_library
(
name
,
...
...
@@ -150,7 +183,7 @@ def cc_proto_library(
if
internal_bootstrap_hack
:
# For pre-checked-in generated files, we add the internal_bootstrap_hack
# which will skip the codegen action.
_
proto_gen
(
proto_gen
(
name
=
name
+
"_genproto"
,
srcs
=
srcs
,
deps
=
[
s
+
"_genproto"
for
s
in
deps
],
...
...
@@ -170,13 +203,14 @@ def cc_proto_library(
outs
=
_CcOuts
(
srcs
,
use_grpc_plugin
)
_
proto_gen
(
proto_gen
(
name
=
name
+
"_genproto"
,
srcs
=
srcs
,
deps
=
[
s
+
"_genproto"
for
s
in
deps
],
includes
=
includes
,
protoc
=
protoc
,
grpc_cpp_plugin
=
grpc_cpp_plugin
,
plugin
=
grpc_cpp_plugin
,
plugin_language
=
"grpc"
,
gen_cc
=
1
,
outs
=
outs
,
visibility
=
[
"//visibility:public"
],
...
...
@@ -286,7 +320,7 @@ def py_proto_library(
if
include
!=
None
:
includes
=
[
include
]
_
proto_gen
(
proto_gen
(
name
=
name
+
"_genproto"
,
srcs
=
srcs
,
deps
=
[
s
+
"_genproto"
for
s
in
deps
],
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment