mirror of
https://github.com/DNSCrypt/dnscrypt-proxy.git
synced 2025-04-04 13:47:39 +03:00
Update deps
This commit is contained in:
parent
79779cf744
commit
f85b3e81ec
60 changed files with 1310 additions and 2126 deletions
142
vendor/golang.org/x/mod/modfile/rule.go
generated
vendored
142
vendor/golang.org/x/mod/modfile/rule.go
generated
vendored
|
@ -5,17 +5,17 @@
|
|||
// Package modfile implements a parser and formatter for go.mod files.
|
||||
//
|
||||
// The go.mod syntax is described in
|
||||
// https://golang.org/cmd/go/#hdr-The_go_mod_file.
|
||||
// https://pkg.go.dev/cmd/go/#hdr-The_go_mod_file.
|
||||
//
|
||||
// The Parse and ParseLax functions both parse a go.mod file and return an
|
||||
// The [Parse] and [ParseLax] functions both parse a go.mod file and return an
|
||||
// abstract syntax tree. ParseLax ignores unknown statements and may be used to
|
||||
// parse go.mod files that may have been developed with newer versions of Go.
|
||||
//
|
||||
// The File struct returned by Parse and ParseLax represent an abstract
|
||||
// go.mod file. File has several methods like AddNewRequire and DropReplace
|
||||
// that can be used to programmatically edit a file.
|
||||
// The [File] struct returned by Parse and ParseLax represent an abstract
|
||||
// go.mod file. File has several methods like [File.AddNewRequire] and
|
||||
// [File.DropReplace] that can be used to programmatically edit a file.
|
||||
//
|
||||
// The Format function formats a File back to a byte slice which can be
|
||||
// The [Format] function formats a File back to a byte slice which can be
|
||||
// written to a file.
|
||||
package modfile
|
||||
|
||||
|
@ -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
|
||||
|
@ -219,7 +226,7 @@ var dontFixRetract VersionFixer = func(_, vers string) (string, error) {
|
|||
// data is the content of the file.
|
||||
//
|
||||
// fix is an optional function that canonicalizes module versions.
|
||||
// If fix is nil, all module versions must be canonical (module.CanonicalVersion
|
||||
// If fix is nil, all module versions must be canonical ([module.CanonicalVersion]
|
||||
// must return the same string).
|
||||
func Parse(file string, data []byte, fix VersionFixer) (*File, error) {
|
||||
return parseToFile(file, data, fix, true)
|
||||
|
@ -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`,
|
||||
// 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.
|
||||
// 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)
|
||||
|
@ -881,7 +923,7 @@ func (f *File) Format() ([]byte, error) {
|
|||
}
|
||||
|
||||
// Cleanup cleans up the file f after any edit operations.
|
||||
// To avoid quadratic behavior, modifications like DropRequire
|
||||
// To avoid quadratic behavior, modifications like [File.DropRequire]
|
||||
// clear the entry but do not remove it from the slice.
|
||||
// Cleanup cleans out all the cleared entries.
|
||||
func (f *File) Cleanup() {
|
||||
|
@ -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.
|
||||
|
@ -995,8 +1075,8 @@ func (f *File) AddNewRequire(path, vers string, indirect bool) {
|
|||
// The requirements in req must specify at most one distinct version for each
|
||||
// module path.
|
||||
//
|
||||
// If any existing requirements may be removed, the caller should call Cleanup
|
||||
// after all edits are complete.
|
||||
// If any existing requirements may be removed, the caller should call
|
||||
// [File.Cleanup] after all edits are complete.
|
||||
func (f *File) SetRequire(req []*Require) {
|
||||
type elem struct {
|
||||
version string
|
||||
|
@ -1387,13 +1467,21 @@ func (f *File) DropRetract(vi VersionInterval) error {
|
|||
func (f *File) SortBlocks() {
|
||||
f.removeDups() // otherwise sorting is unsafe
|
||||
|
||||
// semanticSortForExcludeVersionV is the Go version (plus leading "v") at which
|
||||
// lines in exclude blocks start to use semantic sort instead of lexicographic sort.
|
||||
// See go.dev/issue/60028.
|
||||
const semanticSortForExcludeVersionV = "v1.21"
|
||||
useSemanticSortForExclude := f.Go != nil && semver.Compare("v"+f.Go.Version, semanticSortForExcludeVersionV) >= 0
|
||||
|
||||
for _, stmt := range f.Syntax.Stmt {
|
||||
block, ok := stmt.(*LineBlock)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
less := lineLess
|
||||
if block.Token[0] == "retract" {
|
||||
if block.Token[0] == "exclude" && useSemanticSortForExclude {
|
||||
less = lineExcludeLess
|
||||
} else if block.Token[0] == "retract" {
|
||||
less = lineRetractLess
|
||||
}
|
||||
sort.SliceStable(block.Line, func(i, j int) bool {
|
||||
|
@ -1496,6 +1584,22 @@ func lineLess(li, lj *Line) bool {
|
|||
return len(li.Token) < len(lj.Token)
|
||||
}
|
||||
|
||||
// lineExcludeLess reports whether li should be sorted before lj for lines in
|
||||
// an "exclude" block.
|
||||
func lineExcludeLess(li, lj *Line) bool {
|
||||
if len(li.Token) != 2 || len(lj.Token) != 2 {
|
||||
// Not a known exclude specification.
|
||||
// Fall back to sorting lexicographically.
|
||||
return lineLess(li, lj)
|
||||
}
|
||||
// An exclude specification has two tokens: ModulePath and Version.
|
||||
// Compare module path by string order and version by semver rules.
|
||||
if pi, pj := li.Token[0], lj.Token[0]; pi != pj {
|
||||
return pi < pj
|
||||
}
|
||||
return semver.Compare(li.Token[1], lj.Token[1]) < 0
|
||||
}
|
||||
|
||||
// lineRetractLess returns whether li should be sorted before lj for lines in
|
||||
// a "retract" block. It treats each line as a version interval. Single versions
|
||||
// are compared as if they were intervals with the same low and high version.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue