This repository has been archived by the owner on Jun 17, 2023. It is now read-only.
forked from stackb/rules_proto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grpc_web_js_library.go
64 lines (53 loc) · 1.97 KB
/
grpc_web_js_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
package rules_nodejs
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"
)
const (
grpcWebJsLibraryRuleName = "grpc_web_js_library"
grpcWebJsLibraryRuleSuffix = "_grpc_web_js_library"
)
func init() {
protoc.Rules().MustRegisterRule("stackb:rules_proto:grpc_web_js_library", &grpcWebJsLibrary{})
}
// grpcWebJsLibrary implements LanguageRule for the 'grpc_web_js_library' rule from @build_stack_rules_proto.
// (which is essentially a wrapper for 'js_library' rule from @build_bazel_rules_nodejs)
type grpcWebJsLibrary struct{}
// Name implements part of the LanguageRule interface.
func (s *grpcWebJsLibrary) Name() string {
return grpcWebJsLibraryRuleName
}
// KindInfo implements part of the LanguageRule interface.
func (s *grpcWebJsLibrary) KindInfo() rule.KindInfo {
return jsLibraryKindInfo
}
// LoadInfo implements part of the LanguageRule interface.
func (s *grpcWebJsLibrary) LoadInfo() rule.LoadInfo {
return rule.LoadInfo{
Name: "@build_stack_rules_proto//rules/nodejs:grpc_web_js_library.bzl",
Symbols: []string{grpcWebJsLibraryRuleName},
}
}
// ProvideRule implements part of the LanguageRule interface.
func (s *grpcWebJsLibrary) ProvideRule(cfg *protoc.LanguageRuleConfig, pc *protoc.ProtocConfiguration) protoc.RuleProvider {
outputs := pc.GetPluginOutputs("grpc:grpc-web:protoc-gen-grpc-web")
if len(outputs) == 0 {
return nil
}
return &JsLibrary{
KindName: grpcWebJsLibraryRuleName,
RuleNameSuffix: grpcWebJsLibraryRuleSuffix,
Outputs: outputs,
RuleConfig: cfg,
Config: pc,
Resolver: func(c *config.Config, ix *resolve.RuleIndex, r *rule.Rule, imports []string, from label.Label) {
deps := append(r.AttrStrings("deps"), ":"+pc.Library.BaseName()+ProtoNodeJsLibraryRuleSuffix)
if len(deps) > 0 {
r.SetAttr("deps", deps)
}
},
}
}