diff --git a/internal/e2e/ibazel.go b/internal/e2e/ibazel.go index cfb560e1..dc1d1bb8 100644 --- a/internal/e2e/ibazel.go +++ b/internal/e2e/ibazel.go @@ -19,7 +19,7 @@ import ( // Maximum amount of time to wait before failing a test for not matching your expectations. const ( - defaultDelay = 20 * time.Second + defaultDelay = 40 * time.Second ) type IBazelTester struct { diff --git a/internal/ibazel/workspace/workspace.go b/internal/ibazel/workspace/workspace.go index dbf91fc7..e8290c97 100644 --- a/internal/ibazel/workspace/workspace.go +++ b/internal/ibazel/workspace/workspace.go @@ -39,6 +39,7 @@ func (m *MainWorkspace) FindWorkspace() (string, error) { } volume := filepath.VolumeName(path) + sentinel_filenames := []string{"WORKSPACE.bzlmod", "WORKSPACE.bazel", "MODULE.bazel", "WORKSPACE"} // search order for { // filepath.Dir() includes a trailing separator if we're at the root @@ -46,17 +47,16 @@ func (m *MainWorkspace) FindWorkspace() (string, error) { path = volume } - // Check if we're at the workspace path - if s, err := os.Stat(filepath.Join(path, "WORKSPACE")); err == nil { - if !s.IsDir() && s.Name() == "WORKSPACE" { - // In macOS directories called "workspace" will match because the file - // system isn't case sensitive. - return path, nil - } - } + for _, sentinel := range sentinel_filenames { + // Check if we're at the workspace path + if s, err := os.Stat(filepath.Join(path, sentinel)); err == nil { + // In macOS directories called "workspace" will match "WORKSPACE" + // because the file system isn't case sensitive - if _, err := os.Stat(filepath.Join(path, "WORKSPACE.bazel")); err == nil { - return path, nil + if !s.IsDir() && s.Name() == sentinel { + return path, nil + } + } } // If we've reached the root, then we know the cwd isn't within a workspace diff --git a/internal/ibazel/workspace/workspace_test.go b/internal/ibazel/workspace/workspace_test.go index 10931e34..6ea1de05 100644 --- a/internal/ibazel/workspace/workspace_test.go +++ b/internal/ibazel/workspace/workspace_test.go @@ -42,6 +42,22 @@ func TestAppleCaseInsensitivity(t *testing.T) { files: []string{}, err: false, }, + "simple with bzlmod extension": { + startingWD: "", + wantPath: "", + dirs: []string{}, + workspacePath: "/WORKSPACE.bzlmod", + files: []string{}, + err: false, + }, + "simple with MODULE.bazel": { + startingWD: "", + wantPath: "", + dirs: []string{}, + workspacePath: "/MODULE.bazel", + files: []string{}, + err: false, + }, "no workspace": { startingWD: "c/d", wantPath: "", @@ -53,6 +69,43 @@ func TestAppleCaseInsensitivity(t *testing.T) { files: []string{}, err: true, }, + "no workspace in workspace-named path": { + startingWD: "c/WORKSPACE", + wantPath: filepath.FromSlash("/a"), + dirs: []string{ + "a/b", + "c/WORKSPACE", + }, + workspacePath: "/a/WORKSPACE", + files: []string{}, + err: true, + }, + "no workspace in MODULE.bazel-named path": { + startingWD: "c/MODULE.bazel", + wantPath: "", + dirs: []string{ + "a/b", + "c/MODULE.bazel", + }, + workspacePath: "/a/WORKSPACE", + files: []string{}, + err: true, + }, + "workspace nested in workspace-named path": { + // this is intended to catch case-insensitive Macs but mimics the + // case-insensitive match with a case-sensitive match of the dir + // the "WORKSPACE" dirname should not early-quit the search, allowing + // us to find /c/MODULE.bazel + startingWD: "c/d/WORKSPACE", + wantPath: filepath.FromSlash("/c"), + dirs: []string{ + "a/b", + "c/d/WORKSPACE", + }, + workspacePath: "/c/MODULE.bazel", + files: []string{}, + err: false, + }, "nested workspace": { startingWD: "a/workspace", wantPath: "",