aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2024-05-08 20:41:33 -0400
committerGopher Robot <gobot@golang.org>2024-05-14 18:34:56 +0000
commitca5fc8de65bfd30f6eb66a7bd45945956c3812e8 (patch)
treef56dc4e6f13d5dbdc5cd39e0ca94be9db7a6671b /src
parent2cc42f73287e3ad7a11d7296762b2b9fed3a2447 (diff)
downloadgo-ca5fc8de65bfd30f6eb66a7bd45945956c3812e8.tar.gz
go-ca5fc8de65bfd30f6eb66a7bd45945956c3812e8.zip
cmd/vendor: pull in x/mod/modfile godebug changes
go get golang.org/x/mod@c0bdc7bd go mod tidy go mod vendor Pulls in CL 584300. For #65573. Change-Id: Ia8ec86e2ee049b911fcf09d57f83972786b0470d Reviewed-on: https://go-review.googlesource.com/c/go/+/584475 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/go.mod2
-rw-r--r--src/cmd/go.sum4
-rw-r--r--src/cmd/vendor/golang.org/x/mod/modfile/rule.go106
-rw-r--r--src/cmd/vendor/golang.org/x/mod/modfile/work.go52
-rw-r--r--src/cmd/vendor/modules.txt2
5 files changed, 158 insertions, 8 deletions
diff --git a/src/cmd/go.mod b/src/cmd/go.mod
index 6c5b5c46ea..7773088514 100644
--- a/src/cmd/go.mod
+++ b/src/cmd/go.mod
@@ -6,7 +6,7 @@ require (
github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5
golang.org/x/arch v0.7.0
golang.org/x/build v0.0.0-20240222153247-cf4ed81bb19f
- golang.org/x/mod v0.17.1-0.20240507203540-6686f416970d
+ golang.org/x/mod v0.17.1-0.20240514174713-c0bdc7bd01c9
golang.org/x/sync v0.7.0
golang.org/x/sys v0.20.0
golang.org/x/telemetry v0.0.0-20240510223629-51e8b5d718eb
diff --git a/src/cmd/go.sum b/src/cmd/go.sum
index 3e0b99dc67..a53cc50859 100644
--- a/src/cmd/go.sum
+++ b/src/cmd/go.sum
@@ -26,8 +26,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/build v0.0.0-20240222153247-cf4ed81bb19f h1:XQ2eu0I26WsNCKQkRehp+5mwjjChw94trD9LT8LLSq0=
golang.org/x/build v0.0.0-20240222153247-cf4ed81bb19f/go.mod h1:HTqTCkubWT8epEK9hDWWGkoOOB7LGSrU1qvWZCSwO50=
-golang.org/x/mod v0.17.1-0.20240507203540-6686f416970d h1:QS9b5Jvh12iuDV+eYRspS3+7Fn6wOTYI6EAHdeGEsmY=
-golang.org/x/mod v0.17.1-0.20240507203540-6686f416970d/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
+golang.org/x/mod v0.17.1-0.20240514174713-c0bdc7bd01c9 h1:EfMABMgrJ8+hRjLvhUzJkLKgFv3lYAglGXczg5ggNyk=
+golang.org/x/mod v0.17.1-0.20240514174713-c0bdc7bd01c9/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
diff --git a/src/cmd/vendor/golang.org/x/mod/modfile/rule.go b/src/cmd/vendor/golang.org/x/mod/modfile/rule.go
index 0e7b7e2679..66dcaf9803 100644
--- a/src/cmd/vendor/golang.org/x/mod/modfile/rule.go
+++ b/src/cmd/vendor/golang.org/x/mod/modfile/rule.go
@@ -38,6 +38,7 @@ type File struct {
Module *Module
Go *Go
Toolchain *Toolchain
+ Godebug []*Godebug
Require []*Require
Exclude []*Exclude
Replace []*Replace
@@ -65,6 +66,13 @@ type Toolchain struct {
Syntax *Line
}
+// A Godebug is a single godebug key=value statement.
+type Godebug struct {
+ Key string
+ Value string
+ Syntax *Line
+}
+
// An Exclude is a single exclude statement.
type Exclude struct {
Mod module.Version
@@ -289,7 +297,7 @@ func parseToFile(file string, data []byte, fix VersionFixer, strict bool) (parse
})
}
continue
- case "module", "require", "exclude", "replace", "retract":
+ case "module", "godebug", "require", "exclude", "replace", "retract":
for _, l := range x.Line {
f.add(&errs, x, l, x.Token[0], l.Token, fix, strict)
}
@@ -308,7 +316,9 @@ var laxGoVersionRE = lazyregexp.New(`^v?(([1-9][0-9]*)\.(0|[1-9][0-9]*))([^0-9].
// Toolchains must be named beginning with `go1`,
// 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+
+// Note that this regexp is a much looser condition than go/version.IsValid,
+// for forward compatibility.
+// (This code has to be work to identify new toolchains even if we tweak the syntax in the future.)
var ToolchainRE = lazyregexp.New(`^default$|^go1($|\.)`)
func (f *File) add(errs *ErrorList, block *LineBlock, line *Line, verb string, args []string, fix VersionFixer, strict bool) {
@@ -384,7 +394,7 @@ func (f *File) add(errs *ErrorList, block *LineBlock, line *Line, verb string, a
if len(args) != 1 {
errorf("toolchain directive expects exactly one argument")
return
- } else if strict && !ToolchainRE.MatchString(args[0]) {
+ } else if !ToolchainRE.MatchString(args[0]) {
errorf("invalid toolchain version '%s': must match format go1.23.0 or default", args[0])
return
}
@@ -412,6 +422,22 @@ func (f *File) add(errs *ErrorList, block *LineBlock, line *Line, verb string, a
}
f.Module.Mod = module.Version{Path: s}
+ case "godebug":
+ if len(args) != 1 || strings.ContainsAny(args[0], "\"`',") {
+ errorf("usage: godebug key=value")
+ return
+ }
+ key, value, ok := strings.Cut(args[0], "=")
+ if !ok {
+ errorf("usage: godebug key=value")
+ return
+ }
+ f.Godebug = append(f.Godebug, &Godebug{
+ Key: key,
+ Value: value,
+ Syntax: line,
+ })
+
case "require", "exclude":
if len(args) != 2 {
errorf("usage: %s module/path v1.2.3", verb)
@@ -654,6 +680,22 @@ func (f *WorkFile) add(errs *ErrorList, line *Line, verb string, args []string,
f.Toolchain = &Toolchain{Syntax: line}
f.Toolchain.Name = args[0]
+ case "godebug":
+ if len(args) != 1 || strings.ContainsAny(args[0], "\"`',") {
+ errorf("usage: godebug key=value")
+ return
+ }
+ key, value, ok := strings.Cut(args[0], "=")
+ if !ok {
+ errorf("usage: godebug key=value")
+ return
+ }
+ f.Godebug = append(f.Godebug, &Godebug{
+ Key: key,
+ Value: value,
+ Syntax: line,
+ })
+
case "use":
if len(args) != 1 {
errorf("usage: %s local/dir", verb)
@@ -929,6 +971,15 @@ func (f *File) Format() ([]byte, error) {
// Cleanup cleans out all the cleared entries.
func (f *File) Cleanup() {
w := 0
+ for _, g := range f.Godebug {
+ if g.Key != "" {
+ f.Godebug[w] = g
+ w++
+ }
+ }
+ f.Godebug = f.Godebug[:w]
+
+ w = 0
for _, r := range f.Require {
if r.Mod.Path != "" {
f.Require[w] = r
@@ -1027,6 +1078,45 @@ func (f *File) AddToolchainStmt(name string) error {
return nil
}
+// AddGodebug sets the first godebug line for key to value,
+// preserving any existing comments for that line and removing all
+// other godebug lines for key.
+//
+// If no line currently exists for key, AddGodebug adds a new line
+// at the end of the last godebug block.
+func (f *File) AddGodebug(key, value string) error {
+ need := true
+ for _, g := range f.Godebug {
+ if g.Key == key {
+ if need {
+ g.Value = value
+ f.Syntax.updateLine(g.Syntax, "godebug", key+"="+value)
+ need = false
+ } else {
+ g.Syntax.markRemoved()
+ *g = Godebug{}
+ }
+ }
+ }
+
+ if need {
+ f.addNewGodebug(key, value)
+ }
+ return nil
+}
+
+// addNewGodebug adds a new godebug key=value line at the end
+// of the last godebug block, regardless of any existing godebug lines for key.
+func (f *File) addNewGodebug(key, value string) {
+ line := f.Syntax.addLine(nil, "godebug", key+"="+value)
+ g := &Godebug{
+ Key: key,
+ Value: value,
+ Syntax: line,
+ }
+ f.Godebug = append(f.Godebug, g)
+}
+
// AddRequire sets the first require line for path to version vers,
// preserving any existing comments for that line and removing all
// other lines for path.
@@ -1334,6 +1424,16 @@ func (f *File) SetRequireSeparateIndirect(req []*Require) {
f.SortBlocks()
}
+func (f *File) DropGodebug(key string) error {
+ for _, g := range f.Godebug {
+ if g.Key == key {
+ g.Syntax.markRemoved()
+ *g = Godebug{}
+ }
+ }
+ return nil
+}
+
func (f *File) DropRequire(path string) error {
for _, r := range f.Require {
if r.Mod.Path == path {
diff --git a/src/cmd/vendor/golang.org/x/mod/modfile/work.go b/src/cmd/vendor/golang.org/x/mod/modfile/work.go
index d7b99376eb..8f54897cf7 100644
--- a/src/cmd/vendor/golang.org/x/mod/modfile/work.go
+++ b/src/cmd/vendor/golang.org/x/mod/modfile/work.go
@@ -14,6 +14,7 @@ import (
type WorkFile struct {
Go *Go
Toolchain *Toolchain
+ Godebug []*Godebug
Use []*Use
Replace []*Replace
@@ -68,7 +69,7 @@ func ParseWork(file string, data []byte, fix VersionFixer) (*WorkFile, error) {
Err: fmt.Errorf("unknown block type: %s", strings.Join(x.Token, " ")),
})
continue
- case "use", "replace":
+ case "godebug", "use", "replace":
for _, l := range x.Line {
f.add(&errs, l, x.Token[0], l.Token, fix)
}
@@ -184,6 +185,55 @@ func (f *WorkFile) DropToolchainStmt() {
}
}
+// AddGodebug sets the first godebug line for key to value,
+// preserving any existing comments for that line and removing all
+// other godebug lines for key.
+//
+// If no line currently exists for key, AddGodebug adds a new line
+// at the end of the last godebug block.
+func (f *WorkFile) AddGodebug(key, value string) error {
+ need := true
+ for _, g := range f.Godebug {
+ if g.Key == key {
+ if need {
+ g.Value = value
+ f.Syntax.updateLine(g.Syntax, "godebug", key+"="+value)
+ need = false
+ } else {
+ g.Syntax.markRemoved()
+ *g = Godebug{}
+ }
+ }
+ }
+
+ if need {
+ f.addNewGodebug(key, value)
+ }
+ return nil
+}
+
+// addNewGodebug adds a new godebug key=value line at the end
+// of the last godebug block, regardless of any existing godebug lines for key.
+func (f *WorkFile) addNewGodebug(key, value string) {
+ line := f.Syntax.addLine(nil, "godebug", key+"="+value)
+ g := &Godebug{
+ Key: key,
+ Value: value,
+ Syntax: line,
+ }
+ f.Godebug = append(f.Godebug, g)
+}
+
+func (f *WorkFile) DropGodebug(key string) error {
+ for _, g := range f.Godebug {
+ if g.Key == key {
+ g.Syntax.markRemoved()
+ *g = Godebug{}
+ }
+ }
+ return nil
+}
+
func (f *WorkFile) AddUse(diskPath, modulePath string) error {
need := true
for _, d := range f.Use {
diff --git a/src/cmd/vendor/modules.txt b/src/cmd/vendor/modules.txt
index 44a0b69008..648b89f4d2 100644
--- a/src/cmd/vendor/modules.txt
+++ b/src/cmd/vendor/modules.txt
@@ -25,7 +25,7 @@ golang.org/x/arch/x86/x86asm
# golang.org/x/build v0.0.0-20240222153247-cf4ed81bb19f
## explicit; go 1.21
golang.org/x/build/relnote
-# golang.org/x/mod v0.17.1-0.20240507203540-6686f416970d
+# golang.org/x/mod v0.17.1-0.20240514174713-c0bdc7bd01c9
## explicit; go 1.18
golang.org/x/mod/internal/lazyregexp
golang.org/x/mod/modfile