]> Cypherpunks repositories - gostls13.git/commitdiff
go/build: fix ImportDir to report PkgTarget for directories in GOROOT/GOPATH
authorRuss Cox <rsc@golang.org>
Wed, 1 Nov 2017 20:12:40 +0000 (16:12 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 2 Nov 2017 03:33:33 +0000 (03:33 +0000)
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: David Crawshaw <crawshaw@golang.org>
src/go/build/build.go
src/go/build/build_test.go

index d8163d01723cfa77005b6f356cb7f4051071b726..68fb423983878eb9b960be6a3bd4f6182a5bd14b 100644 (file)
@@ -544,6 +544,7 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa
                                p.Goroot = true
                                p.ImportPath = sub
                                p.Root = ctxt.GOROOT
+                               setPkga() // p.ImportPath changed
                                goto Found
                        }
                }
@@ -571,6 +572,7 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa
                                // Record it.
                                p.ImportPath = sub
                                p.Root = root
+                               setPkga() // p.ImportPath changed
                                goto Found
                        }
                }
index 979f76c177357100c9c1abc304c1d54cd364c024..ac5d2c3bb98d3ac8c84bd1cdae014cd130b47dfb 100644 (file)
@@ -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)
        }
 }
+
+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)
+       }
+}