]> Cypherpunks repositories - gostls13.git/commitdiff
exp/types: Use build.FindTree in GcImporter
authorJames Whitehead <jnwhiteh@gmail.com>
Fri, 10 Feb 2012 21:35:03 +0000 (13:35 -0800)
committerRobert Griesemer <gri@golang.org>
Fri, 10 Feb 2012 21:35:03 +0000 (13:35 -0800)
Fixes #2932

R=gri
CC=golang-dev
https://golang.org/cl/5654046

src/pkg/exp/types/gcimporter.go
src/pkg/exp/types/gcimporter_test.go

index a573fbb2463edc4f7741cd041263df37fdc8e9f3..8b28aede1ecf1b9ce47d8e336245f714bd355de2 100644 (file)
@@ -11,12 +11,12 @@ import (
        "errors"
        "fmt"
        "go/ast"
+       "go/build"
        "go/token"
        "io"
        "math/big"
        "os"
        "path/filepath"
-       "runtime"
        "strconv"
        "text/scanner"
 )
@@ -24,7 +24,6 @@ import (
 const trace = false // set to true for debugging
 
 var (
-       pkgRoot = filepath.Join(runtime.GOROOT(), "pkg", runtime.GOOS+"_"+runtime.GOARCH)
        pkgExts = [...]string{".a", ".5", ".6", ".8"}
 )
 
@@ -39,8 +38,12 @@ func findPkg(path string) (filename, id string) {
        var noext string
        switch path[0] {
        default:
-               // "x" -> "$GOROOT/pkg/$GOOS_$GOARCH/x.ext", "x"
-               noext = filepath.Join(pkgRoot, path)
+               // "x" -> "$GOPATH/pkg/$GOOS_$GOARCH/x.ext", "x"
+               tree, pkg, err := build.FindTree(path)
+               if err != nil {
+                       return
+               }
+               noext = filepath.Join(tree.PkgDir(), pkg)
 
        case '.':
                // "./x" -> "/this/directory/x.ext", "/this/directory/x"
index 912d467ea08ca87077bd2d035eff1f1956bcd190..5411f3bccef61c16e81d99d3d4ff85d720c4334a 100644 (file)
@@ -61,7 +61,7 @@ func testPath(t *testing.T, path string) bool {
 const maxTime = 3 * time.Second
 
 func testDir(t *testing.T, dir string, endTime time.Time) (nimports int) {
-       dirname := filepath.Join(pkgRoot, dir)
+       dirname := filepath.Join(runtime.GOROOT(), "pkg", runtime.GOOS+"_"+runtime.GOARCH, dir)
        list, err := ioutil.ReadDir(dirname)
        if err != nil {
                t.Errorf("testDir(%s): %s", dirname, err)