mirror of
https://github.com/golang/go
synced 2024-11-05 16:26:11 -07:00
cmd/go: correct GoMod field in 'go list' for replacements that lack an explicit go.mod file
Change-Id: I241a3bbaf9c4b779b74146232d2f144bb46a0dc7 Reviewed-on: https://go-review.googlesource.com/c/go/+/203178 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
parent
bd622872f4
commit
f922cc6446
@ -179,11 +179,12 @@ func moduleInfo(m module.Version, fromBuildList bool) *modinfo.ModulePublic {
|
||||
} else {
|
||||
info.Replace.Dir = filepath.Join(ModRoot(), r.Path)
|
||||
}
|
||||
info.Replace.GoMod = filepath.Join(info.Replace.Dir, "go.mod")
|
||||
}
|
||||
if cfg.BuildMod != "vendor" {
|
||||
completeFromModCache(info.Replace)
|
||||
info.Dir = info.Replace.Dir
|
||||
info.GoMod = filepath.Join(info.Dir, "go.mod")
|
||||
info.GoMod = info.Replace.GoMod
|
||||
}
|
||||
return info
|
||||
}
|
||||
|
59
src/cmd/go/testdata/mod/not-rsc.io_quote_v0.1.0-nomod.txt
vendored
Normal file
59
src/cmd/go/testdata/mod/not-rsc.io_quote_v0.1.0-nomod.txt
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
Constructed by hand.
|
||||
(derived from rsc.io/quote@e7a685a342, but without an explicit go.mod file.)
|
||||
|
||||
-- .mod --
|
||||
module "not-rsc.io/quote"
|
||||
-- .info --
|
||||
{"Version":"v0.1.0-nomod","Time":"2018-02-14T00:51:33Z"}
|
||||
-- quote.go --
|
||||
// Copyright 2018 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package quote collects pithy sayings.
|
||||
package quote // import "rsc.io/quote"
|
||||
|
||||
// Hello returns a greeting.
|
||||
func Hello() string {
|
||||
return "Hello, world."
|
||||
}
|
||||
|
||||
// Glass returns a useful phrase for world travelers.
|
||||
func Glass() string {
|
||||
// See http://www.oocities.org/nodotus/hbglass.html.
|
||||
return "I can eat glass and it doesn't hurt me."
|
||||
}
|
||||
|
||||
// Go returns a Go proverb.
|
||||
func Go() string {
|
||||
return "Don't communicate by sharing memory, share memory by communicating."
|
||||
}
|
||||
-- quote_test.go --
|
||||
// Copyright 2018 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package quote
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestHello(t *testing.T) {
|
||||
hello := "Hello, world."
|
||||
if out := Hello(); out != hello {
|
||||
t.Errorf("Hello() = %q, want %q", out, hello)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGlass(t *testing.T) {
|
||||
glass := "I can eat glass and it doesn't hurt me."
|
||||
if out := Glass(); out != glass {
|
||||
t.Errorf("Glass() = %q, want %q", out, glass)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGo(t *testing.T) {
|
||||
go1 := "Don't communicate by sharing memory. Share memory by communicating."
|
||||
if out := Go(); out != go1 {
|
||||
t.Errorf("Go() = %q, want %q", out, go1)
|
||||
}
|
||||
}
|
7
src/cmd/go/testdata/script/mod_replace.txt
vendored
7
src/cmd/go/testdata/script/mod_replace.txt
vendored
@ -45,6 +45,13 @@ go mod edit -replace=rsc.io/quote/v3=./local/rsc.io/quote/v3
|
||||
! go get -d rsc.io/quote/v3/missing-package
|
||||
stderr 'module rsc.io/quote/v3@upgrade found \(v3.0.0, replaced by ./local/rsc.io/quote/v3\), but does not contain package'
|
||||
|
||||
# The reported Dir and GoMod for a replaced module should be accurate.
|
||||
cp go.mod.orig go.mod
|
||||
go mod edit -replace=rsc.io/quote/v3=not-rsc.io/quote@v0.1.0-nomod
|
||||
go mod download
|
||||
go list -m -f '{{.Path}} {{.Version}} {{.Dir}} {{.GoMod}}{{with .Replace}} => {{.Path}} {{.Version}} {{.Dir}} {{.GoMod}}{{end}}' rsc.io/quote/v3
|
||||
stdout '^rsc.io/quote/v3 v3.0.0 '$GOPATH'[/\\]pkg[/\\]mod[/\\]not-rsc.io[/\\]quote@v0.1.0-nomod '$GOPATH'[/\\]pkg[/\\]mod[/\\]cache[/\\]download[/\\]not-rsc.io[/\\]quote[/\\]@v[/\\]v0.1.0-nomod.mod => not-rsc.io/quote v0.1.0-nomod '$GOPATH'[/\\]pkg[/\\]mod[/\\]not-rsc.io[/\\]quote@v0.1.0-nomod '$GOPATH'[/\\]pkg[/\\]mod[/\\]cache[/\\]download[/\\]not-rsc.io[/\\]quote[/\\]@v[/\\]v0.1.0-nomod.mod$'
|
||||
|
||||
-- go.mod --
|
||||
module quoter
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user