From 5d929a9c9236f146bcb49a1c7a0d29e0b93a76ae Mon Sep 17 00:00:00 2001 From: Andrew Gerrand Date: Fri, 15 Jul 2011 13:45:22 +1000 Subject: [PATCH] go/build: less aggressive failure when GOROOT not found R=golang-dev, rsc, dsymonds CC=golang-dev https://golang.org/cl/4743041 --- src/pkg/go/build/path.go | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/pkg/go/build/path.go b/src/pkg/go/build/path.go index ea588abbd6..e21dababd7 100644 --- a/src/pkg/go/build/path.go +++ b/src/pkg/go/build/path.go @@ -13,7 +13,7 @@ import ( "strings" ) -// Path is a validated list of Trees derived from $GOPATH at init. +// Path is a validated list of Trees derived from $GOROOT and $GOPATH at init. var Path []*Tree // Tree describes a Go source tree, either $GOROOT or one from $GOPATH. @@ -79,7 +79,10 @@ func (t *Tree) HasPkg(pkg string) bool { // TODO(adg): check object version is consistent } -var ErrNotFound = os.NewError("package could not be found locally") +var ( + ErrNotFound = os.NewError("go/build: package could not be found locally") + ErrTreeNotFound = os.NewError("go/build: no valid GOROOT or GOPATH could be found") +) // FindTree takes an import or filesystem path and returns the // tree where the package source should be and the package import path. @@ -111,7 +114,11 @@ func FindTree(path string) (tree *Tree, pkg string, err os.Error) { return } } - err = ErrNotFound + if tree == nil { + err = ErrTreeNotFound + } else { + err = ErrNotFound + } return } @@ -133,12 +140,13 @@ var ( // set up Path: parse and validate GOROOT and GOPATH variables func init() { root := runtime.GOROOT() - p, err := newTree(root) + t, err := newTree(root) if err != nil { - log.Fatalf("Invalid GOROOT %q: %v", root, err) + log.Printf("go/build: invalid GOROOT %q: %v", root, err) + } else { + t.Goroot = true + Path = []*Tree{t} } - p.Goroot = true - Path = []*Tree{p} for _, p := range filepath.SplitList(os.Getenv("GOPATH")) { if p == "" { @@ -146,7 +154,7 @@ func init() { } t, err := newTree(p) if err != nil { - log.Printf("Invalid GOPATH %q: %v", p, err) + log.Printf("go/build: invalid GOPATH %q: %v", p, err) continue } Path = append(Path, t) @@ -160,7 +168,7 @@ func init() { } // use GOROOT if no valid GOPATH specified - if defaultTree == nil { + if defaultTree == nil && len(Path) > 0 { defaultTree = Path[0] } } -- 2.50.0