aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2019-02-21 12:00:12 -0500
committerBryan C. Mills <bcmills@google.com>2019-05-06 20:25:45 +0000
commit4a1d39bb8072c1805b37c6b07037f1a151ee9f58 (patch)
tree78e7b8bdac73b63841ac7620560f255a0a448160
parente02d81890f6737ef479dd296e51efcdcd33c04b7 (diff)
downloadgo-4a1d39bb8072c1805b37c6b07037f1a151ee9f58.tar.gz
go-4a1d39bb8072c1805b37c6b07037f1a151ee9f58.zip
[release-branch.go1.12] cmd/go/internal/imports: use the full path to resolve symlinks
info.Name returns a name relative to the directory, so we need to prefix that directory in the Stat call. (This was missed in CL 141097 due to the fact that the test only happened to check symlinks in the current directory.) This allows the misc/ tests to work in module mode on platforms that support symlinks. Updates #30228 Updates #28107 Fixes #31763 Change-Id: Ie31836382df0cbd7d203b7a8b637c4743d68b6f3 Reviewed-on: https://go-review.googlesource.com/c/163517 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/175441 Reviewed-by: Andrew Bonventre <andybons@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
-rw-r--r--src/cmd/go/internal/imports/scan.go2
-rw-r--r--src/cmd/go/testdata/script/mod_symlink.txt29
2 files changed, 25 insertions, 6 deletions
diff --git a/src/cmd/go/internal/imports/scan.go b/src/cmd/go/internal/imports/scan.go
index 966a38cfef..3d9b6132b1 100644
--- a/src/cmd/go/internal/imports/scan.go
+++ b/src/cmd/go/internal/imports/scan.go
@@ -26,7 +26,7 @@ func ScanDir(dir string, tags map[string]bool) ([]string, []string, error) {
// If the directory entry is a symlink, stat it to obtain the info for the
// link target instead of the link itself.
if info.Mode()&os.ModeSymlink != 0 {
- info, err = os.Stat(name)
+ info, err = os.Stat(filepath.Join(dir, name))
if err != nil {
continue // Ignore broken symlinks.
}
diff --git a/src/cmd/go/testdata/script/mod_symlink.txt b/src/cmd/go/testdata/script/mod_symlink.txt
index 61da3cc355..49bece2b84 100644
--- a/src/cmd/go/testdata/script/mod_symlink.txt
+++ b/src/cmd/go/testdata/script/mod_symlink.txt
@@ -2,16 +2,31 @@ env GO111MODULE=on
[!symlink] skip
# 'go list' should resolve modules of imported packages.
-go list -deps -f '{{.Module}}'
+go list -deps -f '{{.Module}}' .
stdout golang.org/x/text
-# They should continue to resolve if the importing file is a symlink.
+go list -deps -f '{{.Module}}' ./subpkg
+stdout golang.org/x/text
+
+# Create a copy of the module using symlinks in src/links.
mkdir links
+symlink links/go.mod -> $GOPATH/src/go.mod
+symlink links/issue.go -> $GOPATH/src/issue.go
+mkdir links/subpkg
+symlink links/subpkg/issue.go -> $GOPATH/src/subpkg/issue.go
+
+# We should see the copy as a valid module root.
cd links
-symlink go.mod -> ../go.mod
-symlink issue.go -> ../issue.go
+go env GOMOD
+stdout links[/\\]go.mod
+go list -m
+stdout golang.org/issue/28107
-go list -deps -f '{{.Module}}'
+# The symlink-based copy should contain the same packages
+# and have the same dependencies as the original.
+go list -deps -f '{{.Module}}' .
+stdout golang.org/x/text
+go list -deps -f '{{.Module}}' ./subpkg
stdout golang.org/x/text
-- go.mod --
@@ -21,3 +36,7 @@ module golang.org/issue/28107
package issue
import _ "golang.org/x/text/language"
+-- subpkg/issue.go --
+package issue
+
+import _ "golang.org/x/text/language"