| 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 |
[GOOS:darwin] skip 'Lstat on darwin does not conform to POSIX pathname resolution; see #59586' |
| 10 |
[GOOS:ios] skip 'Lstat on ios does not conform to POSIX pathname resolution; see #59586' |
| 11 |
|
| 12 |
# Ensure that the relative path to $WORK/lib/goroot/src from $PWD is a different |
| 13 |
# number of ".." hops than the relative path to it from $WORK/share/goroot/src. |
| 14 |
|
| 15 |
cd $WORK |
| 16 |
|
| 17 |
# Construct a fake GOROOT in $WORK/lib/goroot whose src directory is a symlink |
| 18 |
# to a subdirectory of $WORK/share. This mimics the directory structure reported |
| 19 |
# in https://go.dev/issue/57754. |
| 20 |
# |
| 21 |
# Symlink everything else to the original $GOROOT to avoid needless copying work. |
| 22 |
|
| 23 |
mkdir $WORK/lib/goroot |
| 24 |
mkdir $WORK/share/goroot |
| 25 |
symlink $WORK/share/goroot/src -> $GOROOT${/}src |
| 26 |
symlink $WORK/lib/goroot/src -> ../../share/goroot/src |
| 27 |
symlink $WORK/lib/goroot/pkg -> $GOROOT${/}pkg |
| 28 |
|
| 29 |
# Verify that our symlink shenanigans don't prevent cmd/go from finding its |
| 30 |
# GOROOT using os.Executable. |
| 31 |
# |
| 32 |
# To do so, we copy the actual cmd/go executable — which is implemented as the |
| 33 |
# cmd/go test binary instead of the original $GOROOT/bin/go, which may be |
| 34 |
# arbitrarily stale — into the bin subdirectory of the fake GOROOT, causing |
| 35 |
# os.Executable to report a path in that directory. |
| 36 |
|
| 37 |
mkdir $WORK/lib/goroot/bin |
| 38 |
cp $TESTGO_EXE $WORK/lib/goroot/bin/go$GOEXE |
| 39 |
|
| 40 |
env GOROOT='' # Clear to force cmd/go to find GOROOT itself. |
| 41 |
exec $WORK/lib/goroot/bin/go env GOROOT |
| 42 |
stdout $WORK${/}lib${/}goroot |
| 43 |
|
| 44 |
# Now verify that 'go list' can find standard-library packages in the symlinked |
| 45 |
# source tree, with paths matching the one reported by 'go env GOROOT'. |
| 46 |
|
| 47 |
exec $WORK/lib/goroot/bin/go list -f '{{.ImportPath}}: {{.Dir}}' encoding/binary |
| 48 |
stdout '^encoding/binary: '$WORK${/}lib${/}goroot${/}src${/}encoding${/}binary'$' |
| 49 |
|
| 50 |
exec $WORK/lib/goroot/bin/go list -f '{{.ImportPath}}: {{.Dir}}' std |
| 51 |
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 |
exec $WORK/lib/goroot/bin/go list -f '{{.ImportPath}}: {{.Dir}}' .../binary |
| 61 |
stdout '^encoding/binary: '$WORK${/}lib${/}goroot${/}src${/}encoding${/}binary'$' |
| 62 |
! stderr . |