Commit 5d929a9c authored by Andrew Gerrand's avatar Andrew Gerrand

go/build: less aggressive failure when GOROOT not found

R=golang-dev, rsc, dsymonds
CC=golang-dev
https://golang.org/cl/4743041
parent 29125be5
...@@ -13,7 +13,7 @@ import ( ...@@ -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 { ...@@ -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) { ...@@ -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 ( ...@@ -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() { ...@@ -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() { ...@@ -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]
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment