Skip to content

Commit 3c764ba

Browse files
author
Jay Conrod
committed
cmd/go: write go.mod requirements more consistently for go 1.17+
If go.mod declares 1.17 or higher, when the go command rewrites go.mod (for example, after 'go mod tidy'), it will be more consistent about moving requirements in two blocks, one containing only direct requirements, and one containing only indirect requirements. The go command will not move requirements into or out of a block with comments. It may still update versions and "// indirect" comments, and it may delete unneeded requirements though. Fixes #47563 Fixes #47733 Change-Id: Ia6fb3e302be53097893abf01aa7cea60ac7b069a Reviewed-on: https://go-review.googlesource.com/c/go/+/343432 Trust: Jay Conrod <[email protected]> Run-TryBot: Jay Conrod <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 6268468 commit 3c764ba

File tree

9 files changed

+266
-152
lines changed

9 files changed

+266
-152
lines changed

src/cmd/go.mod

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ go 1.18
44

55
require (
66
github.com/google/pprof v0.0.0-20210827144239-02619b876842
7-
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639 // indirect
87
golang.org/x/arch v0.0.0-20210901143047-ebb09ed340f1
9-
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
10-
golang.org/x/mod v0.5.1-0.20210830214625-1b1db11ec8f4
11-
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e // indirect
8+
golang.org/x/mod v0.5.1-0.20210913215816-37dd6891021a
129
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b
1310
golang.org/x/tools v0.1.6-0.20210904010709-360456621443
11+
)
12+
13+
require (
14+
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639 // indirect
15+
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
16+
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e // indirect
1417
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
1518
)

src/cmd/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ golang.org/x/arch v0.0.0-20210901143047-ebb09ed340f1 h1:MwxAfiDvuwX8Nnnc6iRDhzyM
99
golang.org/x/arch v0.0.0-20210901143047-ebb09ed340f1/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
1010
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
1111
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
12-
golang.org/x/mod v0.5.1-0.20210830214625-1b1db11ec8f4 h1:7Qds88gNaRx0Dz/1wOwXlR7asekh1B1u26wEwN6FcEI=
13-
golang.org/x/mod v0.5.1-0.20210830214625-1b1db11ec8f4/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
12+
golang.org/x/mod v0.5.1-0.20210913215816-37dd6891021a h1:55PVa91KndtPGH2lus5l2gDZqoO/x+Oa5CV0lVf8Ij8=
13+
golang.org/x/mod v0.5.1-0.20210913215816-37dd6891021a/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
1414
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1515
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e h1:XMgFehsDnnLGtjvjOfqWSUzt0alpTR1RSEuznObga2c=
1616
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

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

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ go mod edit -go=1.17 u/go.mod
202202
go mod edit -go=1.17 w/go.mod
203203
go mod edit -go=1.17 x/go.mod
204204
go mod edit -go=1.17
205-
cp go.mod go.mod.orig
205+
cmp go.mod go.mod.beforetidy
206206
go mod tidy
207-
cmp go.mod go.mod.orig
207+
cmp go.mod go.mod.aftertidy
208208

209209
# With lazy loading, 'go list all' with neither -mod=vendor nor -test should
210210
# match -mod=vendor without -test in 1.15.
@@ -466,3 +466,66 @@ module example.com/x
466466
go 1.15
467467
-- x/x.go --
468468
package x
469+
-- go.mod.beforetidy --
470+
module example.com/main
471+
472+
// Note: this go.mod file initially specifies go 1.15,
473+
// but includes some redundant roots so that it
474+
// also already obeys the 1.17 lazy loading invariants.
475+
go 1.17
476+
477+
require (
478+
example.com/a v0.1.0
479+
example.com/b v0.1.0 // indirect
480+
example.com/q v0.1.0
481+
example.com/r v0.1.0 // indirect
482+
example.com/t v0.1.0
483+
example.com/u v0.1.0 // indirect
484+
)
485+
486+
replace (
487+
example.com/a v0.1.0 => ./a
488+
example.com/b v0.1.0 => ./b
489+
example.com/c v0.1.0 => ./c
490+
example.com/d v0.1.0 => ./d
491+
example.com/q v0.1.0 => ./q
492+
example.com/r v0.1.0 => ./r
493+
example.com/s v0.1.0 => ./s
494+
example.com/t v0.1.0 => ./t
495+
example.com/u v0.1.0 => ./u
496+
example.com/w v0.1.0 => ./w
497+
example.com/x v0.1.0 => ./x
498+
)
499+
-- go.mod.aftertidy --
500+
module example.com/main
501+
502+
// Note: this go.mod file initially specifies go 1.15,
503+
// but includes some redundant roots so that it
504+
// also already obeys the 1.17 lazy loading invariants.
505+
go 1.17
506+
507+
require (
508+
example.com/a v0.1.0
509+
example.com/q v0.1.0
510+
example.com/t v0.1.0
511+
)
512+
513+
require (
514+
example.com/b v0.1.0 // indirect
515+
example.com/r v0.1.0 // indirect
516+
example.com/u v0.1.0 // indirect
517+
)
518+
519+
replace (
520+
example.com/a v0.1.0 => ./a
521+
example.com/b v0.1.0 => ./b
522+
example.com/c v0.1.0 => ./c
523+
example.com/d v0.1.0 => ./d
524+
example.com/q v0.1.0 => ./q
525+
example.com/r v0.1.0 => ./r
526+
example.com/s v0.1.0 => ./s
527+
example.com/t v0.1.0 => ./t
528+
example.com/u v0.1.0 => ./u
529+
example.com/w v0.1.0 => ./w
530+
example.com/x v0.1.0 => ./x
531+
)

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ require (
8383
package x
8484
import _ "rsc.io/quote"
8585
-- go.mod.crlf --
86-
module m
87-
88-
go 1.14
89-
90-
require (
91-
rsc.io/quote v1.5.2
92-
rsc.io/testonly v1.0.0 // indirect
93-
)
86+
module m
87+
88+
go 1.14
89+
90+
require (
91+
rsc.io/quote v1.5.2
92+
rsc.io/testonly v1.0.0 // indirect
93+
)
9494
-- go.mod.unsorted --
9595
module m
9696

@@ -141,10 +141,10 @@ module m
141141

142142
go $goversion
143143

144+
require rsc.io/quote v1.5.2
145+
144146
require (
145-
rsc.io/quote v1.5.2
147+
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect
146148
rsc.io/sampler v1.3.0 // indirect
147149
rsc.io/testonly v1.0.0 // indirect
148150
)
149-
150-
require golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,9 @@ go 1.17
7272

7373
replace example.net/indirect v0.1.0 => ./indirect
7474

75-
require (
76-
example.net/ambiguous/nested v0.1.0 // indirect
77-
example.net/indirect v0.1.0
78-
)
75+
require example.net/indirect v0.1.0
76+
77+
require example.net/ambiguous/nested v0.1.0 // indirect
7978
-- all-m.txt --
8079
example.com/m
8180
example.net/ambiguous v0.1.0

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,9 @@ replace (
9797
example.net/requireincompatible v0.1.0 => ./requireincompatible
9898
)
9999

100-
require (
101-
example.com/retract/incompatible v1.0.0 // indirect
102-
example.net/lazy v0.1.0
103-
)
100+
require example.net/lazy v0.1.0
101+
102+
require example.com/retract/incompatible v1.0.0 // indirect
104103
-- incompatible.go --
105104
package incompatible
106105

0 commit comments

Comments
 (0)