From 1518a244642df4eb2c999d1161b08a21dd9e1f18 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Thu, 31 Oct 2013 10:56:33 -0400 Subject: [PATCH] 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 --- importer/util.go | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/importer/util.go b/importer/util.go index 7b9796a2..262c39f9 100644 --- a/importer/util.go +++ b/importer/util.go @@ -12,22 +12,11 @@ import ( "go/build" "go/parser" "go/token" - "os" "path/filepath" "strconv" "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, // then loads, parses and returns them. // @@ -42,9 +31,8 @@ func parsePackageFiles(ctxt *build.Context, fset *token.FileSet, path string, wh ctxt2 := *ctxt ctxt2.CgoEnabled = false - // TODO(adonovan): fix: Do we need cwd? Shouldn't - // ImportDir(path) / $GOROOT suffice? - bp, err := ctxt2.Import(path, cwd, 0) + // Import(srcDir="") disables local imports, e.g. import "./foo". + bp, err := ctxt2.Import(path, "", 0) if _, ok := err.(*build.NoGoError); ok { return nil, nil // empty directory }