File tree 2 files changed +48
-9
lines changed
2 files changed +48
-9
lines changed Original file line number Diff line number Diff line change @@ -22,8 +22,8 @@ import (
22
22
23
23
"github.com/emirpasic/gods/lists/singlylinkedlist"
24
24
25
- "github.com/bazelbuild/bazel-gazelle/label"
26
25
"github.com/bazel-contrib/rules_python/gazelle/manifest"
26
+ "github.com/bazelbuild/bazel-gazelle/label"
27
27
)
28
28
29
29
// Directives
@@ -125,21 +125,28 @@ const (
125
125
126
126
// defaultIgnoreFiles is the list of default values used in the
127
127
// python_ignore_files option.
128
- var defaultIgnoreFiles = map [string ]struct {}{
129
- }
128
+ var defaultIgnoreFiles = map [string ]struct {}{}
130
129
131
130
// Configs is an extension of map[string]*Config. It provides finding methods
132
131
// on top of the mapping.
133
132
type Configs map [string ]* Config
134
133
135
134
// ParentForPackage returns the parent Config for the given Bazel package.
136
- func (c * Configs ) ParentForPackage (pkg string ) * Config {
137
- dir := path .Dir (pkg )
138
- if dir == "." {
139
- dir = ""
135
+ func (c Configs ) ParentForPackage (pkg string ) * Config {
136
+ for {
137
+ dir := path .Dir (pkg )
138
+ if dir == "." {
139
+ dir = ""
140
+ }
141
+ parent := (map [string ]* Config )(c )[dir ]
142
+ if parent != nil {
143
+ return parent
144
+ }
145
+ if dir == "" {
146
+ return nil
147
+ }
148
+ pkg = dir
140
149
}
141
- parent := (map [string ]* Config )(* c )[dir ]
142
- return parent
143
150
}
144
151
145
152
// Config represents a config extension for a specific Bazel package.
Original file line number Diff line number Diff line change @@ -248,3 +248,35 @@ func TestFormatThirdPartyDependency(t *testing.T) {
248
248
})
249
249
}
250
250
}
251
+
252
+ func TestConfigsMap (t * testing.T ) {
253
+ t .Run ("only root" , func (t * testing.T ) {
254
+ configs := Configs {"" : New ("root/dir" , "" )}
255
+
256
+ if configs .ParentForPackage ("" ) == nil {
257
+ t .Fatal ("expected non-nil for root config" )
258
+ }
259
+
260
+ if configs .ParentForPackage ("a/b/c" ) != configs ["" ] {
261
+ t .Fatal ("expected root for subpackage" )
262
+ }
263
+ })
264
+
265
+ t .Run ("sparse child configs" , func (t * testing.T ) {
266
+ configs := Configs {"" : New ("root/dir" , "" )}
267
+ configs ["a" ] = configs ["" ].NewChild ()
268
+ configs ["a/b/c" ] = configs ["a" ].NewChild ()
269
+
270
+ if configs .ParentForPackage ("a/b/c/d" ) != configs ["a/b/c" ] {
271
+ t .Fatal ("child should match direct parent" )
272
+ }
273
+
274
+ if configs .ParentForPackage ("a/b/c/d/e" ) != configs ["a/b/c" ] {
275
+ t .Fatal ("grandchild should match first parant" )
276
+ }
277
+
278
+ if configs .ParentForPackage ("other/root/path" ) != configs ["" ] {
279
+ t .Fatal ("non-configured subpackage should match root" )
280
+ }
281
+ })
282
+ }
You can’t perform that action at this time.
0 commit comments