Skip to content

Commit 5e1e3a0

Browse files
ronaudinhomatloob
authored andcommitted
cmd/go: show deprecation message on go run/install
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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent d9f9746 commit 5e1e3a0

8 files changed

+63
-1
lines changed

src/cmd/go/internal/load/pkg.go

+7
Original file line numberDiff line numberDiff line change
@@ -3322,6 +3322,13 @@ func PackagesAndErrorsOutsideModule(ctx context.Context, opts PackageOpts, args
33223322
return nil, fmt.Errorf("%s: %w", args[0], err)
33233323
}
33243324
rootMod := qrs[0].Mod
3325+
deprecation, err := modload.CheckDeprecation(ctx, rootMod)
3326+
if err != nil {
3327+
return nil, fmt.Errorf("%s: %w", args[0], err)
3328+
}
3329+
if deprecation != "" {
3330+
fmt.Fprintf(os.Stderr, "go: module %s is deprecated: %s\n", rootMod.Path, modload.ShortMessage(deprecation, ""))
3331+
}
33253332
data, err := modfetch.GoMod(ctx, rootMod.Path, rootMod.Version)
33263333
if err != nil {
33273334
return nil, fmt.Errorf("%s: %w", args[0], err)

src/cmd/go/testdata/mod/example.com_deprecated_a_v1.0.0.txt

+7
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@ module example.com/deprecated/a
1010
go 1.17
1111
-- a.go --
1212
package a
13+
14+
-- cmd/a/a.go --
15+
package main
16+
17+
import "fmt"
18+
19+
func main() { fmt.Println("[email protected]") }

src/cmd/go/testdata/mod/example.com_deprecated_a_v1.9.0.txt

+7
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,10 @@ module example.com/deprecated/a
1212
go 1.17
1313
-- a.go --
1414
package a
15+
16+
-- cmd/a/a.go --
17+
package main
18+
19+
import "fmt"
20+
21+
func main() { fmt.Println("[email protected]") }

src/cmd/go/testdata/mod/example.com_undeprecated_v1.0.0.txt

+7
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,10 @@ module example.com/undeprecated
1212
go 1.17
1313
-- undeprecated.go --
1414
package undeprecated
15+
16+
-- cmd/a/a.go --
17+
package main
18+
19+
import "fmt"
20+
21+
func main() { fmt.Println("[email protected]") }

src/cmd/go/testdata/mod/example.com_undeprecated_v1.0.1.txt

+7
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,10 @@ module example.com/undeprecated
1212
go 1.17
1313
-- undeprecated.go --
1414
package undeprecated
15+
16+
-- cmd/a/a.go --
17+
package main
18+
19+
import "fmt"
20+
21+
func main() { fmt.Println("[email protected]") }

src/cmd/go/testdata/script/mod_install_pkg_version.txt

+13
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,19 @@ env GO111MODULE=
182182
# Verifies #43278.
183183
go install -mod=readonly example.com/cmd/[email protected]
184184

185+
186+
# 'go install pkg@version' should show a deprecation message if the module is deprecated.
187+
env GO111MODULE=on
188+
go install example.com/deprecated/a/cmd/a@latest
189+
stderr '^go: module example.com/deprecated/a is deprecated: in example.com/deprecated/[email protected]$'
190+
go install example.com/deprecated/a/cmd/[email protected]
191+
stderr '^go: module example.com/deprecated/a is deprecated: in example.com/deprecated/[email protected]$'
192+
193+
# 'go install pkg@version' does not show a deprecation message if the module is no longer
194+
# deprecated in its latest version, even if the module is deprecated in its current version.
195+
go install example.com/undeprecated/cmd/[email protected]
196+
! stderr 'module.*is deprecated'
197+
185198
-- m/go.mod --
186199
module m
187200

src/cmd/go/testdata/script/mod_list_deprecated.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ require (
4747
example.com/undeprecated v1.0.0
4848
)
4949
-- go.sum --
50-
example.com/deprecated/a v1.9.0 h1:pRyvBIZheJpQVVnNW4Fdg8QuoqDgtkCreqZZbASV3BE=
50+
example.com/deprecated/a v1.9.0 h1:HeC7d0lb7umZa0vCCW+0W3WtBTulO+1Mr32m/Hwzeg8=
5151
example.com/deprecated/a v1.9.0/go.mod h1:Z1uUVshSY9kh6l/2hZ8oA9SBviX2yfaeEpcLDz6AZwY=
5252
example.com/undeprecated v1.0.0/go.mod h1:1qiRbdA9VzJXDqlG26Y41O5Z7YyO+jAD9do8XCZQ+Gg=

src/cmd/go/testdata/script/mod_run_pkg_version.txt

+14
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@ stdout '^[email protected]$'
8282
go run -mod=readonly example.com/cmd/[email protected]
8383
8484

85+
86+
# 'go run pkg@version' should show a deprecation message if the module is deprecated.
87+
go run example.com/deprecated/a/cmd/a@latest
88+
stderr '^go: module example.com/deprecated/a is deprecated: in example.com/deprecated/[email protected]$'
89+
90+
go run example.com/deprecated/a/cmd/[email protected]
91+
stderr '^go: module example.com/deprecated/a is deprecated: in example.com/deprecated/[email protected]$'
92+
93+
94+
# 'go run pkg@version' does not show a deprecation message if the module is no longer
95+
# deprecated in its latest version, even if the module is deprecated in its current version.
96+
go run example.com/undeprecated/cmd/[email protected]
97+
! stderr 'module.*is deprecated'
98+
8599
-- m/go.mod --
86100
module m
87101

0 commit comments

Comments
 (0)