if env := Getenv("GOROOT"); env != "" {
return filepath.Clean(env)
}
- def := filepath.Clean(runtime.GOROOT())
+ def := ""
+ if r := runtime.GOROOT(); r != "" {
+ def = filepath.Clean(r)
+ }
if runtime.Compiler == "gccgo" {
// gccgo has no real GOROOT, and it certainly doesn't
// depend on the executable's location.
}
}
+ 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)
"path/filepath"
"regexp"
"runtime"
+ "runtime/debug"
"strconv"
"strings"
"sync"
ok = testenv.HasSymlink()
case "case-sensitive":
ok = isCaseSensitive(ts.t)
+ case "trimpath":
+ if info, _ := debug.ReadBuildInfo(); info == nil {
+ ts.fatalf("missing build info")
+ } else {
+ for _, s := range info.Settings {
+ if s.Key == "-trimpath" && s.Value == "true" {
+ ok = true
+ break
+ }
+ }
+ }
default:
if strings.HasPrefix(cond.tag, "exec:") {
prog := cond.tag[len("exec:"):]
# TODO(#51483): when runtime.GOROOT() returns the empty string,
# go/build should default to 'go env GOROOT' instead.
-[short] skip
-
env GOROOT=
env GOROOT_FINAL=
+[trimpath] ! go env GOROOT
+[trimpath] stderr '^go: cannot find GOROOT directory: ''go'' binary is trimmed and GOROOT is not set$'
+[trimpath] stop
+
+
+[short] skip
+
go run .
stdout '^GOROOT '$TESTGO_GOROOT'$'
stdout '^runtime '$TESTGO_GOROOT${/}src${/}runtime'$'