Skip to content

Commit d172a22

Browse files
authored
fix: use REPO.bazel and MODULE.bazel when finding repo root (#2013)
Fixes #2012
1 parent 7f7af3b commit d172a22

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

internal/wspace/finder.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
)
2121

2222
var workspaceFiles = []string{"WORKSPACE.bazel", "WORKSPACE"}
23+
// See https://bazel.build/versions/8.0.0/external/overview#repository
24+
var repoBoundaryMarkerFiles = []string{"WORKSPACE.bazel", "WORKSPACE", "REPO.bazel", "MODULE.bazel"}
2325

2426
// IsWORKSPACE checks whether path is named WORKSPACE or WORKSPACE.bazel
2527
func IsWORKSPACE(path string) bool {
@@ -45,7 +47,8 @@ func FindWORKSPACEFile(root string) string {
4547
return filepath.Join(root, "WORKSPACE")
4648
}
4749

48-
// FindRepoRoot searches from the given dir and up for a directory containing a WORKSPACE file
50+
// FindRepoRoot searches from the given dir and up for a directory containing a "boundary marker file"
51+
// which delimit a repository as of Bazel 8,
4952
// returning the directory containing it, or an error if none found in the tree.
5053
func FindRepoRoot(dir string) (string, error) {
5154
dir, err := filepath.Abs(dir)
@@ -54,8 +57,8 @@ func FindRepoRoot(dir string) (string, error) {
5457
}
5558

5659
for {
57-
for _, workspaceFile := range workspaceFiles {
58-
filepath := filepath.Join(dir, workspaceFile)
60+
for _, boundaryFile := range repoBoundaryMarkerFiles {
61+
filepath := filepath.Join(dir, boundaryFile)
5962
info, err := os.Stat(filepath)
6063
if err == nil && !info.IsDir() {
6164
return dir, nil

0 commit comments

Comments
 (0)