mirror of
https://github.com/golang/go
synced 2024-11-26 14:46:47 -07:00
cmd/go: don't print 'go get' deprecation notices in the main module
If a user runs 'go get example.com/cmd' for a package in the main module, it's more likely they intend to fill in missing dependencies for that package (especially with -u). If the intent were only to build and install, 'go install example.com/cmd' would be a better choice. For #43684 Resolving a comment on CL 305670. Change-Id: I5c80ffdcdb3425b448f2f49cc20b07a18cb2bbe9 Reviewed-on: https://go-review.googlesource.com/c/go/+/318570 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
parent
bade680867
commit
b1aff42900
@ -386,14 +386,14 @@ func runGet(ctx context.Context, cmd *base.Command, args []string) {
|
||||
}
|
||||
load.CheckPackageErrors(pkgs)
|
||||
|
||||
haveExe := false
|
||||
haveExternalExe := false
|
||||
for _, pkg := range pkgs {
|
||||
if pkg.Name == "main" {
|
||||
haveExe = true
|
||||
if pkg.Name == "main" && pkg.Module != nil && pkg.Module.Path != modload.Target.Path {
|
||||
haveExternalExe = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if haveExe {
|
||||
if haveExternalExe {
|
||||
fmt.Fprint(os.Stderr, "go get: installing executables with 'go get' in module mode is deprecated.")
|
||||
var altMsg string
|
||||
if modload.HasModRoot() {
|
||||
|
@ -7,16 +7,33 @@ go get example.com/cmd/a
|
||||
stderr '^go get: installing executables with ''go get'' in module mode is deprecated.$'
|
||||
stderr 'Use ''go install pkg@version'' instead.'
|
||||
|
||||
|
||||
go mod init m
|
||||
cp go.mod.orig go.mod
|
||||
|
||||
# 'go get' inside a module with a non-main package does not print a message.
|
||||
# This will stop building in the future, but it's the command we want to use.
|
||||
go get rsc.io/quote
|
||||
! stderr deprecated
|
||||
cp go.mod.orig go.mod
|
||||
|
||||
# 'go get' inside a module with an executable prints a different
|
||||
# deprecation message.
|
||||
go get example.com/cmd/a
|
||||
stderr '^go get: installing executables with ''go get'' in module mode is deprecated.$'
|
||||
stderr 'To adjust and download dependencies of the current module, use ''go get -d'''
|
||||
cp go.mod.orig go.mod
|
||||
|
||||
# 'go get' should not print a warning for a main package inside the main module.
|
||||
# The intent is most likely to update the dependencies of that package.
|
||||
# 'go install' would be used otherwise.
|
||||
go get m
|
||||
! stderr .
|
||||
cp go.mod.orig go.mod
|
||||
|
||||
-- go.mod.orig --
|
||||
module m
|
||||
|
||||
go 1.17
|
||||
-- main.go --
|
||||
package main
|
||||
|
||||
func main() {}
|
||||
|
Loading…
Reference in New Issue
Block a user