"log"
"os"
"path/filepath"
- "runtime"
rtrace "runtime/trace"
"slices"
"strings"
return
}
+ if cfg.GOROOT == "" {
+ fmt.Fprintf(os.Stderr, "go: cannot find GOROOT directory: 'go' binary is trimmed and GOROOT is not set\n")
+ os.Exit(2)
+ }
+ if fi, err := os.Stat(cfg.GOROOT); err != nil || !fi.IsDir() {
+ fmt.Fprintf(os.Stderr, "go: cannot find GOROOT directory: %v\n", cfg.GOROOT)
+ os.Exit(2)
+ }
+
// Diagnose common mistake: GOPATH==GOROOT.
// This setting is equivalent to not setting GOPATH at all,
// which is not what most people want when they do it.
- if gopath := cfg.BuildContext.GOPATH; filepath.Clean(gopath) == filepath.Clean(runtime.GOROOT()) {
+ if gopath := cfg.BuildContext.GOPATH; filepath.Clean(gopath) == filepath.Clean(cfg.GOROOT) {
fmt.Fprintf(os.Stderr, "warning: GOPATH set to GOROOT (%s) has no effect\n", gopath)
} else {
for _, p := range filepath.SplitList(gopath) {
}
}
- if cfg.GOROOT == "" {
- fmt.Fprintf(os.Stderr, "go: cannot find GOROOT directory: 'go' binary is trimmed and GOROOT is not set\n")
- os.Exit(2)
- }
- if fi, err := os.Stat(cfg.GOROOT); err != nil || !fi.IsDir() {
- fmt.Fprintf(os.Stderr, "go: cannot find GOROOT directory: %v\n", cfg.GOROOT)
- os.Exit(2)
- }
-
cmd, used := lookupCmd(args)
cfg.CmdName = strings.Join(args[:used], " ")
if len(cmd.Commands) > 0 {
env TESTGOROOT=$GOROOT
env GOROOT=
+# Unset GOPATH and any variables that its default may be derived from,
+# so that we can check for a spurious warning.
+env GOPATH=
+env HOME=''
+env USERPROFILE=''
+env home=''
+
# Relocated Executable
# Since we built with -trimpath and the binary isn't installed in a
# normal-looking GOROOT, this command should fail.
! exec $WORK/new/bin/go$GOEXE env GOROOT
stderr '^go: cannot find GOROOT directory: ''go'' binary is trimmed and GOROOT is not set$'
+! stderr 'GOPATH set to GOROOT'
# Cross-compiled binaries in cmd are installed to a ${GOOS}_${GOARCH} subdirectory,
# so we also want to try a copy there.
cp $WORK/new/bin/go$GOEXE $WORK/new/bin/${GOOS}_${GOARCH}/go$GOEXE
! exec $WORK/new/bin/${GOOS}_${GOARCH}/go$GOEXE env GOROOT
stderr '^go: cannot find GOROOT directory: ''go'' binary is trimmed and GOROOT is not set$'
+! stderr 'GOPATH set to GOROOT'
# Relocated Tree:
# If the binary is sitting in a bin dir next to ../pkg/tool, that counts as a GOROOT,
mkdir $WORK/new/pkg/tool
exec $WORK/bin/check$GOEXE $WORK/new/bin/go$GOEXE $WORK/new
exec $WORK/bin/check$GOEXE $WORK/new/bin/${GOOS}_${GOARCH}/go$GOEXE $WORK/new
+! stderr 'GOPATH set to GOROOT'
-- check.go --
package main