aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJay Conrod <jayconrod@google.com>2021-05-10 17:19:50 -0400
committerJay Conrod <jayconrod@google.com>2021-05-17 16:02:12 +0000
commitb1aff42900133e4fbc9b7d7c1af13c77e4f647b0 (patch)
treea0a98389f6da38bee974639904a0b7e359aa46a4 /src
parentbade680867c9b1eecc7b5d177ed94c455a72e50a (diff)
downloadgo-b1aff42900133e4fbc9b7d7c1af13c77e4f647b0.tar.xz
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>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/go/internal/modget/get.go8
-rw-r--r--src/cmd/go/testdata/script/mod_get_deprecate_install.txt21
2 files changed, 23 insertions, 6 deletions
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() {}