mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/go: print deprecation notice for 'go get cmd'
The notice is shown when 'go get' is invoked with the -d flag, and the arguments match at least one main package. This reverts CL 274552. For #43684 Change-Id: I42e6731455f22988bf72dde1d5a76d197e9e3954 Reviewed-on: https://go-review.googlesource.com/c/go/+/305670 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
parent
d5b9dc1317
commit
254fb85c12
2 changed files with 47 additions and 3 deletions
|
|
@ -385,10 +385,32 @@ func runGet(ctx context.Context, cmd *base.Command, args []string) {
|
||||||
pkgs = append(pkgs, pkg)
|
pkgs = append(pkgs, pkg)
|
||||||
}
|
}
|
||||||
load.CheckPackageErrors(pkgs)
|
load.CheckPackageErrors(pkgs)
|
||||||
|
|
||||||
|
haveExe := false
|
||||||
|
for _, pkg := range pkgs {
|
||||||
|
if pkg.Name == "main" {
|
||||||
|
haveExe = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if haveExe {
|
||||||
|
fmt.Fprint(os.Stderr, "go get: installing executables with 'go get' in module mode is deprecated.")
|
||||||
|
var altMsg string
|
||||||
|
if modload.HasModRoot() {
|
||||||
|
altMsg = `
|
||||||
|
To adjust and download dependencies of the current module, use 'go get -d'.
|
||||||
|
To install using requirements of the current module, use 'go install'.
|
||||||
|
To install ignoring the current module, use 'go install' with a version,
|
||||||
|
like 'go install example.com/cmd@latest'.
|
||||||
|
`
|
||||||
|
} else {
|
||||||
|
altMsg = "\n\tUse 'go install pkg@version' instead.\n"
|
||||||
|
}
|
||||||
|
fmt.Fprint(os.Stderr, altMsg)
|
||||||
|
fmt.Fprintf(os.Stderr, "\tFor more information, see https://golang.org/doc/go-get-install-deprecation\n\tor run 'go help get' or 'go help install'.\n")
|
||||||
|
}
|
||||||
|
|
||||||
work.InstallPackages(ctx, pkgPatterns, pkgs)
|
work.InstallPackages(ctx, pkgPatterns, pkgs)
|
||||||
// TODO(#40276): After Go 1.16, print a deprecation notice when building and
|
|
||||||
// installing main packages. 'go install pkg' or 'go install pkg@version'
|
|
||||||
// should be used instead. Give the specific argument to use if possible.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !modload.HasModRoot() {
|
if !modload.HasModRoot() {
|
||||||
|
|
|
||||||
22
src/cmd/go/testdata/script/mod_get_deprecate_install.txt
vendored
Normal file
22
src/cmd/go/testdata/script/mod_get_deprecate_install.txt
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
[short] skip
|
||||||
|
|
||||||
|
env GO111MODULE=on
|
||||||
|
|
||||||
|
# 'go get' outside a module with an executable prints a deprecation message.
|
||||||
|
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
|
||||||
|
|
||||||
|
# '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
|
||||||
|
|
||||||
|
# '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'''
|
||||||
Loading…
Add table
Add a link
Reference in a new issue