Add check for deprecations in PackagesAndErrorsOutsideModule. This affects go run/install outside module when run in module-aware mode.
Fixes #59230
Change-Id: I106df36a856894fb1b634decfa812e31cf88fe74
Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest
Reviewed-on: https://go-review.googlesource.com/c/go/+/528775
Reviewed-by: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
return nil, fmt.Errorf("%s: %w", args[0], err)
}
rootMod := qrs[0].Mod
+ deprecation, err := modload.CheckDeprecation(ctx, rootMod)
+ if err != nil {
+ return nil, fmt.Errorf("%s: %w", args[0], err)
+ }
+ if deprecation != "" {
+ fmt.Fprintf(os.Stderr, "go: module %s is deprecated: %s\n", rootMod.Path, modload.ShortMessage(deprecation, ""))
+ }
data, err := modfetch.GoMod(ctx, rootMod.Path, rootMod.Version)
if err != nil {
return nil, fmt.Errorf("%s: %w", args[0], err)
go 1.17
-- a.go --
package a
+
+-- cmd/a/a.go --
+package main
+
+import "fmt"
+
+func main() { fmt.Println("a@v1.0.0") }
go 1.17
-- a.go --
package a
+
+-- cmd/a/a.go --
+package main
+
+import "fmt"
+
+func main() { fmt.Println("a@v1.9.0") }
go 1.17
-- undeprecated.go --
package undeprecated
+
+-- cmd/a/a.go --
+package main
+
+import "fmt"
+
+func main() { fmt.Println("a@v1.0.0") }
go 1.17
-- undeprecated.go --
package undeprecated
+
+-- cmd/a/a.go --
+package main
+
+import "fmt"
+
+func main() { fmt.Println("a@v1.0.1") }
# Verifies #43278.
go install -mod=readonly example.com/cmd/a@v1.0.0
+
+# 'go install pkg@version' should show a deprecation message if the module is deprecated.
+env GO111MODULE=on
+go install example.com/deprecated/a/cmd/a@latest
+stderr '^go: module example.com/deprecated/a is deprecated: in example.com/deprecated/a@v1.9.0$'
+go install example.com/deprecated/a/cmd/a@v1.0.0
+stderr '^go: module example.com/deprecated/a is deprecated: in example.com/deprecated/a@v1.9.0$'
+
+# 'go install pkg@version' does not show a deprecation message if the module is no longer
+# deprecated in its latest version, even if the module is deprecated in its current version.
+go install example.com/undeprecated/cmd/a@v1.0.0
+! stderr 'module.*is deprecated'
+
-- m/go.mod --
module m
example.com/undeprecated v1.0.0
)
-- go.sum --
-example.com/deprecated/a v1.9.0 h1:pRyvBIZheJpQVVnNW4Fdg8QuoqDgtkCreqZZbASV3BE=
+example.com/deprecated/a v1.9.0 h1:HeC7d0lb7umZa0vCCW+0W3WtBTulO+1Mr32m/Hwzeg8=
example.com/deprecated/a v1.9.0/go.mod h1:Z1uUVshSY9kh6l/2hZ8oA9SBviX2yfaeEpcLDz6AZwY=
example.com/undeprecated v1.0.0/go.mod h1:1qiRbdA9VzJXDqlG26Y41O5Z7YyO+jAD9do8XCZQ+Gg=
go run -mod=readonly example.com/cmd/a@v1.0.0
stdout '^a@v1.0.0$'
+
+# 'go run pkg@version' should show a deprecation message if the module is deprecated.
+go run example.com/deprecated/a/cmd/a@latest
+stderr '^go: module example.com/deprecated/a is deprecated: in example.com/deprecated/a@v1.9.0$'
+stdout '^a@v1.9.0$'
+go run example.com/deprecated/a/cmd/a@v1.0.0
+stderr '^go: module example.com/deprecated/a is deprecated: in example.com/deprecated/a@v1.9.0$'
+stdout '^a@v1.0.0$'
+
+# 'go run pkg@version' does not show a deprecation message if the module is no longer
+# deprecated in its latest version, even if the module is deprecated in its current version.
+go run example.com/undeprecated/cmd/a@v1.0.0
+! stderr 'module.*is deprecated'
+
-- m/go.mod --
module m