aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/load/pkg.go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2018-11-08 10:29:40 -0500
committerBryan C. Mills <bcmills@google.com>2018-11-29 18:57:53 +0000
commitcdbd4d49d8b3595048ae63ac0f3891633470dfbe (patch)
tree5c022d3524572f5289af1d4b7070ec761eaf3a64 /src/cmd/go/internal/load/pkg.go
parenta2b4ac6cf29d31f1c927720712a25cda7bfbc682 (diff)
downloadgo-cdbd4d49d8b3595048ae63ac0f3891633470dfbe.tar.gz
go-cdbd4d49d8b3595048ae63ac0f3891633470dfbe.zip
cmd/go: enable module mode without a main module when GO111MODULE=on
This is as minimal a change as I could comfortably make to enable 'go get' outside of a module for 1.12. In general, commands invoked in module mode while outside of a module operate as though they are in a module with an initially-empty go.mod file. ('go env GOMOD' reports os.DevNull.) Commands that operate on the current directory (such as 'go list' and 'go get -u' without arguments) fail: without a module definition, we don't know the package path. Likewise, commands whose sole purpose is to write files within the main module (such as 'go mod edit' and 'go mod vendor') fail, since we don't know where to write their output. Since the go.sum file for the main module is authoritative, we do not check go.sum files when operating outside of a module. I plan to revisit that when the tree opens for 1.13. We may also want to revisit the behavior of 'go list': it would be useful to be able to query individual packages (and dependencies of those packages) within versioned modules, but today we only allow versioned paths in conjunction with the '-m' flag. Fixes #24250 RELNOTE=yes Change-Id: I028c323ddea27693a92ad0aa4a6a55d5e3f43f2c Reviewed-on: https://go-review.googlesource.com/c/148517 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/cmd/go/internal/load/pkg.go')
-rw-r--r--src/cmd/go/internal/load/pkg.go4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go
index a64bab1479..72a3d70607 100644
--- a/src/cmd/go/internal/load/pkg.go
+++ b/src/cmd/go/internal/load/pkg.go
@@ -1515,7 +1515,9 @@ func (p *Package) load(stk *ImportStack, bp *build.Package, err error) {
}
if cfg.ModulesEnabled {
- p.Module = ModPackageModuleInfo(p.ImportPath)
+ if !p.Internal.CmdlineFiles {
+ p.Module = ModPackageModuleInfo(p.ImportPath)
+ }
if p.Name == "main" {
p.Internal.BuildInfo = ModPackageBuildInfo(p.ImportPath, p.Deps)
}