]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix error for 'go install x.go' when GOBIN is not set
authorRuss Cox <rsc@golang.org>
Tue, 10 Sep 2013 18:41:07 +0000 (14:41 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 10 Sep 2013 18:41:07 +0000 (14:41 -0400)
Fixes #6191.
Fixes #5426.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/13234052

src/cmd/go/build.go
src/cmd/go/pkg.go
src/cmd/go/test.bash

index 7308fb6f5566967a200e50d589bdf1d7694c2783..e8a9430c1a05d0af583041275b725115cd316d86 100644 (file)
@@ -311,7 +311,9 @@ func runInstall(cmd *Command, args []string) {
 
        for _, p := range pkgs {
                if p.Target == "" && (!p.Standard || p.ImportPath != "unsafe") {
-                       if p.ConflictDir != "" {
+                       if p.cmdline {
+                               errorf("go install: no install location for .go files listed on command line (GOBIN not set)")
+                       } else if p.ConflictDir != "" {
                                errorf("go install: no install location for %s: hidden by %s", p.Dir, p.ConflictDir)
                        } else {
                                errorf("go install: no install location for directory %s outside GOPATH", p.Dir)
@@ -486,6 +488,7 @@ func goFilesPackage(gofiles []string) *Package {
        bp, err := ctxt.ImportDir(dir, 0)
        pkg := new(Package)
        pkg.local = true
+       pkg.cmdline = true
        pkg.load(&stk, bp, err)
        pkg.localPrefix = dirToImportPath(dir)
        pkg.ImportPath = "command-line-arguments"
index 7f53c5c2637a880bee9031dd8210de1c0c799535..71f14c74a23b731b85be7a4aa406ac6bd5dab5e9 100644 (file)
@@ -82,6 +82,7 @@ type Package struct {
        fake         bool                 // synthesized package
        forceBuild   bool                 // this package must be rebuilt
        forceLibrary bool                 // this package is a library (even if named "main")
+       cmdline      bool                 // defined by files listed on command line
        local        bool                 // imported via local path (./ or ../)
        localPrefix  string               // interpret ./ and ../ imports relative to this prefix
        exeName      string               // desired name for temporary executable
index 62ab21913508ef459a44fbccaa36bdfdd9b1eda7..61e9e6ada0944cfc9cab8d51a5c96670235479ae 100755 (executable)
@@ -150,11 +150,16 @@ fi
 
 # Without $GOBIN set, installing a program outside $GOPATH should fail
 # (there is nowhere to install it).
-TEST install without destination
-if ./testgo install testdata/src/go-cmd-test/helloworld.go; then
+TEST install without destination fails
+if ./testgo install testdata/src/go-cmd-test/helloworld.go 2>testdata/err; then
        echo "go install testdata/src/go-cmd-test/helloworld.go should have failed, did not"
        ok=false
+elif ! grep 'no install location for .go files listed on command line' testdata/err; then
+       echo "wrong error:"
+       cat testdata/err
+       ok=false
 fi
+rm -f testdata/err
 
 # With $GOBIN set, should install there.
 TEST install to GOBIN '(command-line package)'