aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/doc
diff options
context:
space:
mode:
authorJay Conrod <jayconrod@google.com>2019-10-10 10:26:21 -0400
committerJay Conrod <jayconrod@google.com>2019-10-10 19:07:50 +0000
commit68395a66f9fece387701e1450e3d7a8fa91fb76e (patch)
tree302e4c4e83a64035ab7c638fa6a236e23905f794 /src/cmd/doc
parent46b7557836c8a7f8a481946eebbf4a1b0947b332 (diff)
downloadgo-68395a66f9fece387701e1450e3d7a8fa91fb76e.tar.xz
cmd/go: forbid module pattern 'all' when outside a module
Also, in cmd/doc, avoid calling 'go list -m all' when in module mode outside a module since it's now an error. Fixes #32027 Change-Id: I7224c7fdf7e950bce6c058ab2a5837c27ba3b899 Reviewed-on: https://go-review.googlesource.com/c/go/+/200297 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/doc')
-rw-r--r--src/cmd/doc/dirs.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/cmd/doc/dirs.go b/src/cmd/doc/dirs.go
index c6f5cd9af8..0f990f7017 100644
--- a/src/cmd/doc/dirs.go
+++ b/src/cmd/doc/dirs.go
@@ -162,7 +162,15 @@ func findCodeRoots() []Dir {
// Check for use of modules by 'go env GOMOD',
// which reports a go.mod file path if modules are enabled.
stdout, _ := exec.Command("go", "env", "GOMOD").Output()
- usingModules = len(bytes.TrimSpace(stdout)) > 0
+ gomod := string(bytes.TrimSpace(stdout))
+ usingModules = len(gomod) > 0
+ if gomod == os.DevNull {
+ // Modules are enabled, but the working directory is outside any module.
+ // We can still access std, cmd, and packages specified as source files
+ // on the command line, but there are no module roots.
+ // Avoid 'go list -m all' below, since it will not work.
+ return list
+ }
}
if !usingModules {