-
Notifications
You must be signed in to change notification settings - Fork 383
/
lang.go
99 lines (77 loc) · 3.14 KB
/
lang.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
/* Copyright 2019 The Bazel Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package test_filegroup generates an "all_files" filegroup target
// in each package. This target globs files in the same package and
// depends on subpackages.
//
// These rules are used for testing with go_bazel_test.
//
// This extension is experimental and subject to change. It is not included
// in the default Gazelle binary.
package test_filegroup
import (
"flag"
"path"
"github.com/bazelbuild/bazel-gazelle/config"
"github.com/bazelbuild/bazel-gazelle/label"
"github.com/bazelbuild/bazel-gazelle/language"
"github.com/bazelbuild/bazel-gazelle/repo"
"github.com/bazelbuild/bazel-gazelle/resolve"
"github.com/bazelbuild/bazel-gazelle/rule"
)
const testFilegroupName = "test_filegroup"
type testFilegroupLang struct{}
func NewLanguage() language.Language {
return &testFilegroupLang{}
}
func (*testFilegroupLang) Name() string { return testFilegroupName }
func (*testFilegroupLang) RegisterFlags(fs *flag.FlagSet, cmd string, c *config.Config) {}
func (*testFilegroupLang) CheckFlags(fs *flag.FlagSet, c *config.Config) error { return nil }
func (*testFilegroupLang) KnownDirectives() []string { return nil }
func (*testFilegroupLang) Configure(c *config.Config, rel string, f *rule.File) {}
func (*testFilegroupLang) Kinds() map[string]rule.KindInfo {
return kinds
}
func (*testFilegroupLang) Loads() []rule.LoadInfo { return nil }
func (*testFilegroupLang) Fix(c *config.Config, f *rule.File) {}
func (*testFilegroupLang) Imports(c *config.Config, r *rule.Rule, f *rule.File) []resolve.ImportSpec {
return nil
}
func (*testFilegroupLang) Embeds(r *rule.Rule, from label.Label) []label.Label { return nil }
func (*testFilegroupLang) Resolve(c *config.Config, ix *resolve.RuleIndex, rc *repo.RemoteCache, r *rule.Rule, imports interface{}, from label.Label) {
}
var kinds = map[string]rule.KindInfo{
"filegroup": {
NonEmptyAttrs: map[string]bool{"srcs": true, "deps": true},
MergeableAttrs: map[string]bool{"srcs": true},
},
}
func (*testFilegroupLang) GenerateRules(args language.GenerateArgs) language.GenerateResult {
r := rule.NewRule("filegroup", "all_files")
srcs := make([]string, 0, len(args.Subdirs)+len(args.RegularFiles))
for _, f := range args.RegularFiles {
srcs = append(srcs, f)
}
for _, f := range args.Subdirs {
pkg := path.Join(args.Rel, f)
srcs = append(srcs, "//"+pkg+":all_files")
}
r.SetAttr("srcs", srcs)
r.SetAttr("testonly", true)
if args.File == nil || !args.File.HasDefaultVisibility() {
r.SetAttr("visibility", []string{"//visibility:public"})
}
return language.GenerateResult{
Gen: []*rule.Rule{r},
Imports: []interface{}{nil},
}
}