]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: don't print 'go get' deprecation notices in the main module
authorJay Conrod <jayconrod@google.com>
Mon, 10 May 2021 21:19:50 +0000 (17:19 -0400)
committerJay Conrod <jayconrod@google.com>
Mon, 17 May 2021 16:02:12 +0000 (16:02 +0000)
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>
src/cmd/go/internal/modget/get.go
src/cmd/go/testdata/script/mod_get_deprecate_install.txt

index 3a24b6a2f7e16bd53e743489bc4ce6e7a3b8ce22..2a7fe5226fd136ff0077b0228e1a84c0233282c9 100644 (file)
@@ -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() {
index d832b5f2e80a6dd3453da49dbe276bea0ebaa7e8..63cd27a42d2bc76911d0e36f589adb4f97259f22 100644 (file)
@@ -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() {}