forked from stackb/rules_proto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
objc_plugin.go
42 lines (34 loc) · 1.09 KB
/
objc_plugin.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
package builtin
import (
"path"
"github.com/bazelbuild/bazel-gazelle/label"
"github.com/stackb/rules_proto/pkg/protoc"
)
func init() {
protoc.Plugins().MustRegisterPlugin(&ObjcPlugin{})
}
// ObjcPlugin implements Plugin for the built-in protoc C# plugin.
type ObjcPlugin struct{}
// Name implements part of the Plugin interface.
func (p *ObjcPlugin) Name() string {
return "builtin:objc"
}
// Configure implements part of the Plugin interface.
func (p *ObjcPlugin) Configure(ctx *protoc.PluginContext) *protoc.PluginConfiguration {
return &protoc.PluginConfiguration{
Label: label.New("build_stack_rules_proto", "plugin/builtin", "objc"),
Outputs: protoc.FlatMapFiles(
objcFileName(ctx.Rel, ctx.PluginConfig),
protoc.Always,
ctx.ProtoLibrary.Files()...,
),
Options: ctx.PluginConfig.GetOptions(),
}
}
func objcFileName(rel string, cfg protoc.LanguagePluginConfig) func(*protoc.File) []string {
return func(f *protoc.File) []string {
// setup the file extension
base := path.Join(rel, protoc.ToPascalCase(f.Name))
return []string{base + ".pbobjc.h", base + ".pbobjc.m"}
}
}