mirror of
https://github.com/golang/go
synced 2024-09-15 22:20:06 +00: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)
|
load.CheckPackageErrors(pkgs)
|
||||||
|
|
||||||
haveExe := false
|
haveExternalExe := false
|
||||||
for _, pkg := range pkgs {
|
for _, pkg := range pkgs {
|
||||||
if pkg.Name == "main" {
|
if pkg.Name == "main" && pkg.Module != nil && pkg.Module.Path != modload.Target.Path {
|
||||||
haveExe = true
|
haveExternalExe = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if haveExe {
|
if haveExternalExe {
|
||||||
fmt.Fprint(os.Stderr, "go get: installing executables with 'go get' in module mode is deprecated.")
|
fmt.Fprint(os.Stderr, "go get: installing executables with 'go get' in module mode is deprecated.")
|
||||||
var altMsg string
|
var altMsg string
|
||||||
if modload.HasModRoot() {
|
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 '^go get: installing executables with ''go get'' in module mode is deprecated.$'
|
||||||
stderr 'Use ''go install pkg@version'' instead.'
|
stderr 'Use ''go install pkg@version'' instead.'
|
||||||
|
|
||||||
|
cp go.mod.orig go.mod
|
||||||
go mod init m
|
|
||||||
|
|
||||||
# 'go get' inside a module with a non-main package does not print a message.
|
# '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.
|
# This will stop building in the future, but it's the command we want to use.
|
||||||
go get rsc.io/quote
|
go get rsc.io/quote
|
||||||
! stderr deprecated
|
! stderr deprecated
|
||||||
|
cp go.mod.orig go.mod
|
||||||
|
|
||||||
# 'go get' inside a module with an executable prints a different
|
# 'go get' inside a module with an executable prints a different
|
||||||
# deprecation message.
|
# deprecation message.
|
||||||
go get example.com/cmd/a
|
go get example.com/cmd/a
|
||||||
stderr '^go get: installing executables with ''go get'' in module mode is deprecated.$'
|
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'''
|
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 a new issue