aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/vendor
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/vendor')
-rw-r--r--src/cmd/vendor/golang.org/x/mod/modfile/print.go14
-rw-r--r--src/cmd/vendor/golang.org/x/mod/modfile/rule.go96
-rw-r--r--src/cmd/vendor/golang.org/x/mod/modfile/work.go61
-rw-r--r--src/cmd/vendor/modules.txt2
4 files changed, 157 insertions, 16 deletions
diff --git a/src/cmd/vendor/golang.org/x/mod/modfile/print.go b/src/cmd/vendor/golang.org/x/mod/modfile/print.go
index 524f93022a..2a0123d4b9 100644
--- a/src/cmd/vendor/golang.org/x/mod/modfile/print.go
+++ b/src/cmd/vendor/golang.org/x/mod/modfile/print.go
@@ -16,7 +16,13 @@ import (
func Format(f *FileSyntax) []byte {
pr := &printer{}
pr.file(f)
- return pr.Bytes()
+
+ // remove trailing blank lines
+ b := pr.Bytes()
+ for len(b) > 0 && b[len(b)-1] == '\n' && (len(b) == 1 || b[len(b)-2] == '\n') {
+ b = b[:len(b)-1]
+ }
+ return b
}
// A printer collects the state during printing of a file or expression.
@@ -59,7 +65,11 @@ func (p *printer) newline() {
}
p.trim()
- p.printf("\n")
+ if b := p.Bytes(); len(b) == 0 || (len(b) >= 2 && b[len(b)-1] == '\n' && b[len(b)-2] == '\n') {
+ // skip the blank line at top of file or after a blank line
+ } else {
+ p.printf("\n")
+ }
for i := 0; i < p.margin; i++ {
p.printf("\t")
}
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 c20aef1566..39f03f26c1 100644
--- a/src/cmd/vendor/golang.org/x/mod/modfile/rule.go
+++ b/src/cmd/vendor/golang.org/x/mod/modfile/rule.go
@@ -35,12 +35,13 @@ import (
// A File is the parsed, interpreted form of a go.mod file.
type File struct {
- Module *Module
- Go *Go
- Require []*Require
- Exclude []*Exclude
- Replace []*Replace
- Retract []*Retract
+ Module *Module
+ Go *Go
+ Toolchain *Toolchain
+ Require []*Require
+ Exclude []*Exclude
+ Replace []*Replace
+ Retract []*Retract
Syntax *FileSyntax
}
@@ -58,6 +59,12 @@ type Go struct {
Syntax *Line
}
+// A Toolchain is the toolchain statement.
+type Toolchain struct {
+ Name string // "go1.21rc1"
+ Syntax *Line
+}
+
// An Exclude is a single exclude statement.
type Exclude struct {
Mod module.Version
@@ -296,9 +303,13 @@ func parseToFile(file string, data []byte, fix VersionFixer, strict bool) (parse
return f, nil
}
-var GoVersionRE = lazyregexp.New(`^([1-9][0-9]*)\.(0|[1-9][0-9]*)$`)
+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`)
+
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.
// We ignore all unknown directives as well as main-module-only
@@ -364,6 +375,21 @@ func (f *File) add(errs *ErrorList, block *LineBlock, line *Line, verb string, a
f.Go = &Go{Syntax: line}
f.Go.Version = args[0]
+ case "toolchain":
+ if f.Toolchain != nil {
+ errorf("repeated toolchain statement")
+ return
+ }
+ if len(args) != 1 {
+ errorf("toolchain directive expects exactly one argument")
+ return
+ } else if strict && !ToolchainRE.MatchString(args[0]) {
+ errorf("invalid toolchain version '%s': must match format go1.23 or local", args[0])
+ return
+ }
+ f.Toolchain = &Toolchain{Syntax: line}
+ f.Toolchain.Name = args[0]
+
case "module":
if f.Module != nil {
errorf("repeated module statement")
@@ -612,6 +638,22 @@ func (f *WorkFile) add(errs *ErrorList, line *Line, verb string, args []string,
f.Go = &Go{Syntax: line}
f.Go.Version = args[0]
+ case "toolchain":
+ if f.Toolchain != nil {
+ errorf("repeated toolchain statement")
+ return
+ }
+ if len(args) != 1 {
+ errorf("toolchain directive expects exactly one argument")
+ return
+ } else if !ToolchainRE.MatchString(args[0]) {
+ errorf("invalid toolchain version '%s': must match format go1.23 or local", args[0])
+ return
+ }
+
+ f.Toolchain = &Toolchain{Syntax: line}
+ f.Toolchain.Name = args[0]
+
case "use":
if len(args) != 1 {
errorf("usage: %s local/dir", verb)
@@ -926,7 +968,7 @@ func (f *File) Cleanup() {
func (f *File) AddGoStmt(version string) error {
if !GoVersionRE.MatchString(version) {
- return fmt.Errorf("invalid language version string %q", version)
+ return fmt.Errorf("invalid language version %q", version)
}
if f.Go == nil {
var hint Expr
@@ -944,6 +986,44 @@ func (f *File) AddGoStmt(version string) error {
return nil
}
+// DropGoStmt deletes the go statement from the file.
+func (f *File) DropGoStmt() {
+ if f.Go != nil {
+ f.Go.Syntax.markRemoved()
+ f.Go = nil
+ }
+}
+
+// DropToolchainStmt deletes the toolchain statement from the file.
+func (f *File) DropToolchainStmt() {
+ if f.Toolchain != nil {
+ f.Toolchain.Syntax.markRemoved()
+ f.Toolchain = nil
+ }
+}
+
+func (f *File) AddToolchainStmt(name string) error {
+ if !ToolchainRE.MatchString(name) {
+ return fmt.Errorf("invalid toolchain name %q", name)
+ }
+ if f.Toolchain == nil {
+ var hint Expr
+ if f.Go != nil && f.Go.Syntax != nil {
+ hint = f.Go.Syntax
+ } else if f.Module != nil && f.Module.Syntax != nil {
+ hint = f.Module.Syntax
+ }
+ f.Toolchain = &Toolchain{
+ Name: name,
+ Syntax: f.Syntax.addLine(hint, "toolchain", name),
+ }
+ } else {
+ f.Toolchain.Name = name
+ f.Syntax.updateLine(f.Toolchain.Syntax, "toolchain", name)
+ }
+ return nil
+}
+
// 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.
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 0c0e521525..75dc1c5491 100644
--- a/src/cmd/vendor/golang.org/x/mod/modfile/work.go
+++ b/src/cmd/vendor/golang.org/x/mod/modfile/work.go
@@ -12,9 +12,10 @@ import (
// A WorkFile is the parsed, interpreted form of a go.work file.
type WorkFile struct {
- Go *Go
- Use []*Use
- Replace []*Replace
+ Go *Go
+ Toolchain *Toolchain
+ Use []*Use
+ Replace []*Replace
Syntax *FileSyntax
}
@@ -109,7 +110,7 @@ func (f *WorkFile) Cleanup() {
func (f *WorkFile) AddGoStmt(version string) error {
if !GoVersionRE.MatchString(version) {
- return fmt.Errorf("invalid language version string %q", version)
+ return fmt.Errorf("invalid language version %q", version)
}
if f.Go == nil {
stmt := &Line{Token: []string{"go", version}}
@@ -117,7 +118,7 @@ func (f *WorkFile) AddGoStmt(version string) error {
Version: version,
Syntax: stmt,
}
- // Find the first non-comment-only block that's and add
+ // Find the first non-comment-only block and add
// the go statement before it. That will keep file comments at the top.
i := 0
for i = 0; i < len(f.Syntax.Stmt); i++ {
@@ -133,6 +134,56 @@ func (f *WorkFile) AddGoStmt(version string) error {
return nil
}
+func (f *WorkFile) AddToolchainStmt(name string) error {
+ if !ToolchainRE.MatchString(name) {
+ return fmt.Errorf("invalid toolchain name %q", name)
+ }
+ if f.Toolchain == nil {
+ stmt := &Line{Token: []string{"toolchain", name}}
+ f.Toolchain = &Toolchain{
+ Name: name,
+ Syntax: stmt,
+ }
+ // Find the go line and add the toolchain line after it.
+ // Or else find the first non-comment-only block and add
+ // the toolchain line before it. That will keep file comments at the top.
+ i := 0
+ for i = 0; i < len(f.Syntax.Stmt); i++ {
+ if line, ok := f.Syntax.Stmt[i].(*Line); ok && len(line.Token) > 0 && line.Token[0] == "go" {
+ i++
+ goto Found
+ }
+ }
+ for i = 0; i < len(f.Syntax.Stmt); i++ {
+ if _, ok := f.Syntax.Stmt[i].(*CommentBlock); !ok {
+ break
+ }
+ }
+ Found:
+ f.Syntax.Stmt = append(append(f.Syntax.Stmt[:i:i], stmt), f.Syntax.Stmt[i:]...)
+ } else {
+ f.Toolchain.Name = name
+ f.Syntax.updateLine(f.Toolchain.Syntax, "toolchain", name)
+ }
+ return nil
+}
+
+// DropGoStmt deletes the go statement from the file.
+func (f *WorkFile) DropGoStmt() {
+ if f.Go != nil {
+ f.Go.Syntax.markRemoved()
+ f.Go = nil
+ }
+}
+
+// DropToolchainStmt deletes the toolchain statement from the file.
+func (f *WorkFile) DropToolchainStmt() {
+ if f.Toolchain != nil {
+ f.Toolchain.Syntax.markRemoved()
+ f.Toolchain = 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 9a3b431470..cb409f425c 100644
--- a/src/cmd/vendor/modules.txt
+++ b/src/cmd/vendor/modules.txt
@@ -23,7 +23,7 @@ golang.org/x/arch/arm/armasm
golang.org/x/arch/arm64/arm64asm
golang.org/x/arch/ppc64/ppc64asm
golang.org/x/arch/x86/x86asm
-# golang.org/x/mod v0.10.1-0.20230517154618-e7bea8f1d64f
+# golang.org/x/mod v0.10.1-0.20230523205221-fc83a8faf993
## explicit; go 1.17
golang.org/x/mod/internal/lazyregexp
golang.org/x/mod/modfile