4
4
_scala_proto_deps_providers = "scala_proto_deps_providers" ,
5
5
)
6
6
7
- def _generators (ctx ):
8
- return dict (
9
- ctx .attr .named_generators ,
10
- scala = ctx .attr .main_generator ,
11
- )
12
-
13
7
def _generators_jars (ctx ):
14
8
generator_deps = ctx .attr .extra_generator_dependencies + [
15
9
ctx .attr ._main_generator_dep ,
@@ -19,22 +13,6 @@ def _generators_jars(ctx):
19
13
for dep in generator_deps
20
14
])
21
15
22
- def _generators_opts (ctx ):
23
- opts = []
24
- if ctx .attr .with_grpc :
25
- opts .append ("grpc" )
26
- if ctx .attr .with_flat_package :
27
- opts .append ("flat_package" )
28
- if ctx .attr .with_single_line_to_string :
29
- opts .append ("single_line_to_proto_string" )
30
- return "," .join (opts )
31
-
32
- def _compile_dep_ids (ctx ):
33
- deps = ["scalapb_compile_deps" ]
34
- if ctx .attr .with_grpc :
35
- deps .append ("scalapb_grpc_deps" )
36
- return deps
37
-
38
16
def _ignored_proto_targets_by_label (ctx ):
39
17
return {p .label : p for p in ctx .attr .blacklisted_protos }
40
18
@@ -49,13 +27,14 @@ def _worker_flags(ctx, generators, jars):
49
27
return "--jvm_flags=" + " " .join (["-D%s=%s" % i for i in env .items ()])
50
28
51
29
def _scala_proto_toolchain_impl (ctx ):
52
- generators = _generators ( ctx )
30
+ generators = ctx . attr . generators
53
31
generators_jars = _generators_jars (ctx )
32
+ compile_dep_ids = ["scalapb_compile_deps" ]
54
33
toolchain = platform_common .ToolchainInfo (
55
34
generators = generators ,
56
35
generators_jars = generators_jars ,
57
- generators_opts = _generators_opts ( ctx ) ,
58
- compile_dep_ids = _compile_dep_ids ( ctx ) ,
36
+ generators_opts = ctx . attr . generators_opts ,
37
+ compile_dep_ids = compile_dep_ids ,
59
38
blacklisted_protos = _ignored_proto_targets_by_label (ctx ),
60
39
protoc = ctx .executable .protoc ,
61
40
scalac = ctx .attr .scalac .files_to_run ,
@@ -66,35 +45,20 @@ def _scala_proto_toolchain_impl(ctx):
66
45
return [toolchain ]
67
46
68
47
# Args:
69
- # with_grpc: Enables generation of grpc service bindings for services
70
- # with_flat_package: When true, ScalaPB will not append the protofile base name to the package name
71
- # with_single_line_to_string: Enables generation of toString() methods that use the single line format
72
48
# blacklisted_protos: list of protobuf targets to exclude from recursive building
73
49
# code_generator: what code generator to use, usually you'll want the default
74
50
scala_proto_toolchain = rule (
75
51
implementation = _scala_proto_toolchain_impl ,
76
52
attrs = {
77
- "with_grpc" : attr .bool (),
78
- "with_flat_package" : attr .bool (),
79
- "with_single_line_to_string" : attr .bool (),
80
53
"blacklisted_protos" : attr .label_list (default = []),
81
54
"code_generator" : attr .label (
82
55
executable = True ,
83
56
cfg = "exec" ,
84
57
default = Label ("//src/scala/scripts:scalapb_worker" ),
85
58
allow_files = True ,
86
59
),
87
- # `scripts.ScalaPbCodeGenerator` and `_main_generator_dep` are currently
88
- # necessary to support protoc-bridge < 0.9.8, specifically 0.7.14
89
- # required by Scala 2.11. See #1647 and scalapb/ScalaPB#1771.
90
- #
91
- # If we drop 2.11 support, restore `scalapb.ScalaPbCodeGenerator` here,
92
- # remove `_main_generator_dep`, and delete
93
- # `//src/scala/scripts:scalapb_codegenerator_wrapper` and its files.
94
- "main_generator" : attr .string (
95
- default = "scripts.ScalaPbCodeGenerator" ,
96
- ),
97
- "named_generators" : attr .string_dict (),
60
+ "generators" : attr .string_dict (),
61
+ "generators_opts" : attr .string_list_dict (),
98
62
"extra_generator_dependencies" : attr .label_list (
99
63
providers = [JavaInfo ],
100
64
),
@@ -121,6 +85,13 @@ scala_proto_toolchain = rule(
121
85
[proto rules documentation](https://docs.bazel.build/versions/master/be/protocol-buffer.html#proto_library)
122
86
""" ,
123
87
),
88
+ # `scripts.ScalaPbCodeGenerator` and `_main_generator_dep` are currently
89
+ # necessary to support protoc-bridge < 0.9.8, specifically 0.7.14
90
+ # required by Scala 2.11. See #1647 and scalapb/ScalaPB#1771.
91
+ #
92
+ # If we drop 2.11 support, restore `scalapb.ScalaPbCodeGenerator` here,
93
+ # remove `_main_generator_dep`, and delete
94
+ # `//src/scala/scripts:scalapb_codegenerator_wrapper` and its files.
124
95
"_main_generator_dep" : attr .label (
125
96
default = Label (
126
97
"//src/scala/scripts:scalapb_codegenerator_wrapper" ,
@@ -132,6 +103,25 @@ scala_proto_toolchain = rule(
132
103
},
133
104
)
134
105
106
+ def scalapb_toolchain (name , opts = [], ** kwargs ):
107
+ """Sets up a scala_proto_toolchain using ScalaPB.
108
+
109
+ Args:
110
+ name: A unique name for this target
111
+ opts: scalapb generator options like 'grpc' or 'flat_package'
112
+ kwargs: remaining arguments to `scala_proto_toolchain`
113
+ """
114
+ scala_proto_toolchain (
115
+ name = name ,
116
+ generators = {
117
+ "scala" : "scripts.ScalaPbCodeGenerator" ,
118
+ },
119
+ generators_opts = {
120
+ "scala" : opts ,
121
+ },
122
+ ** kwargs
123
+ )
124
+
135
125
def _scala_proto_deps_toolchain (ctx ):
136
126
toolchain = platform_common .ToolchainInfo (
137
127
dep_providers = ctx .attr .dep_providers ,
0 commit comments