summaryrefslogtreecommitdiff
path: root/src/pkg/go/build/path.go
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2012-01-30 15:38:19 +0100
committerOndřej Surý <ondrej@sury.org>2012-01-30 15:38:19 +0100
commit4cecda6c347bd6902b960c6a35a967add7070b0d (patch)
treea462e224ff41ec9f3eb1a0b6e815806f9e8804ad /src/pkg/go/build/path.go
parent6c7ca6e4d4e26e4c8cbe0d183966011b3b088a0a (diff)
downloadgolang-4cecda6c347bd6902b960c6a35a967add7070b0d.tar.gz
Imported Upstream version 2012.01.27upstream-weekly/2012.01.27
Diffstat (limited to 'src/pkg/go/build/path.go')
-rw-r--r--src/pkg/go/build/path.go29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/pkg/go/build/path.go b/src/pkg/go/build/path.go
index e39b5f8fa..7e931faff 100644
--- a/src/pkg/go/build/path.go
+++ b/src/pkg/go/build/path.go
@@ -5,8 +5,8 @@
package build
import (
+ "errors"
"fmt"
- "log"
"os"
"path/filepath"
"runtime"
@@ -21,9 +21,9 @@ type Tree struct {
Goroot bool
}
-func newTree(p string) (*Tree, os.Error) {
+func newTree(p string) (*Tree, error) {
if !filepath.IsAbs(p) {
- return nil, os.NewError("must be absolute")
+ return nil, errors.New("must be absolute")
}
ep, err := filepath.EvalSymlinks(p)
if err != nil {
@@ -56,7 +56,7 @@ func (t *Tree) PkgDir() string {
func (t *Tree) BinDir() string {
if t.Goroot {
if gobin := os.Getenv("GOBIN"); gobin != "" {
- return gobin
+ return filepath.Clean(gobin)
}
}
return filepath.Join(t.Path, "bin")
@@ -69,7 +69,7 @@ func (t *Tree) HasSrc(pkg string) bool {
if err != nil {
return false
}
- return fi.IsDirectory()
+ return fi.IsDir()
}
// HasPkg returns whether the given package's
@@ -79,18 +79,17 @@ func (t *Tree) HasPkg(pkg string) bool {
if err != nil {
return false
}
- return fi.IsRegular()
- // TODO(adg): check object version is consistent
+ return !fi.IsDir()
}
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")
+ ErrNotFound = errors.New("package could not be found locally")
+ ErrTreeNotFound = errors.New("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.
-func FindTree(path string) (tree *Tree, pkg string, err os.Error) {
+func FindTree(path string) (tree *Tree, pkg string, err error) {
if isLocalPath(path) {
if path, err = filepath.Abs(path); err != nil {
return
@@ -104,14 +103,14 @@ func FindTree(path string) (tree *Tree, pkg string, err os.Error) {
continue
}
tree = t
- pkg = path[len(tpath):]
+ pkg = filepath.ToSlash(path[len(tpath):])
return
}
err = fmt.Errorf("path %q not inside a GOPATH", path)
return
}
tree = defaultTree
- pkg = path
+ pkg = filepath.ToSlash(path)
for _, t := range Path {
if t.HasSrc(pkg) {
tree = t
@@ -149,9 +148,7 @@ var (
func init() {
root := runtime.GOROOT()
t, err := newTree(root)
- if err != nil {
- log.Printf("go/build: invalid GOROOT %q: %v", root, err)
- } else {
+ if err == nil {
t.Goroot = true
Path = []*Tree{t}
}
@@ -162,9 +159,9 @@ func init() {
}
t, err := newTree(p)
if err != nil {
- log.Printf("go/build: invalid GOPATH %q: %v", p, err)
continue
}
+
Path = append(Path, t)
gcImportArgs = append(gcImportArgs, "-I", t.PkgDir())
ldImportArgs = append(ldImportArgs, "-L", t.PkgDir())