"errors"
"fmt"
"go/ast"
+ "go/build"
"go/token"
"io"
"math/big"
"os"
"path/filepath"
- "runtime"
"strconv"
"text/scanner"
)
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"}
)
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"
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)