1
0
mirror of https://github.com/golang/go synced 2024-11-25 05:57:57 -07:00

go/build: less aggressive failure when GOROOT not found

R=golang-dev, rsc, dsymonds
CC=golang-dev
https://golang.org/cl/4743041
This commit is contained in:
Andrew Gerrand 2011-07-15 13:45:22 +10:00
parent 29125be5c7
commit 5d929a9c92

View File

@ -13,7 +13,7 @@ import (
"strings" "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 var Path []*Tree
// Tree describes a Go source tree, either $GOROOT or one from $GOPATH. // 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 // 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 // FindTree takes an import or filesystem path and returns the
// tree where the package source should be and the package import path. // 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 return
} }
} }
err = ErrNotFound if tree == nil {
err = ErrTreeNotFound
} else {
err = ErrNotFound
}
return return
} }
@ -133,12 +140,13 @@ var (
// set up Path: parse and validate GOROOT and GOPATH variables // set up Path: parse and validate GOROOT and GOPATH variables
func init() { func init() {
root := runtime.GOROOT() root := runtime.GOROOT()
p, err := newTree(root) t, err := newTree(root)
if err != nil { 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")) { for _, p := range filepath.SplitList(os.Getenv("GOPATH")) {
if p == "" { if p == "" {
@ -146,7 +154,7 @@ func init() {
} }
t, err := newTree(p) t, err := newTree(p)
if err != nil { if err != nil {
log.Printf("Invalid GOPATH %q: %v", p, err) log.Printf("go/build: invalid GOPATH %q: %v", p, err)
continue continue
} }
Path = append(Path, t) Path = append(Path, t)
@ -160,7 +168,7 @@ func init() {
} }
// use GOROOT if no valid GOPATH specified // use GOROOT if no valid GOPATH specified
if defaultTree == nil { if defaultTree == nil && len(Path) > 0 {
defaultTree = Path[0] defaultTree = Path[0]
} }
} }