mirror of
https://github.com/golang/go
synced 2024-11-18 10:14:45 -07:00
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 <bcmills@google.com>
This commit is contained in:
parent
eaeb383209
commit
91381dc0ae
@ -473,7 +473,7 @@ func TestNoMainModule(t *testing.T) {
|
|||||||
cmd.Stderr = &stderr
|
cmd.Stderr = &stderr
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatalf("godoc command failed: %v\nstderr=%q", err, stderr.String())
|
||||||
}
|
}
|
||||||
if strings.Contains(stderr.String(), "go mod download") {
|
if strings.Contains(stderr.String(), "go mod download") {
|
||||||
t.Errorf("stderr contains 'go mod download', is that intentional?\nstderr=%q", stderr.String())
|
t.Errorf("stderr contains 'go mod download', is that intentional?\nstderr=%q", stderr.String())
|
||||||
|
@ -222,7 +222,7 @@ func main() {
|
|||||||
fillModuleCache(os.Stderr, goModFile)
|
fillModuleCache(os.Stderr, goModFile)
|
||||||
|
|
||||||
// Determine modules in the build list.
|
// Determine modules in the build list.
|
||||||
mods, err := buildList()
|
mods, err := buildList(goModFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "failed to determine the build list of the main module: %v", err)
|
fmt.Fprintf(os.Stderr, "failed to determine the build list of the main module: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@ -456,7 +456,12 @@ func fillModuleCache(w io.Writer, goMod string) {
|
|||||||
// in module mode.
|
// in module mode.
|
||||||
//
|
//
|
||||||
// See https://golang.org/cmd/go/#hdr-The_main_module_and_the_build_list.
|
// See https://golang.org/cmd/go/#hdr-The_main_module_and_the_build_list.
|
||||||
func buildList() ([]mod, error) {
|
func buildList(goMod string) ([]mod, error) {
|
||||||
|
if goMod == os.DevNull {
|
||||||
|
// Empty build list.
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
out, err := exec.Command("go", "list", "-m", "-json", "all").Output()
|
out, err := exec.Command("go", "list", "-m", "-json", "all").Output()
|
||||||
if ee := (*exec.ExitError)(nil); xerrors.As(err, &ee) {
|
if ee := (*exec.ExitError)(nil); xerrors.As(err, &ee) {
|
||||||
return nil, fmt.Errorf("go command exited unsuccessfully: %v\n%s", ee.ProcessState.String(), ee.Stderr)
|
return nil, fmt.Errorf("go command exited unsuccessfully: %v\n%s", ee.ProcessState.String(), ee.Stderr)
|
||||||
|
Loading…
Reference in New Issue
Block a user