]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: list directories in module cache replacements
authorJay Conrod <jayconrod@google.com>
Tue, 5 Mar 2019 19:53:03 +0000 (14:53 -0500)
committerJay Conrod <jayconrod@google.com>
Fri, 15 Mar 2019 21:45:04 +0000 (21:45 +0000)
"go list" has allowed listing directory paths to packages in the
module cache since CL 126715. This is sometimes necessary for tools
gathering package information about source files in imported packages.

With this change, we only allow directories in the module cache for
modules in the build list after replacements are applied. Previously,
we ignored replacements when expanding file system path patterns while
constructing the build list.

Fixes #29548

Change-Id: Ic7f89122c4656c8967c14545cb7117f98e89e721
Reviewed-on: https://go-review.googlesource.com/c/go/+/165381
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/cmd/go/internal/modload/load.go
src/cmd/go/testdata/script/mod_list_replace_dir.txt [new file with mode: 0644]

index 33b53052d8d3b741916b143c3fae78ef6747c91d..71b7308c0da3bec4a6c159417db2c1eeb3750cdd 100644 (file)
@@ -212,7 +212,18 @@ func ImportPaths(patterns []string) []*search.Match {
 // if dir is in the module cache copy of a module in our build list.
 func pathInModuleCache(dir string) string {
        for _, m := range buildList[1:] {
-               root, err := modfetch.DownloadDir(m)
+               var root string
+               var err error
+               if repl := Replacement(m); repl.Path != "" && repl.Version == "" {
+                       root = repl.Path
+                       if !filepath.IsAbs(root) {
+                               root = filepath.Join(ModRoot(), root)
+                       }
+               } else if repl.Path != "" {
+                       root, err = modfetch.DownloadDir(repl)
+               } else {
+                       root, err = modfetch.DownloadDir(m)
+               }
                if err != nil {
                        continue
                }
diff --git a/src/cmd/go/testdata/script/mod_list_replace_dir.txt b/src/cmd/go/testdata/script/mod_list_replace_dir.txt
new file mode 100644 (file)
index 0000000..37de882
--- /dev/null
@@ -0,0 +1,19 @@
+# Test that "go list" succeeds when given a directory in a replacement
+# module within the module cache.
+# Verifies golang.org/issue/29548
+
+env GO111MODULE=on
+go mod download
+
+! go list $GOPATH/pkg/mod/rsc.io/quote@v1.5.2
+stderr 'outside available modules'
+
+go list $GOPATH/pkg/mod/rsc.io/quote@v1.5.1
+stdout 'rsc.io/quote'
+
+-- go.mod --
+module example.com/quoter
+
+require rsc.io/quote v1.5.2
+
+replace rsc.io/quote => rsc.io/quote v1.5.1