From 3548a1e7b8691be21d57bec32b875130543d0ea7 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 30 Jul 2015 15:20:12 -0700 Subject: [PATCH] cmd/go: permit installing into a subdirectory of $GOPATH/bin In https://golang.org/cl/12080 we forbade installing cross-compiled binaries into a subdirectory of $GOBIN, in order to fix https://golang.org/issue/9769. However, that fix was too aggressive, in that it also forbade installing into a subdirectory of $GOPATH/bin. This patch permits installing cross-compiled binaries into a subdirectory $GOPATH/bin while continuing to forbid installing into a subdirectory of $GOBIN. Fixes #11778. Change-Id: Ibc9919554e8c275beff54ec8bf919cfaa03b11ba Reviewed-on: https://go-review.googlesource.com/12938 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Russ Cox --- src/cmd/go/go_test.go | 2 +- src/cmd/go/pkg.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index c89543871b..783ae554ba 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -765,7 +765,7 @@ func TestGoInstallErrorOnCrossCompileToBin(t *testing.T) { } tg.setenv("GOOS", "linux") tg.setenv("GOARCH", goarch) - tg.runFail("install", "mycmd") + tg.run("install", "mycmd") tg.setenv("GOBIN", tg.path(".")) tg.runFail("install", "mycmd") tg.run("install", "cmd/pack") diff --git a/src/cmd/go/pkg.go b/src/cmd/go/pkg.go index 98c9594d2e..a2c5ba7e5e 100644 --- a/src/cmd/go/pkg.go +++ b/src/cmd/go/pkg.go @@ -744,8 +744,8 @@ func (p *Package) load(stk *importStack, bp *build.Package, err error) *Package } else if p.build.BinDir != "" { // Install to GOBIN or bin of GOPATH entry. p.target = filepath.Join(p.build.BinDir, elem) - if !p.Goroot && strings.Contains(elem, "/") { - // Do not create bin/goos_goarch/elem. + if !p.Goroot && strings.Contains(elem, "/") && gobin != "" { + // Do not create $GOBIN/goos_goarch/elem. p.target = "" p.gobinSubdir = true } -- 2.48.1