]> Cypherpunks repositories - gostls13.git/commitdiff
go/build: less aggressive failure when GOROOT not found
authorAndrew Gerrand <adg@golang.org>
Fri, 15 Jul 2011 03:45:22 +0000 (13:45 +1000)
committerAndrew Gerrand <adg@golang.org>
Fri, 15 Jul 2011 03:45:22 +0000 (13:45 +1000)
R=golang-dev, rsc, dsymonds
CC=golang-dev
https://golang.org/cl/4743041

src/pkg/go/build/path.go

index ea588abbd6b55380d8ed4974f20f44fdac5c4af7..e21dababd7acd4ed464cbd8d022454099e75ab06 100644 (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
                }
        }
-       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]
        }
 }