]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: correct GoMod field in 'go list' for replacements that lack an explicit go...
authorBryan C. Mills <bcmills@google.com>
Thu, 24 Oct 2019 15:29:33 +0000 (11:29 -0400)
committerBryan C. Mills <bcmills@google.com>
Thu, 24 Oct 2019 17:40:35 +0000 (17:40 +0000)
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>
src/cmd/go/internal/modload/build.go
src/cmd/go/testdata/mod/not-rsc.io_quote_v0.1.0-nomod.txt [new file with mode: 0644]
src/cmd/go/testdata/script/mod_replace.txt

index f31f60a448b6684cd8078fe3fda52f7ef94ae88c..acbebb6d662a4fff4caded3d4c3beb9e0dfd2810 100644 (file)
@@ -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
 }
diff --git a/src/cmd/go/testdata/mod/not-rsc.io_quote_v0.1.0-nomod.txt b/src/cmd/go/testdata/mod/not-rsc.io_quote_v0.1.0-nomod.txt
new file mode 100644 (file)
index 0000000..efff088
--- /dev/null
@@ -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)
+       }
+}
index e4301b50d0d00fe97e5044f524c4e14853d8760f..c21f1720021559032a9c8f9c8876999481126612 100644 (file)
@@ -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