]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: don't accept a relative path as GOBIN
authorBurcu Dogan <jbd@google.com>
Mon, 12 Oct 2015 15:56:05 +0000 (08:56 -0700)
committerAndrew Gerrand <adg@golang.org>
Mon, 12 Oct 2015 23:53:04 +0000 (23:53 +0000)
Fixes #12907.

Change-Id: I5925852fe6962d4ec7dbb3ea5323e8ddfaf9d576
Reviewed-on: https://go-review.googlesource.com/15755
Reviewed-by: Andrew Gerrand <adg@golang.org>
Run-TryBot: Andrew Gerrand <adg@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/go/alldocs.go
src/cmd/go/build.go
src/cmd/go/go_test.go
src/cmd/go/help.go

index d11a5a00f7921e3c02c5085fa6ead4511ca45df6..228ad19de4093d83945ae143dec3cd20040575cf 100644 (file)
@@ -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:
 
index 0166e9126ba19cf93815d3994e92cb7852cc6ce4..677e34c2b10b4563508705a804684ea33c350bf8 100644 (file)
@@ -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))
index ab78fe9a88452fe275ab29b6f8474ff0f6d2dcab..a4c91c960af2a4476fa2f77c72adc0997695e48a 100644 (file)
@@ -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) {
index 034dfc3cacaa8ce2770670b23af5a67378ae5f58..244451d3ebc51c0db3e242f5cc8e4df2b8c7707f 100644 (file)
@@ -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: