Skip to content

Commit

Permalink
cmd/go: permit installing into a subdirectory of $GOPATH/bin
Browse files Browse the repository at this point in the history
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 golang#11778.

Change-Id: Ibc9919554e8c275beff54ec8bf919cfaa03b11ba
Reviewed-on: https://go-review.googlesource.com/12938
Run-TryBot: Ian Lance Taylor <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Russ Cox <[email protected]>
  • Loading branch information
ianlancetaylor committed Jul 31, 2015
1 parent 4e0be15 commit 3548a1e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/cmd/go/go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/go/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 3548a1e

Please sign in to comment.