fatalf("$GOROOT must be set")
}
goroot = filepath.Clean(b)
+ if modRoot := findModuleRoot(goroot); modRoot != "" {
+ fatalf("found go.mod file in %s: $GOROOT must not be inside a module", modRoot)
+ }
b = os.Getenv("GOROOT_FINAL")
if b == "" {
}
}
+func findModuleRoot(dir string) (root string) {
+ for {
+ if fi, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil && !fi.IsDir() {
+ return dir
+ }
+ d := filepath.Dir(dir)
+ if d == dir {
+ break
+ }
+ dir = d
+ }
+ return ""
+}
+
func defaulttarg() string {
// xgetwd might return a path with symlinks fully resolved, and if
// there happens to be symlinks in goroot, then the hasprefix test