@@ -2,6 +2,7 @@ package python
2
2
3
3
import (
4
4
"fmt"
5
+ "io/fs"
5
6
"log"
6
7
"os"
7
8
"path/filepath"
@@ -29,9 +30,6 @@ const (
29
30
30
31
var (
31
32
buildFilenames = []string {"BUILD" , "BUILD.bazel" }
32
- // errHaltDigging is an error that signals whether the generator should halt
33
- // digging the source tree searching for modules in subdirectories.
34
- errHaltDigging = fmt .Errorf ("halt digging" )
35
33
)
36
34
37
35
// GenerateRules extracts build metadata from source files in a directory.
@@ -106,9 +104,9 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
106
104
// boundaryPackages represents child Bazel packages that are used as a
107
105
// boundary to stop processing under that tree.
108
106
boundaryPackages := make (map [string ]struct {})
109
- err := filepath .Walk (
107
+ err := filepath .WalkDir (
110
108
filepath .Join (args .Dir , d ),
111
- func (path string , info os. FileInfo , err error ) error {
109
+ func (path string , entry fs. DirEntry , err error ) error {
112
110
if err != nil {
113
111
return err
114
112
}
@@ -120,7 +118,7 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
120
118
return nil
121
119
}
122
120
}
123
- if info .IsDir () {
121
+ if entry .IsDir () {
124
122
// If we are visiting a directory, we determine if we should
125
123
// halt digging the tree based on a few criterias:
126
124
// 1. The directory has a BUILD or BUILD.bazel files. Then
@@ -135,7 +133,7 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
135
133
}
136
134
137
135
if ! cfg .CoarseGrainedGeneration () && hasEntrypointFile (path ) {
138
- return errHaltDigging
136
+ return fs . SkipDir
139
137
}
140
138
141
139
return nil
@@ -168,7 +166,7 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
168
166
return nil
169
167
},
170
168
)
171
- if err != nil && err != errHaltDigging {
169
+ if err != nil {
172
170
log .Printf ("ERROR: %v\n " , err )
173
171
return language.GenerateResult {}
174
172
}
0 commit comments