cmd: vendor version error message changes from x/mod

For golang/go#61888

Change-Id: I254fe559f25ac643e842a935954d18744ae87b0b
Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest
Reviewed-on: https://go-review.googlesource.com/c/go/+/560855
Reviewed-by: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
Sam Thanawalla 2024-02-02 19:20:06 +00:00
parent 210f051d6b
commit 4aaa550ff5
5 changed files with 9 additions and 53 deletions

View File

@ -6,7 +6,7 @@ require (
github.com/google/pprof v0.0.0-20230811205829-9131a7e9cc17 github.com/google/pprof v0.0.0-20230811205829-9131a7e9cc17
golang.org/x/arch v0.7.0 golang.org/x/arch v0.7.0
golang.org/x/build v0.0.0-20240201175143-3ee44a092755 golang.org/x/build v0.0.0-20240201175143-3ee44a092755
golang.org/x/mod v0.14.0 golang.org/x/mod v0.15.1-0.20240207185259-766dc5df63e3
golang.org/x/sync v0.6.0 golang.org/x/sync v0.6.0
golang.org/x/sys v0.16.1-0.20240110015235-f69d32aa924f golang.org/x/sys v0.16.1-0.20240110015235-f69d32aa924f
golang.org/x/telemetry v0.0.0-20240131160148-1cb064e7d4f2 golang.org/x/telemetry v0.0.0-20240131160148-1cb064e7d4f2

View File

@ -10,8 +10,8 @@ golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc=
golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/build v0.0.0-20240201175143-3ee44a092755 h1:irSM9p93GT4I3+Pu/grZlkwIjrXA3GfyKwlSosVbmtU= golang.org/x/build v0.0.0-20240201175143-3ee44a092755 h1:irSM9p93GT4I3+Pu/grZlkwIjrXA3GfyKwlSosVbmtU=
golang.org/x/build v0.0.0-20240201175143-3ee44a092755/go.mod h1:RHSzqFUzT4+buJlGik6WptO5NxLQiR/ewD2uz3fgWuA= golang.org/x/build v0.0.0-20240201175143-3ee44a092755/go.mod h1:RHSzqFUzT4+buJlGik6WptO5NxLQiR/ewD2uz3fgWuA=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= golang.org/x/mod v0.15.1-0.20240207185259-766dc5df63e3 h1:/p/VemLWiTsjHqHwME1Iu+xIu8s9fBtwBk8bU/ejA1A=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/mod v0.15.1-0.20240207185259-766dc5df63e3/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.16.1-0.20240110015235-f69d32aa924f h1:GvGFYRZ5kIldzXQj3UmUiUTMe5spPODuLKQvP38A+Qc= golang.org/x/sys v0.16.1-0.20240110015235-f69d32aa924f h1:GvGFYRZ5kIldzXQj3UmUiUTMe5spPODuLKQvP38A+Qc=

View File

@ -308,6 +308,7 @@ var laxGoVersionRE = lazyregexp.New(`^v?(([1-9][0-9]*)\.(0|[1-9][0-9]*))([^0-9].
// Toolchains must be named beginning with `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. // like "go1.20.3" or "go1.20.3-gccgo". As a special case, "default" is also permitted.
// TODO(samthanawalla): Replace regex with https://pkg.go.dev/go/version#IsValid in 1.23+
var ToolchainRE = lazyregexp.New(`^default$|^go1($|\.)`) var ToolchainRE = lazyregexp.New(`^default$|^go1($|\.)`)
func (f *File) add(errs *ErrorList, block *LineBlock, line *Line, verb string, args []string, fix VersionFixer, strict bool) { func (f *File) add(errs *ErrorList, block *LineBlock, line *Line, verb string, args []string, fix VersionFixer, strict bool) {
@ -384,7 +385,7 @@ func (f *File) add(errs *ErrorList, block *LineBlock, line *Line, verb string, a
errorf("toolchain directive expects exactly one argument") errorf("toolchain directive expects exactly one argument")
return return
} else if strict && !ToolchainRE.MatchString(args[0]) { } else if strict && !ToolchainRE.MatchString(args[0]) {
errorf("invalid toolchain version '%s': must match format go1.23.0 or local", args[0]) errorf("invalid toolchain version '%s': must match format go1.23.0 or default", args[0])
return return
} }
f.Toolchain = &Toolchain{Syntax: line} f.Toolchain = &Toolchain{Syntax: line}
@ -630,7 +631,7 @@ func (f *WorkFile) add(errs *ErrorList, line *Line, verb string, args []string,
errorf("go directive expects exactly one argument") errorf("go directive expects exactly one argument")
return return
} else if !GoVersionRE.MatchString(args[0]) { } else if !GoVersionRE.MatchString(args[0]) {
errorf("invalid go version '%s': must match format 1.23", args[0]) errorf("invalid go version '%s': must match format 1.23.0", args[0])
return return
} }
@ -646,7 +647,7 @@ func (f *WorkFile) add(errs *ErrorList, line *Line, verb string, args []string,
errorf("toolchain directive expects exactly one argument") errorf("toolchain directive expects exactly one argument")
return return
} else if !ToolchainRE.MatchString(args[0]) { } else if !ToolchainRE.MatchString(args[0]) {
errorf("invalid toolchain version '%s': must match format go1.23 or local", args[0]) errorf("invalid toolchain version '%s': must match format go1.23.0 or default", args[0])
return return
} }

View File

@ -8,7 +8,6 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"path"
"strings" "strings"
"sync" "sync"
"sync/atomic" "sync/atomic"
@ -193,51 +192,7 @@ func (c *Client) SetGONOSUMDB(list string) {
var ErrGONOSUMDB = errors.New("skipped (listed in GONOSUMDB)") var ErrGONOSUMDB = errors.New("skipped (listed in GONOSUMDB)")
func (c *Client) skip(target string) bool { func (c *Client) skip(target string) bool {
return globsMatchPath(c.nosumdb, target) return module.MatchPrefixPatterns(c.nosumdb, target)
}
// globsMatchPath reports whether any path prefix of target
// matches one of the glob patterns (as defined by path.Match)
// in the comma-separated globs list.
// It ignores any empty or malformed patterns in the list.
func globsMatchPath(globs, target string) bool {
for globs != "" {
// Extract next non-empty glob in comma-separated list.
var glob string
if i := strings.Index(globs, ","); i >= 0 {
glob, globs = globs[:i], globs[i+1:]
} else {
glob, globs = globs, ""
}
if glob == "" {
continue
}
// A glob with N+1 path elements (N slashes) needs to be matched
// against the first N+1 path elements of target,
// which end just before the N+1'th slash.
n := strings.Count(glob, "/")
prefix := target
// Walk target, counting slashes, truncating at the N+1'th slash.
for i := 0; i < len(target); i++ {
if target[i] == '/' {
if n == 0 {
prefix = target[:i]
break
}
n--
}
}
if n > 0 {
// Not enough prefix elements.
continue
}
matched, _ := path.Match(glob, prefix)
if matched {
return true
}
}
return false
} }
// Lookup returns the go.sum lines for the given module path and version. // Lookup returns the go.sum lines for the given module path and version.

View File

@ -26,7 +26,7 @@ golang.org/x/arch/x86/x86asm
# golang.org/x/build v0.0.0-20240201175143-3ee44a092755 # golang.org/x/build v0.0.0-20240201175143-3ee44a092755
## explicit; go 1.21 ## explicit; go 1.21
golang.org/x/build/relnote golang.org/x/build/relnote
# golang.org/x/mod v0.14.0 # golang.org/x/mod v0.15.1-0.20240207185259-766dc5df63e3
## explicit; go 1.18 ## explicit; go 1.18
golang.org/x/mod/internal/lazyregexp golang.org/x/mod/internal/lazyregexp
golang.org/x/mod/modfile golang.org/x/mod/modfile