From: Jay Conrod Date: Mon, 10 May 2021 21:19:50 +0000 (-0400) Subject: cmd/go: don't print 'go get' deprecation notices in the main module X-Git-Tag: go1.17beta1~145 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b1aff42900133e4fbc9b7d7c1af13c77e4f647b0;p=gostls13.git 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 Run-TryBot: Jay Conrod TryBot-Result: Go Bot Reviewed-by: Bryan C. Mills --- diff --git a/src/cmd/go/internal/modget/get.go b/src/cmd/go/internal/modget/get.go index 3a24b6a2f7..2a7fe5226f 100644 --- a/src/cmd/go/internal/modget/get.go +++ b/src/cmd/go/internal/modget/get.go @@ -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() { diff --git a/src/cmd/go/testdata/script/mod_get_deprecate_install.txt b/src/cmd/go/testdata/script/mod_get_deprecate_install.txt index d832b5f2e8..63cd27a42d 100644 --- a/src/cmd/go/testdata/script/mod_get_deprecate_install.txt +++ b/src/cmd/go/testdata/script/mod_get_deprecate_install.txt @@ -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() {}