Commit 21e6612d authored by Russ Cox's avatar Russ Cox

go/build: fix ImportDir to report PkgTarget for directories in GOROOT/GOPATH

This makes ImportDir("$GOROOT/src/math", 0)
and Import("math", "", 0) equivalent. It was an
oversight that they were not before.

An upcoming change to the go command relies on
the two returning the same results.

Change-Id: I187da4830fae85f8dde673c22836ff2da6801047
Reviewed-on: https://go-review.googlesource.com/75290
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarDavid Crawshaw <crawshaw@golang.org>
parent 1114d403
...@@ -544,6 +544,7 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa ...@@ -544,6 +544,7 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa
p.Goroot = true p.Goroot = true
p.ImportPath = sub p.ImportPath = sub
p.Root = ctxt.GOROOT p.Root = ctxt.GOROOT
setPkga() // p.ImportPath changed
goto Found goto Found
} }
} }
...@@ -571,6 +572,7 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa ...@@ -571,6 +572,7 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa
// Record it. // Record it.
p.ImportPath = sub p.ImportPath = sub
p.Root = root p.Root = root
setPkga() // p.ImportPath changed
goto Found goto Found
} }
} }
......
...@@ -382,3 +382,16 @@ func TestImportVendorParentFailure(t *testing.T) { ...@@ -382,3 +382,16 @@ func TestImportVendorParentFailure(t *testing.T) {
t.Fatalf("error on failed import does not mention GOROOT/src/vendor directory:\n%s", e) t.Fatalf("error on failed import does not mention GOROOT/src/vendor directory:\n%s", e)
} }
} }
func TestImportDirTarget(t *testing.T) {
testenv.MustHaveGoBuild(t) // really must just have source
ctxt := Default
ctxt.GOPATH = ""
p, err := ctxt.ImportDir(filepath.Join(ctxt.GOROOT, "src/path"), 0)
if err != nil {
t.Fatal(err)
}
if p.PkgTargetRoot == "" || p.PkgObj == "" {
t.Errorf("p.PkgTargetRoot == %q, p.PkgObj == %q, want non-empty", p.PkgTargetRoot, p.PkgObj)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment