go.tools/importer: don't pass srcDir=os.Getwd to go/build.Import().
This makes imports independent of the process's working directory. (Perhaps this was a feature, but I haven't found a situation in which it actually works.) R=gri CC=golang-dev https://golang.org/cl/19420043
This commit is contained in:
parent
f4fca995ad
commit
1518a24464
|
|
@ -12,22 +12,11 @@ import (
|
||||||
"go/build"
|
"go/build"
|
||||||
"go/parser"
|
"go/parser"
|
||||||
"go/token"
|
"go/token"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cwd string
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
var err error
|
|
||||||
cwd, err = os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
panic("getcwd failed: " + err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// parsePackageFiles enumerates the files belonging to package path,
|
// parsePackageFiles enumerates the files belonging to package path,
|
||||||
// then loads, parses and returns them.
|
// then loads, parses and returns them.
|
||||||
//
|
//
|
||||||
|
|
@ -42,9 +31,8 @@ func parsePackageFiles(ctxt *build.Context, fset *token.FileSet, path string, wh
|
||||||
ctxt2 := *ctxt
|
ctxt2 := *ctxt
|
||||||
ctxt2.CgoEnabled = false
|
ctxt2.CgoEnabled = false
|
||||||
|
|
||||||
// TODO(adonovan): fix: Do we need cwd? Shouldn't
|
// Import(srcDir="") disables local imports, e.g. import "./foo".
|
||||||
// ImportDir(path) / $GOROOT suffice?
|
bp, err := ctxt2.Import(path, "", 0)
|
||||||
bp, err := ctxt2.Import(path, cwd, 0)
|
|
||||||
if _, ok := err.(*build.NoGoError); ok {
|
if _, ok := err.(*build.NoGoError); ok {
|
||||||
return nil, nil // empty directory
|
return nil, nil // empty directory
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue