]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.13] cmd/go/internal/modload: annotate replacements in PackageNotI...
authorBryan C. Mills <bcmills@google.com>
Thu, 5 Sep 2019 16:45:15 +0000 (12:45 -0400)
committerBryan C. Mills <bcmills@google.com>
Thu, 26 Sep 2019 15:29:22 +0000 (15:29 +0000)
Updates #34085
Fixes #34118

Change-Id: I3111f5997466ad33f51e80c71f5fb2ccebdcc6e4
Reviewed-on: https://go-review.googlesource.com/c/go/+/193617
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
(cherry picked from commit 8189a06190046cd69819ad1c6399943be0ee5c2d)
Reviewed-on: https://go-review.googlesource.com/c/go/+/197317

src/cmd/go/internal/modload/import_test.go
src/cmd/go/internal/modload/load.go
src/cmd/go/internal/modload/query.go
src/cmd/go/testdata/script/mod_get_patterns.txt
src/cmd/go/testdata/script/mod_replace.txt

index c6ade5d17f4e00a38a3b78d1bceb8a3a46d79fee..c58892e2ab2a93c6e44f64ffaf8db4a376ec1ffa 100644 (file)
@@ -21,7 +21,7 @@ var importTests = []struct {
        },
        {
                path: "golang.org/x/net",
-               err:  "module golang.org/x/net@.* found, but does not contain package golang.org/x/net",
+               err:  `module golang.org/x/net@.* found \(v0.0.0-.*\), but does not contain package golang.org/x/net`,
        },
        {
                path: "golang.org/x/text",
index b50a084166d446c54a4a9fa34970ea3bc21493d9..92e76a924603695ba374cec25d9ab727ab3a9502 100644 (file)
@@ -1205,6 +1205,11 @@ func (*mvsReqs) next(m module.Version) (module.Version, error) {
        return module.Version{Path: m.Path, Version: "none"}, nil
 }
 
+// fetch downloads the given module (or its replacement)
+// and returns its location.
+//
+// The isLocal return value reports whether the replacement,
+// if any, is local to the filesystem.
 func fetch(mod module.Version) (dir string, isLocal bool, err error) {
        if mod == Target {
                return ModRoot(), true, nil
index f3c003a7cddeabc7ea0ae252a19c3dca1f611bf5..0359470d95e80071a156ab6a47a2d059c22c1f4e 100644 (file)
@@ -381,9 +381,10 @@ func QueryPattern(pattern, query string, allowed func(module.Version) bool) ([]Q
                        r.Packages = match(r.Mod, root, isLocal)
                        if len(r.Packages) == 0 {
                                return r, &PackageNotInModuleError{
-                                       Mod:     r.Mod,
-                                       Query:   query,
-                                       Pattern: pattern,
+                                       Mod:         r.Mod,
+                                       Replacement: Replacement(r.Mod),
+                                       Query:       query,
+                                       Pattern:     pattern,
                                }
                        }
                        return r, nil
@@ -536,21 +537,32 @@ func (e *NoMatchingVersionError) Error() string {
 // code for the versions it knows about, and thus did not have the opportunity
 // to return a non-400 status code to suppress fallback.
 type PackageNotInModuleError struct {
-       Mod     module.Version
-       Query   string
-       Pattern string
+       Mod         module.Version
+       Replacement module.Version
+       Query       string
+       Pattern     string
 }
 
 func (e *PackageNotInModuleError) Error() string {
        found := ""
-       if e.Query != e.Mod.Version {
+       if r := e.Replacement; r.Path != "" {
+               replacement := r.Path
+               if r.Version != "" {
+                       replacement = fmt.Sprintf("%s@%s", r.Path, r.Version)
+               }
+               if e.Query == e.Mod.Version {
+                       found = fmt.Sprintf(" (replaced by %s)", replacement)
+               } else {
+                       found = fmt.Sprintf(" (%s, replaced by %s)", e.Mod.Version, replacement)
+               }
+       } else if e.Query != e.Mod.Version {
                found = fmt.Sprintf(" (%s)", e.Mod.Version)
        }
 
        if strings.Contains(e.Pattern, "...") {
-               return fmt.Sprintf("module %s@%s%s found, but does not contain packages matching %s", e.Mod.Path, e.Query, found, e.Pattern)
+               return fmt.Sprintf("module %s@%s found%s, but does not contain packages matching %s", e.Mod.Path, e.Query, found, e.Pattern)
        }
-       return fmt.Sprintf("module %s@%s%s found, but does not contain package %s", e.Mod.Path, e.Query, found, e.Pattern)
+       return fmt.Sprintf("module %s@%s found%s, but does not contain package %s", e.Mod.Path, e.Query, found, e.Pattern)
 }
 
 // ModuleHasRootPackage returns whether module m contains a package m.Path.
index bfab70090cfaaa661bbb29f9f4535ff58d6d7997..8adc4b0c06579d96896e68f70faedf6b5dc7714b 100644 (file)
@@ -10,11 +10,11 @@ grep 'require rsc.io/quote' go.mod
 
 cp go.mod.orig go.mod
 ! go get -d rsc.io/quote/x...
-stderr 'go get rsc.io/quote/x...: module rsc.io/quote@upgrade \(v1.5.2\) found, but does not contain packages matching rsc.io/quote/x...'
+stderr 'go get rsc.io/quote/x...: module rsc.io/quote@upgrade found \(v1.5.2\), but does not contain packages matching rsc.io/quote/x...'
 ! grep 'require rsc.io/quote' go.mod
 
 ! go get -d rsc.io/quote/x/...
-stderr 'go get rsc.io/quote/x/...: module rsc.io/quote@upgrade \(v1.5.2\) found, but does not contain packages matching rsc.io/quote/x/...'
+stderr 'go get rsc.io/quote/x/...: module rsc.io/quote@upgrade found \(v1.5.2\), but does not contain packages matching rsc.io/quote/x/...'
 ! grep 'require rsc.io/quote' go.mod
 
 # If a pattern matches no packages within a module, the module should not
index 35824b3a8a212f37c8b50a69e38153bd193ba49b..e4301b50d0d00fe97e5044f524c4e14853d8760f 100644 (file)
@@ -38,6 +38,13 @@ grep 'not-rsc.io/quote/v3 v3.1.0' go.mod
 exec ./a5.exe
 stdout 'Concurrency is not parallelism.'
 
+# Error messages for modules not found in replacements should
+# indicate the replacement module.
+cp go.mod.orig go.mod
+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'
+
 -- go.mod --
 module quoter