Commit 5b9c6b9e authored by Burcu Dogan's avatar Burcu Dogan Committed by Andrew Gerrand

cmd/go: don't accept a relative path as GOBIN

Fixes #12907.

Change-Id: I5925852fe6962d4ec7dbb3ea5323e8ddfaf9d576
Reviewed-on: https://go-review.googlesource.com/15755Reviewed-by: 's avatarAndrew Gerrand <adg@golang.org>
Run-TryBot: Andrew Gerrand <adg@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent c6ef16b6
......@@ -886,7 +886,7 @@ DIR/bin/quux, not DIR/bin/foo/quux. The "foo/" prefix is stripped
so that you can add DIR/bin to your PATH to get at the
installed commands. If the GOBIN environment variable is
set, commands are installed to the directory it names instead
of DIR/bin.
of DIR/bin. GOBIN must be an absolute path.
Here's an example directory layout:
......
......@@ -501,6 +501,10 @@ func libname(args []string) string {
}
func runInstall(cmd *Command, args []string) {
if gobin != "" && !filepath.IsAbs(gobin) {
fatalf("cannot install, GOBIN must be an absolute path")
}
raceInit()
buildModeInit()
pkgs := pkgsFilter(packagesForBuild(args))
......
......@@ -1145,6 +1145,15 @@ func TestInstallFailsWithNoBuildableFiles(t *testing.T) {
tg.grepStderr("no buildable Go source files", "go install cgotest did not report 'no buildable Go Source files'")
}
func TestRelativeGOBINFail(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.tempFile("triv.go", `package main; func main() {}`)
tg.setenv("GOBIN", ".")
tg.runFail("install")
tg.grepStderr("cannot install, GOBIN must be an absolute path", "go install must fail if $GOBIN is a relative path")
}
// Test that without $GOBIN set, binaries get installed
// into the GOPATH bin directory.
func TestInstallIntoGOPATH(t *testing.T) {
......
......@@ -307,7 +307,7 @@ DIR/bin/quux, not DIR/bin/foo/quux. The "foo/" prefix is stripped
so that you can add DIR/bin to your PATH to get at the
installed commands. If the GOBIN environment variable is
set, commands are installed to the directory it names instead
of DIR/bin.
of DIR/bin. GOBIN must be an absolute path.
Here's an example directory layout:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment