Skip to content

Commit

Permalink
fix: use REPO.bazel and MODULE.bazel when finding repo root (#2013)
Browse files Browse the repository at this point in the history
Fixes #2012
  • Loading branch information
alexeagle authored Jan 14, 2025
1 parent 7f7af3b commit d172a22
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions internal/wspace/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
)

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

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

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

for {
for _, workspaceFile := range workspaceFiles {
filepath := filepath.Join(dir, workspaceFile)
for _, boundaryFile := range repoBoundaryMarkerFiles {
filepath := filepath.Join(dir, boundaryFile)
info, err := os.Stat(filepath)
if err == nil && !info.IsDir() {
return dir, nil
Expand Down

0 comments on commit d172a22

Please sign in to comment.