This lets us have non-main packages like cmd/internal or cmd/nm/internal/whatever.
The src/pkg migration (see golang.org/s/go14mainrepo) will allow this
as a natural side effect. The explicit change here just allows use of the
effect a little sooner.
LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/
117630043
// Determine directory from import path.
if ctxt.GOROOT != "" {
- dir := ctxt.joinPath(ctxt.GOROOT, "src", "pkg", path)
+ var dir string
+ if strings.HasPrefix(path, "cmd/") {
+ dir = ctxt.joinPath(ctxt.GOROOT, "src", path)
+ } else {
+ dir = ctxt.joinPath(ctxt.GOROOT, "src", "pkg", path)
+ }
isDir := ctxt.isDir(dir)
binaryOnly = !isDir && mode&AllowBinary != 0 && pkga != "" && ctxt.isFile(ctxt.joinPath(ctxt.GOROOT, pkga))
if isDir || binaryOnly {
}
}
}
+
+func TestImportCmd(t *testing.T) {
+ p, err := Import("cmd/internal/objfile", "", 0)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !strings.HasSuffix(filepath.ToSlash(p.Dir), "src/cmd/internal/objfile") {
+ t.Fatalf("Import cmd/internal/objfile returned Dir=%q, want %q", filepath.ToSlash(p.Dir), ".../src/cmd/internal/objfile")
+ }
+}