]> Cypherpunks.ru repositories - gostls13.git/commit
cmd/go: enable module mode without a main module when GO111MODULE=on
authorBryan C. Mills <bcmills@google.com>
Thu, 8 Nov 2018 15:29:40 +0000 (10:29 -0500)
committerBryan C. Mills <bcmills@google.com>
Thu, 29 Nov 2018 18:57:53 +0000 (18:57 +0000)
commitcdbd4d49d8b3595048ae63ac0f3891633470dfbe
tree5c022d3524572f5289af1d4b7070ec761eaf3a64
parenta2b4ac6cf29d31f1c927720712a25cda7bfbc682
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>
22 files changed:
src/cmd/go/internal/clean/clean.go
src/cmd/go/internal/envcmd/env.go
src/cmd/go/internal/load/pkg.go
src/cmd/go/internal/modcmd/edit.go
src/cmd/go/internal/modcmd/vendor.go
src/cmd/go/internal/modget/get.go
src/cmd/go/internal/modload/build.go
src/cmd/go/internal/modload/import.go
src/cmd/go/internal/modload/init.go
src/cmd/go/internal/modload/list.go
src/cmd/go/internal/modload/load.go
src/cmd/go/internal/modload/query.go
src/cmd/go/internal/modload/search.go
src/cmd/go/internal/modload/testgo.go [new file with mode: 0644]
src/cmd/go/testdata/mod/example.com_printversion_v0.1.0.txt [new file with mode: 0644]
src/cmd/go/testdata/mod/example.com_printversion_v1.0.0.txt [new file with mode: 0644]
src/cmd/go/testdata/mod/example.com_version_v1.0.0.txt [new file with mode: 0644]
src/cmd/go/testdata/mod/example.com_version_v1.0.1.txt [new file with mode: 0644]
src/cmd/go/testdata/mod/example.com_version_v1.1.0.txt [new file with mode: 0644]
src/cmd/go/testdata/script/mod_enabled.txt
src/cmd/go/testdata/script/mod_nomod.txt
src/cmd/go/testdata/script/mod_outside.txt [new file with mode: 0644]