require (
github.com/google/pprof v0.0.0-20211104044539-f987b9c94b31
golang.org/x/arch v0.0.0-20210923205945-b76863e36670
- golang.org/x/mod v0.6.0-dev.0.20210913215816-37dd6891021a
+ golang.org/x/mod v0.6.0-dev.0.20211102181907-3a5865c02020
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
golang.org/x/tools v0.1.8-0.20211116011028-4adea5033c5c
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa h1:idItI2DDfCokpg0N51B2VtiLdJ4vAuXC9fnCb2gACo4=
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
-golang.org/x/mod v0.6.0-dev.0.20210913215816-37dd6891021a h1:gAiIC0JKDJwXAQFyqEYxROcAzeeh5ZTwWjKORCFuQxs=
-golang.org/x/mod v0.6.0-dev.0.20210913215816-37dd6891021a/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
+golang.org/x/mod v0.6.0-dev.0.20211102181907-3a5865c02020 h1:HjtpZuJcnSa+yHlL4Y5aypjDvbHkJne5FS8JRmKI2+I=
+golang.org/x/mod v0.6.0-dev.0.20211102181907-3a5865c02020/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
// rewrite the go.mod file. The only time this flag is needed is if no other
// flags are specified, as in 'go mod editwork -fmt'.
//
-// The -directory=path and -dropdirectory=path flags
-// add and drop a directory from the go.work files set of module directories.
+// The -use=path and -dropuse=path flags
+// add and drop a use directive from the go.work file's set of module directories.
//
// The -replace=old[@v]=new[@v] flag adds a replacement of the given
// module path and version pair. If the @v in old@v is omitted, a
// module path and version pair. If the @v is omitted, a replacement without
// a version on the left side is dropped.
//
-// The -directory, -dropdirectory, -replace, and -dropreplace,
+// The -use, -dropuse, -replace, and -dropreplace,
// editing flags may be repeated, and the changes are applied in the order given.
//
// The -go=version flag sets the expected Go language version.
// Replace []Replace
// }
//
-// type Directory struct {
+// type Use struct {
// Path string
// ModulePath string
// }
goVersion = wf.Go.Version
}
seen := map[string]bool{}
- for _, d := range wf.Directory {
+ for _, d := range wf.Use {
modRoot := d.Path
if !filepath.IsAbs(modRoot) {
modRoot = filepath.Join(workDir, modRoot)
func UpdateWorkFile(wf *modfile.WorkFile) {
missingModulePaths := map[string]string{} // module directory listed in file -> abspath modroot
- for _, d := range wf.Directory {
+ for _, d := range wf.Use {
modRoot := d.Path
if d.ModulePath == "" {
missingModulePaths[d.Path] = modRoot
if err != nil {
continue // Error will be reported if modules are loaded.
}
- wf.AddDirectory(moddir, f.Module.Mod.Path)
+ wf.AddUse(moddir, f.Module.Mod.Path)
}
}
}
base.Fatalf("go: error parsing go.mod in directory %s: %v", dir, err)
}
- workF.AddDirectory(ToDirectoryPath(dir), f.Module.Mod.Path)
+ workF.AddUse(ToDirectoryPath(dir), f.Module.Mod.Path)
}
UpdateWorkFile(workF)
rewrite the go.mod file. The only time this flag is needed is if no other
flags are specified, as in 'go mod editwork -fmt'.
-The -directory=path and -dropdirectory=path flags
-add and drop a directory from the go.work files set of module directories.
+The -use=path and -dropuse=path flags
+add and drop a use directive from the go.work file's set of module directories.
The -replace=old[@v]=new[@v] flag adds a replacement of the given
module path and version pair. If the @v in old@v is omitted, a
module path and version pair. If the @v is omitted, a replacement without
a version on the left side is dropped.
-The -directory, -dropdirectory, -replace, and -dropreplace,
+The -use, -dropuse, -replace, and -dropreplace,
editing flags may be repeated, and the changes are applied in the order given.
The -go=version flag sets the expected Go language version.
Replace []Replace
}
- type Directory struct {
+ type Use struct {
Path string
ModulePath string
}
func init() {
cmdEdit.Run = runEditwork // break init cycle
- cmdEdit.Flag.Var(flagFunc(flagEditworkDirectory), "directory", "")
- cmdEdit.Flag.Var(flagFunc(flagEditworkDropDirectory), "dropdirectory", "")
+ cmdEdit.Flag.Var(flagFunc(flagEditworkUse), "use", "")
+ cmdEdit.Flag.Var(flagFunc(flagEditworkDropUse), "dropuse", "")
cmdEdit.Flag.Var(flagFunc(flagEditworkReplace), "replace", "")
cmdEdit.Flag.Var(flagFunc(flagEditworkDropReplace), "dropreplace", "")
modload.WriteWorkFile(gowork, workFile)
}
-// flagEditworkDirectory implements the -directory flag.
-func flagEditworkDirectory(arg string) {
+// flagEditworkUse implements the -use flag.
+func flagEditworkUse(arg string) {
workedits = append(workedits, func(f *modfile.WorkFile) {
_, mf, err := modload.ReadModFile(filepath.Join(arg, "go.mod"), nil)
modulePath := ""
if err == nil {
modulePath = mf.Module.Mod.Path
}
- f.AddDirectory(modload.ToDirectoryPath(arg), modulePath)
- if err := f.AddDirectory(modload.ToDirectoryPath(arg), ""); err != nil {
- base.Fatalf("go: -directory=%s: %v", arg, err)
+ f.AddUse(modload.ToDirectoryPath(arg), modulePath)
+ if err := f.AddUse(modload.ToDirectoryPath(arg), ""); err != nil {
+ base.Fatalf("go: -use=%s: %v", arg, err)
}
})
}
-// flagEditworkDropDirectory implements the -dropdirectory flag.
-func flagEditworkDropDirectory(arg string) {
+// flagEditworkDropUse implements the -dropuse flag.
+func flagEditworkDropUse(arg string) {
workedits = append(workedits, func(f *modfile.WorkFile) {
- if err := f.DropDirectory(modload.ToDirectoryPath(arg)); err != nil {
+ if err := f.DropUse(modload.ToDirectoryPath(arg)); err != nil {
base.Fatalf("go: -dropdirectory=%s: %v", arg, err)
}
})
if workFile.Go != nil {
f.Go = workFile.Go.Version
}
- for _, d := range workFile.Directory {
- f.Directory = append(f.Directory, directoryJSON{DiskPath: d.Path, ModPath: d.ModulePath})
+ for _, d := range workFile.Use {
+ f.Use = append(f.Use, useJSON{DiskPath: d.Path, ModPath: d.ModulePath})
}
for _, r := range workFile.Replace {
// workfileJSON is the -json output data structure.
type workfileJSON struct {
- Go string `json:",omitempty"`
- Directory []directoryJSON
- Replace []replaceJSON
+ Go string `json:",omitempty"`
+ Use []useJSON
+ Replace []replaceJSON
}
-type directoryJSON struct {
+type useJSON struct {
DiskPath string
ModPath string `json:",omitempty"`
}
}
haveDirs := make(map[string]bool)
- for _, dir := range workFile.Directory {
+ for _, dir := range workFile.Use {
haveDirs[filepath.Join(filepath.Dir(gowork), filepath.FromSlash(dir.Path))] = true
}
}
for dir := range removeDirs {
- workFile.DropDirectory(filepath.ToSlash(dir))
+ workFile.DropUse(filepath.ToSlash(dir))
}
for dir := range addDirs {
- workFile.AddDirectory(filepath.ToSlash(dir), "")
+ workFile.AddUse(filepath.ToSlash(dir), "")
}
modload.UpdateWorkFile(workFile)
modload.WriteWorkFile(gowork, workFile)
stderr '^go: -mod may only be set to readonly when in workspace mode'
go list -mod=mod -workfile=off all
-# Test that duplicates in the directory list return an error
+# Test that duplicates in the use list return an error
cp go.work go.work.backup
cp go.work.dup go.work
! go run example.com/b
-- go.work.dup --
go 1.18
-directory (
+use (
a
b
../src/a
-- go.work.want --
go 1.18
-directory (
+use (
./a
./b
)
-- go.work.d --
go 1.18
-directory (
+use (
a
b
d
-- go.work.backwards --
go 1.18
-directory (
+use (
d
b
a
go work init m
cmp go.work go.work.want_initial
-go work edit -directory n
-cmp go.work go.work.want_directory_n
+go work edit -use n
+cmp go.work go.work.want_use_n
go work edit -go 1.18
cmp go.work go.work.want_go_118
-go work edit -dropdirectory m
-cmp go.work go.work.want_dropdirectory_m
+go work edit -dropuse m
+cmp go.work go.work.want_dropuse_m
go work edit -replace=x.1@v1.3.0=y.1@v1.4.0 -replace='x.1@v1.4.0 = ../z'
cmp go.work go.work.want_add_replaces
-go work edit -directory n -directory ../a -directory /b -directory c -directory c
-cmp go.work go.work.want_multidirectory
+go work edit -use n -use ../a -use /b -use c -use c
+cmp go.work go.work.want_multiuse
-go work edit -dropdirectory /b -dropdirectory n
-cmp go.work go.work.want_multidropdirectory
+go work edit -dropuse /b -dropuse n
+cmp go.work go.work.want_multidropuse
go work edit -dropreplace='x.1@v1.4.0'
cmp go.work go.work.want_dropreplace
-go work edit -print -go 1.19 -directory b -dropdirectory c -replace 'x.1@v1.4.0 = ../z' -dropreplace x.1 -dropreplace x.1@v1.3.0
+go work edit -print -go 1.19 -use b -dropuse c -replace 'x.1@v1.4.0 = ../z' -dropreplace x.1 -dropreplace x.1@v1.3.0
cmp stdout go.work.want_print
-go work edit -json -go 1.19 -directory b -dropdirectory c -replace 'x.1@v1.4.0 = ../z' -dropreplace x.1 -dropreplace x.1@v1.3.0
+go work edit -json -go 1.19 -use b -dropuse c -replace 'x.1@v1.4.0 = ../z' -dropreplace x.1 -dropreplace x.1@v1.3.0
cmp stdout go.work.want_json
go work edit -print -fmt -workfile $GOPATH/src/unformatted
-- go.work.want_initial --
go 1.18
-directory ./m
--- go.work.want_directory_n --
+use ./m
+-- go.work.want_use_n --
go 1.18
-directory (
+use (
./m
./n
)
-- go.work.want_go_118 --
go 1.18
-directory (
+use (
./m
./n
)
--- go.work.want_dropdirectory_m --
+-- go.work.want_dropuse_m --
go 1.18
-directory ./n
+use ./n
-- go.work.want_add_replaces --
go 1.18
-directory ./n
+use ./n
replace (
x.1 v1.3.0 => y.1 v1.4.0
x.1 v1.4.0 => ../z
)
--- go.work.want_multidirectory --
+-- go.work.want_multiuse --
go 1.18
-directory (
+use (
../a
./c
./n
x.1 v1.3.0 => y.1 v1.4.0
x.1 v1.4.0 => ../z
)
--- go.work.want_multidropdirectory --
+-- go.work.want_multidropuse --
go 1.18
-directory (
+use (
../a
./c
)
-- go.work.want_dropreplace --
go 1.18
-directory (
+use (
../a
./c
)
-- go.work.want_print --
go 1.19
-directory (
+use (
../a
./b
)
-- go.work.want_json --
{
"Go": "1.19",
- "Directory": [
+ "Use": [
{
"DiskPath": "../a"
},
}
-- unformatted --
go 1.18
- directory (
+ use (
a
b
c
-- formatted --
go 1.18
-directory (
+use (
a
b
c
-- go.work --
go 1.18
-directory a
+use a
-- a/go.mod --
module example.com/a
-- go.work --
go 1.18
-directory (
+use (
./a
./p
)
stdout 'example.com/other v1.0.0 => ./other2'
-- go.work --
-directory m
+use m
replace example.com/dep => ./dep
replace example.com/other => ./other2
-- foo --
-- go.work --
-directory m
-directory n
+use m
+use n
-- m/go.mod --
module example.com/m
stdout 'example.com/dep v1.0.0 => ./dep3'
-- go.work --
-directory m
-directory n
+use m
+use n
replace example.com/dep => ./dep3
-- m/go.mod --
module example.com/m
-- go.work --
go 1.18
-directory .
+use .
-- go.mod --
go 1.18
-- go.work --
go 1.18
-directory ./a
-directory ./b
+use ./a
+use ./b
-- a/go.mod --
go 1.18
-- go.work --
go 1.18
-directory (
+use (
./a
./b
)
-- go.work --
go 1.18
-directory (
+use (
./a
./b
)
-- go.work --
go 1.18
-directory (
+use (
./a
./b
)
-- go.work --
go 1.18
-directory (
+use (
foo
foo/bar // doesn't exist
)
-- go.want_work_r --
go 1.18
-directory (
+use (
foo
foo/bar/baz
)
-- go.want_work_other --
go 1.18
-directory (
+use (
foo
foo/bar/baz
other
-- go.work --
go 1.18
-directory (
+use (
./a
./b
)
f.Go = &Go{Syntax: line}
f.Go.Version = args[0]
- case "directory":
+ case "use":
if len(args) != 1 {
errorf("usage: %s local/dir", verb)
return
errorf("invalid quoted string: %v", err)
return
}
- f.Directory = append(f.Directory, &Directory{
+ f.Use = append(f.Use, &Use{
Path: s,
Syntax: line,
})
// A WorkFile is the parsed, interpreted form of a go.work file.
type WorkFile struct {
- Go *Go
- Directory []*Directory
- Replace []*Replace
+ Go *Go
+ Use []*Use
+ Replace []*Replace
Syntax *FileSyntax
}
-// A Directory is a single directory statement.
-type Directory struct {
- Path string // Directory path of module.
+// A Use is a single directory statement.
+type Use struct {
+ Path string // Use path of module.
ModulePath string // Module path in the comment.
Syntax *Line
}
Err: fmt.Errorf("unknown block type: %s", strings.Join(x.Token, " ")),
})
continue
- case "directory", "replace":
+ case "use", "replace":
for _, l := range x.Line {
f.add(&errs, l, x.Token[0], l.Token, fix)
}
// Cleanup cleans out all the cleared entries.
func (f *WorkFile) Cleanup() {
w := 0
- for _, r := range f.Directory {
+ for _, r := range f.Use {
if r.Path != "" {
- f.Directory[w] = r
+ f.Use[w] = r
w++
}
}
- f.Directory = f.Directory[:w]
+ f.Use = f.Use[:w]
w = 0
for _, r := range f.Replace {
return nil
}
-func (f *WorkFile) AddDirectory(diskPath, modulePath string) error {
+func (f *WorkFile) AddUse(diskPath, modulePath string) error {
need := true
- for _, d := range f.Directory {
+ for _, d := range f.Use {
if d.Path == diskPath {
if need {
d.ModulePath = modulePath
- f.Syntax.updateLine(d.Syntax, "directory", AutoQuote(diskPath))
+ f.Syntax.updateLine(d.Syntax, "use", AutoQuote(diskPath))
need = false
} else {
d.Syntax.markRemoved()
- *d = Directory{}
+ *d = Use{}
}
}
}
if need {
- f.AddNewDirectory(diskPath, modulePath)
+ f.AddNewUse(diskPath, modulePath)
}
return nil
}
-func (f *WorkFile) AddNewDirectory(diskPath, modulePath string) {
- line := f.Syntax.addLine(nil, "directory", AutoQuote(diskPath))
- f.Directory = append(f.Directory, &Directory{Path: diskPath, ModulePath: modulePath, Syntax: line})
+func (f *WorkFile) AddNewUse(diskPath, modulePath string) {
+ line := f.Syntax.addLine(nil, "use", AutoQuote(diskPath))
+ f.Use = append(f.Use, &Use{Path: diskPath, ModulePath: modulePath, Syntax: line})
}
-func (f *WorkFile) SetDirectory(dirs []*Directory) {
+func (f *WorkFile) SetUse(dirs []*Use) {
need := make(map[string]string)
for _, d := range dirs {
need[d.Path] = d.ModulePath
}
- for _, d := range f.Directory {
+ for _, d := range f.Use {
if modulePath, ok := need[d.Path]; ok {
d.ModulePath = modulePath
} else {
d.Syntax.markRemoved()
- *d = Directory{}
+ *d = Use{}
}
}
// TODO(#45713): Add module path to comment.
for diskPath, modulePath := range need {
- f.AddNewDirectory(diskPath, modulePath)
+ f.AddNewUse(diskPath, modulePath)
}
f.SortBlocks()
}
-func (f *WorkFile) DropDirectory(path string) error {
- for _, d := range f.Directory {
+func (f *WorkFile) DropUse(path string) error {
+ for _, d := range f.Use {
if d.Path == path {
d.Syntax.markRemoved()
- *d = Directory{}
+ *d = Use{}
}
}
return nil
// GOPRIVATE environment variable, as described by 'go help module-private'.
//
// It ignores any empty or malformed patterns in the list.
+// Trailing slashes on patterns are ignored.
func MatchPrefixPatterns(globs, target string) bool {
for globs != "" {
// Extract next non-empty glob in comma-separated list.
} else {
glob, globs = globs, ""
}
+ glob = strings.TrimSuffix(glob, "/")
if glob == "" {
continue
}
short string
prerelease string
build string
- err string
}
// IsValid reports whether v is a valid semantic version string.
func parse(v string) (p parsed, ok bool) {
if v == "" || v[0] != 'v' {
- p.err = "missing v prefix"
return
}
p.major, v, ok = parseInt(v[1:])
if !ok {
- p.err = "bad major version"
return
}
if v == "" {
return
}
if v[0] != '.' {
- p.err = "bad minor prefix"
ok = false
return
}
p.minor, v, ok = parseInt(v[1:])
if !ok {
- p.err = "bad minor version"
return
}
if v == "" {
return
}
if v[0] != '.' {
- p.err = "bad patch prefix"
ok = false
return
}
p.patch, v, ok = parseInt(v[1:])
if !ok {
- p.err = "bad patch version"
return
}
if len(v) > 0 && v[0] == '-' {
p.prerelease, v, ok = parsePrerelease(v)
if !ok {
- p.err = "bad prerelease"
return
}
}
if len(v) > 0 && v[0] == '+' {
p.build, v, ok = parseBuild(v)
if !ok {
- p.err = "bad build"
return
}
}
if v != "" {
- p.err = "junk on end"
ok = false
return
}
## explicit; go 1.17
golang.org/x/crypto/ed25519
golang.org/x/crypto/ed25519/internal/edwards25519
-# golang.org/x/mod v0.6.0-dev.0.20210913215816-37dd6891021a
+# golang.org/x/mod v0.6.0-dev.0.20211102181907-3a5865c02020
## explicit; go 1.17
golang.org/x/mod/internal/lazyregexp
golang.org/x/mod/modfile