Skip to content

Commit 91381dc

Browse files
committed
cmd/godoc: don't execute go list -m all when GOMOD is /dev/null
When the GOMOD value is the operating system's null device, there isn't a main module. Return an empty build list right away, since running 'go list -m all' in Go 1.14 will cause a "cannot match "all": working directory is not part of a module" error. Fixes golang/go#35690 Updates golang/go#35728 Change-Id: I024ca3b7d774835140ce4a1625133aff6554a533 Reviewed-on: https://go-review.googlesource.com/c/tools/+/208258 Reviewed-by: Bryan C. Mills <[email protected]>
1 parent eaeb383 commit 91381dc

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

cmd/godoc/godoc_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ func TestNoMainModule(t *testing.T) {
473473
cmd.Stderr = &stderr
474474
err = cmd.Run()
475475
if err != nil {
476-
t.Fatal(err)
476+
t.Fatalf("godoc command failed: %v\nstderr=%q", err, stderr.String())
477477
}
478478
if strings.Contains(stderr.String(), "go mod download") {
479479
t.Errorf("stderr contains 'go mod download', is that intentional?\nstderr=%q", stderr.String())

cmd/godoc/main.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func main() {
222222
fillModuleCache(os.Stderr, goModFile)
223223

224224
// Determine modules in the build list.
225-
mods, err := buildList()
225+
mods, err := buildList(goModFile)
226226
if err != nil {
227227
fmt.Fprintf(os.Stderr, "failed to determine the build list of the main module: %v", err)
228228
os.Exit(1)
@@ -456,7 +456,12 @@ func fillModuleCache(w io.Writer, goMod string) {
456456
// in module mode.
457457
//
458458
// See https://golang.org/cmd/go/#hdr-The_main_module_and_the_build_list.
459-
func buildList() ([]mod, error) {
459+
func buildList(goMod string) ([]mod, error) {
460+
if goMod == os.DevNull {
461+
// Empty build list.
462+
return nil, nil
463+
}
464+
460465
out, err := exec.Command("go", "list", "-m", "-json", "all").Output()
461466
if ee := (*exec.ExitError)(nil); xerrors.As(err, &ee) {
462467
return nil, fmt.Errorf("go command exited unsuccessfully: %v\n%s", ee.ProcessState.String(), ee.Stderr)

0 commit comments

Comments
 (0)