...

Text file src/cmd/go/testdata/script/list_goroot_symlink.txt

Documentation: cmd/go/testdata/script

     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
    15cd $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
    23mkdir $WORK/lib/goroot
    24mkdir $WORK/share/goroot
    25symlink $WORK/share/goroot/src -> $GOROOT${/}src
    26symlink $WORK/lib/goroot/src -> ../../share/goroot/src
    27symlink $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
    37mkdir $WORK/lib/goroot/bin
    38cp $TESTGO_EXE $WORK/lib/goroot/bin/go$GOEXE
    39
    40env GOROOT=''  # Clear to force cmd/go to find GOROOT itself.
    41exec $WORK/lib/goroot/bin/go env GOROOT
    42stdout $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
    47exec $WORK/lib/goroot/bin/go list -f '{{.ImportPath}}: {{.Dir}}' encoding/binary
    48stdout '^encoding/binary: '$WORK${/}lib${/}goroot${/}src${/}encoding${/}binary'$'
    49
    50exec $WORK/lib/goroot/bin/go list -f '{{.ImportPath}}: {{.Dir}}' std
    51stdout '^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
    60exec $WORK/lib/goroot/bin/go list -f '{{.ImportPath}}: {{.Dir}}' .../binary
    61stdout '^encoding/binary: '$WORK${/}lib${/}goroot${/}src${/}encoding${/}binary'$'
    62! stderr .

View as plain text