-
Notifications
You must be signed in to change notification settings - Fork 150
/
scala_proto_library.go
99 lines (82 loc) · 2.8 KB
/
scala_proto_library.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package rules_scala
import (
"github.com/bazelbuild/bazel-gazelle/config"
"github.com/bazelbuild/bazel-gazelle/label"
"github.com/bazelbuild/bazel-gazelle/resolve"
"github.com/bazelbuild/bazel-gazelle/rule"
"github.com/stackb/rules_proto/pkg/protoc"
)
func init() {
protoc.Rules().MustRegisterRule("bazelbuild:rules_scala:scala_proto_library",
&scalaProtoLibrary{})
}
// scalaProtoLibrary implements LanguageRule for the 'scala_proto_library' rule
// from @rules_scala.
type scalaProtoLibrary struct{}
// Name implements part of the LanguageRule interface.
func (s *scalaProtoLibrary) Name() string {
return "scala_proto_library"
}
// KindInfo implements part of the LanguageRule interface.
func (s *scalaProtoLibrary) KindInfo() rule.KindInfo {
return rule.KindInfo{
MergeableAttrs: map[string]bool{
"srcs": true,
"deps": true,
"visibility": true,
},
NonEmptyAttrs: map[string]bool{
"srcs": true,
},
}
}
// LoadInfo implements part of the LanguageRule interface.
func (s *scalaProtoLibrary) LoadInfo() rule.LoadInfo {
return rule.LoadInfo{
Name: "@build_stack_rules_proto//rules/scala:scala_proto_library.bzl",
Symbols: []string{s.Name()},
}
}
// ProvideRule implements part of the LanguageRule interface.
func (s *scalaProtoLibrary) ProvideRule(cfg *protoc.LanguageRuleConfig, pc *protoc.ProtocConfiguration) protoc.RuleProvider {
return &scalaProtoLibraryRule{
kindName: s.Name(),
ruleConfig: cfg,
config: pc,
}
}
// scalaProtoLibraryRule implements RuleProvider for 'scala_library'-derived rules.
type scalaProtoLibraryRule struct {
kindName string
config *protoc.ProtocConfiguration
ruleConfig *protoc.LanguageRuleConfig
}
// Kind implements part of the ruleProvider interface.
func (s *scalaProtoLibraryRule) Kind() string {
return s.kindName
}
// Name implements part of the ruleProvider interface.
func (s *scalaProtoLibraryRule) Name() string {
return s.config.Library.BaseName() + "_scala_proto"
}
// Visibility provides visibility labels.
func (s *scalaProtoLibraryRule) Visibility() []string {
return s.ruleConfig.GetVisibility()
}
// Rule implements part of the ruleProvider interface.
func (s *scalaProtoLibraryRule) Rule(otherGen ...*rule.Rule) *rule.Rule {
newRule := rule.NewRule(s.Kind(), s.Name())
visibility := s.Visibility()
if len(visibility) > 0 {
newRule.SetAttr("visibility", visibility)
}
return newRule
}
// Imports implements part of the RuleProvider interface.
func (s *scalaProtoLibraryRule) Imports(c *config.Config, r *rule.Rule, file *rule.File) []resolve.ImportSpec {
return nil
}
// Resolve implements part of the RuleProvider interface.
func (s *scalaProtoLibraryRule) Resolve(c *config.Config, ix *resolve.RuleIndex, r *rule.Rule, imports []string, from label.Label) {
r.SetAttr("deps", []string{":" + s.config.Library.Name()})
}