forked from stackb/rules_proto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
protoc-gen-grpc-java.go
43 lines (36 loc) · 1.12 KB
/
protoc-gen-grpc-java.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package java
import (
"path"
"github.com/bazelbuild/bazel-gazelle/label"
"github.com/stackb/rules_proto/pkg/protoc"
)
func init() {
protoc.Plugins().MustRegisterPlugin(&ProtocGenGrpcJavaPlugin{})
}
// ProtocGenGrpcJavaPlugin implements Plugin for the grpc java plugin.
type ProtocGenGrpcJavaPlugin struct{}
// Name implements part of the Plugin interface.
func (p *ProtocGenGrpcJavaPlugin) Name() string {
return "grpc:grpc-java:protoc-gen-grpc-java"
}
// Configure implements part of the Plugin interface.
func (p *ProtocGenGrpcJavaPlugin) Configure(ctx *protoc.PluginContext) *protoc.PluginConfiguration {
if !p.shouldApply(ctx.ProtoLibrary) {
return nil
}
srcjar := path.Join(ctx.Rel, ctx.ProtoLibrary.BaseName()+"_grpc.srcjar")
return &protoc.PluginConfiguration{
Label: label.New("build_stack_rules_proto", "plugin/grpc/grpc-java", "protoc-gen-grpc-java"),
Outputs: []string{srcjar},
Out: srcjar,
Options: ctx.PluginConfig.GetOptions(),
}
}
func (p *ProtocGenGrpcJavaPlugin) shouldApply(lib protoc.ProtoLibrary) bool {
for _, f := range lib.Files() {
if f.HasServices() {
return true
}
}
return false
}