|
| 1 | +# Regression test for https://go.dev/issue/57754: 'go list' failed if ../src |
| 2 | +# relative to the location of the go executable was a symlink to the real src |
| 3 | +# directory. (cmd/go expects that ../src is GOROOT/src, but it appears that the |
| 4 | +# Debian build of the Go toolchain is attempting to split GOROOT into binary and |
| 5 | +# source artifacts in different parent directories.) |
| 6 | + |
| 7 | +[short] skip 'copies the cmd/go binary' |
| 8 | +[!symlink] skip 'tests symlink-specific behavior' |
| 9 | + |
| 10 | +# Ensure that the relative path to $WORK/lib/goroot/src from $PWD is a different |
| 11 | +# number of ".." hops than the relative path to it from $WORK/share/goroot/src. |
| 12 | + |
| 13 | +cd $WORK |
| 14 | + |
| 15 | +# Construct a fake GOROOT in $WORK/lib/goroot whose src directory is a symlink |
| 16 | +# to a subdirectory of $WORK/share. This mimics the directory structure reported |
| 17 | +# in https://go.dev/issue/57754. |
| 18 | +# |
| 19 | +# Symlink everything else to the original $GOROOT to avoid needless copying work. |
| 20 | + |
| 21 | +mkdir $WORK/lib/goroot |
| 22 | +mkdir $WORK/share/goroot |
| 23 | +symlink $WORK/share/goroot/src -> $GOROOT${/}src |
| 24 | +symlink $WORK/lib/goroot/src -> ../../share/goroot/src |
| 25 | +symlink $WORK/lib/goroot/pkg -> $GOROOT${/}pkg |
| 26 | + |
| 27 | +# Verify that our symlink shenanigans don't prevent cmd/go from finding its |
| 28 | +# GOROOT using os.Executable. |
| 29 | +# |
| 30 | +# To do so, we copy the actual cmd/go executable — which is implemented as the |
| 31 | +# cmd/go test binary instead of the original $GOROOT/bin/go, which may be |
| 32 | +# arbitrarily stale — into the bin subdirectory of the fake GOROOT, causing |
| 33 | +# os.Executable to report a path in that directory. |
| 34 | + |
| 35 | +mkdir $WORK/lib/goroot/bin |
| 36 | +cp $TESTGO_EXE $WORK/lib/goroot/bin/go$GOEXE |
| 37 | + |
| 38 | +env GOROOT='' # Clear to force cmd/go to find GOROOT itself. |
| 39 | +exec $WORK/lib/goroot/bin/go env GOROOT |
| 40 | +stdout $WORK${/}lib${/}goroot |
| 41 | + |
| 42 | +# Now verify that 'go list' can find standard-library packages in the symlinked |
| 43 | +# source tree, with paths matching the one reported by 'go env GOROOT'. |
| 44 | + |
| 45 | +exec $WORK/lib/goroot/bin/go list -f '{{.ImportPath}}: {{.Dir}}' encoding/binary |
| 46 | +stdout '^encoding/binary: '$WORK${/}lib${/}goroot${/}src${/}encoding${/}binary'$' |
| 47 | + |
| 48 | + # BUG(#50807): This doesn't work on Windows for some reason — perhaps |
| 49 | + # a bug in the Windows Lstat implementation with trailing separators? |
| 50 | +[!GOOS:windows] exec $WORK/lib/goroot/bin/go list -f '{{.ImportPath}}: {{.Dir}}' std |
| 51 | +[!GOOS:windows] stdout '^encoding/binary: '$WORK${/}lib${/}goroot${/}src${/}encoding${/}binary'$' |
| 52 | + |
| 53 | +# Most path lookups in GOROOT are not sensitive to symlinks. However, patterns |
| 54 | +# involving '...' wildcards must use Walk to check the GOROOT tree, which makes |
| 55 | +# them more sensitive to symlinks (because Walk doesn't follow them). |
| 56 | +# |
| 57 | +# So we check such a pattern to confirm that it works and reports a path relative |
| 58 | +# to $GOROOT/src (and not the symlink target). |
| 59 | + |
| 60 | + # BUG(#50807): This should report encoding/binary, not "matched no packages". |
| 61 | +exec $WORK/lib/goroot/bin/go list -f '{{.ImportPath}}: {{.Dir}}' .../binary |
| 62 | +! stdout . |
| 63 | +stderr '^go: warning: "\.\.\./binary" matched no packages$' |
0 commit comments