diff options
| author | Russ Cox <rsc@golang.org> | 2014-08-07 12:33:19 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2014-08-07 12:33:19 -0400 |
| commit | d078d483ce87b4311f79e988a0b609d3c53d3cb4 (patch) | |
| tree | 4b18e35abd5156407aed6267e3f7cfa815d574f8 /src/pkg | |
| parent | 08033f9816e1e33092c93c050dc34514d8e3e926 (diff) | |
| download | go-d078d483ce87b4311f79e988a0b609d3c53d3cb4.tar.xz | |
go/build: look in $GOROOT/src/cmd/foo/bar for import cmd/foo/bar
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
Diffstat (limited to 'src/pkg')
| -rw-r--r-- | src/pkg/go/build/build.go | 7 | ||||
| -rw-r--r-- | src/pkg/go/build/build_test.go | 10 |
2 files changed, 16 insertions, 1 deletions
diff --git a/src/pkg/go/build/build.go b/src/pkg/go/build/build.go index 09730d6351..6db0275032 100644 --- a/src/pkg/go/build/build.go +++ b/src/pkg/go/build/build.go @@ -521,7 +521,12 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa // 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 { diff --git a/src/pkg/go/build/build_test.go b/src/pkg/go/build/build_test.go index f0d243cd53..0040101134 100644 --- a/src/pkg/go/build/build_test.go +++ b/src/pkg/go/build/build_test.go @@ -193,3 +193,13 @@ func TestMatchFile(t *testing.T) { } } } + +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") + } +} |
