Skip to content

Commit

Permalink
cmd: pull in golang.org/x/mod@3a5865c
Browse files Browse the repository at this point in the history
This change updates the cmd module's requirement on x/mod and vendors in
the changes.

This pulls in the following changes into our vendored copy of x/mod:
golang.org/cl/351319: module: accept trailing slash in MatchPrefixPattern
golang.org/cl/353749: semver: remove unused err field
golang.org/cl/355630: x/mod: update requirement on x/crypto
golang.org/cl/359412: modfile: rename directory directive to use

Changes have been made in cmd/go renaming all uses of directory to use
and fixing references to functions in x/mod/modfile to account for the
changes in the last of thse CLs.

For golang#45713

Change-Id: I9121d08f6e6b11838bca50e6cbd756baeeae867b
Reviewed-on: https://go-review.googlesource.com/c/go/+/364114
Trust: Michael Matloob <[email protected]>
Run-TryBot: Michael Matloob <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Bryan C. Mills <[email protected]>
  • Loading branch information
matloob committed Nov 16, 2021
1 parent 29ec902 commit 40effca
Show file tree
Hide file tree
Showing 25 changed files with 112 additions and 120 deletions.
2 changes: 1 addition & 1 deletion src/cmd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.18
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
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VA
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=
Expand Down
8 changes: 4 additions & 4 deletions src/cmd/go/alldocs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/cmd/go/internal/modload/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ func loadWorkFile(path string) (goVersion string, modRoots []string, replaces []
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)
Expand Down Expand Up @@ -606,7 +606,7 @@ func WriteWorkFile(path string, wf *modfile.WorkFile) error {
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
Expand All @@ -620,7 +620,7 @@ func UpdateWorkFile(wf *modfile.WorkFile) {
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)
}
}

Expand Down Expand Up @@ -887,7 +887,7 @@ func CreateWorkFile(ctx context.Context, workFile string, modDirs []string) {
}
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)
Expand Down
40 changes: 20 additions & 20 deletions src/cmd/go/internal/workcmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ This reformatting is also implied by any other modifications that use or
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
Expand All @@ -52,7 +52,7 @@ The -dropreplace=old[@v] flag drops a replacement of the given
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.
Expand All @@ -74,7 +74,7 @@ writing it back to go.mod. The JSON output corresponds to these Go types:
Replace []Replace
}
type Directory struct {
type Use struct {
Path string
ModulePath string
}
Expand Down Expand Up @@ -106,8 +106,8 @@ func (f flagFunc) Set(s string) error { f(s); return nil }
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", "")

Expand Down Expand Up @@ -182,25 +182,25 @@ func runEditwork(ctx context.Context, cmd *base.Command, args []string) {
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)
}
})
Expand Down Expand Up @@ -287,8 +287,8 @@ func editPrintJSON(workFile *modfile.WorkFile) {
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 {
Expand All @@ -304,12 +304,12 @@ func editPrintJSON(workFile *modfile.WorkFile) {

// 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"`
}
6 changes: 3 additions & 3 deletions src/cmd/go/internal/workcmd/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func runUse(ctx context.Context, cmd *base.Command, args []string) {
}

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
}

Expand Down Expand Up @@ -105,10 +105,10 @@ func runUse(ctx context.Context, cmd *base.Command, args []string) {
}

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)
Expand Down
10 changes: 5 additions & 5 deletions src/cmd/go/testdata/script/work.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ go list -mod=readonly all
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
Expand All @@ -59,22 +59,22 @@ go build -n -o foo foo.go
-- 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
Expand Down Expand Up @@ -133,7 +133,7 @@ func main() {
-- go.work.backwards --
go 1.18

directory (
use (
d
b
a
Expand Down
Loading

0 comments on commit 40effca

Please sign in to comment.