Commit 159c2b7e authored by Russ Cox's avatar Russ Cox

cmd/go: fix error for 'go install x.go' when GOBIN is not set

Fixes #6191.
Fixes #5426.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/13234052
parent a547ad6a
......@@ -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"
......
......@@ -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
......
......@@ -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)'
......
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