1
0
mirror of https://github.com/golang/go synced 2024-10-04 01:31:25 -06: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"
)
// 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
}
}
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]
}
}