Skip to content

Commit

Permalink
modfile: update toolchain syntax
Browse files Browse the repository at this point in the history
Final revisions for Go 1.21: lock down the toolchain syntax to use
'toolchain default' instead of 'toolchain local', to avoid confusion
with 'GOTOOLCHAIN=local'; 'toolchain local' does not always mean
the same thing.

Also remove the prefix-go1.2.3 toolchain name form, leaving only
go1.2.3-suffix. There is no need to have two different forms, and it's
confusing.

For golang/go#57001.

Change-Id: I16623c796c620e98178deed899e28a00e85fcc21
Reviewed-on: https://go-review.googlesource.com/c/mod/+/500755
TryBot-Result: Gopher Robot <[email protected]>
Run-TryBot: Russ Cox <[email protected]>
Reviewed-by: Michael Matloob <[email protected]>
  • Loading branch information
rsc committed Jun 5, 2023
1 parent e81ad10 commit 2a1c06a
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions modfile/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,8 @@ func TestParseVersions(t *testing.T) {
{desc: "tool", input: "module m\ntoolchain go1.2\n", ok: true},
{desc: "tool1", input: "module m\ntoolchain go1.2.3\n", ok: true},
{desc: "tool2", input: "module m\ntoolchain go1.2rc1\n", ok: true},
{desc: "tool3", input: "module m\ntoolchain gccgo-go1.2rc1\n", ok: true},
{desc: "tool4", input: "module m\ntoolchain local\n", ok: true},
{desc: "tool3", input: "module m\ntoolchain go1.2rc1-gccgo\n", ok: true},
{desc: "tool4", input: "module m\ntoolchain default\n", ok: true},
{desc: "tool5", input: "module m\ntoolchain inconceivable!\n", ok: false, laxOK: true},
}
t.Run("Strict", func(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions modfile/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,9 @@ func parseToFile(file string, data []byte, fix VersionFixer, strict bool) (parse
var GoVersionRE = lazyregexp.New(`^([1-9][0-9]*)\.(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))?([a-z]+[0-9]+)?$`)
var laxGoVersionRE = lazyregexp.New(`^v?(([1-9][0-9]*)\.(0|[1-9][0-9]*))([^0-9].*)$`)

// Toolchains must be named beginning with `go1` or containing `-go1` as a substring,
// like "go1.20.3" or "gccgo-go1.20.3". As a special case, "local" is also permitted.
var ToolchainRE = lazyregexp.New(`^local$|(^|-)go1`)
// Toolchains must be named beginning with `go1`,
// like "go1.20.3" or "go1.20.3-gccgo". As a special case, "default" is also permitted.
var ToolchainRE = lazyregexp.New(`^default$|^go1($|\.)`)

func (f *File) add(errs *ErrorList, block *LineBlock, line *Line, verb string, args []string, fix VersionFixer, strict bool) {
// If strict is false, this module is a dependency.
Expand Down
2 changes: 1 addition & 1 deletion modfile/testdata/goline.golden
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
go 1.2.3

toolchain local
toolchain default
2 changes: 1 addition & 1 deletion modfile/testdata/goline.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
go 1.2.3
toolchain local
toolchain default
2 changes: 1 addition & 1 deletion modfile/testdata/work/goline.golden
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
go 1.2.3

toolchain local
toolchain default
2 changes: 1 addition & 1 deletion modfile/testdata/work/goline.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
go 1.2.3
toolchain local
toolchain default

0 comments on commit 2a1c06a

Please sign in to comment.