summaryrefslogtreecommitdiff
path: root/src/cmd/go
diff options
context:
space:
mode:
authorDmitri Shuralyov <shurcooL@gmail.com>2014-07-09 13:17:27 +1000
committerDmitri Shuralyov <shurcooL@gmail.com>2014-07-09 13:17:27 +1000
commit89277bceb80f6537ee4dd6c5d22011dc86bed13e (patch)
tree61894b832df00f84034bed844fa04f368e352ba2 /src/cmd/go
parentafa6b1515b90cdabaf9560b020f3084ce5d5152f (diff)
downloadgo-89277bceb80f6537ee4dd6c5d22011dc86bed13e.tar.gz
cmd/go: fix build -o panic when import path pattern matches 0 pkgs
Fixes issue 8165. After this change, the panic is replaced by a message: $ go build -o out ...doesntexist warning: "...doesntexist" matched no packages no packages to build The motivation to return 1 exit error code is to allow -o flag to be used to guarantee that the output binary is written to when exit status is 0. If someone uses an import path pattern to specify a single package and suddenly that matches no packages, it's better to return exit code 1 instead of silently doing nothing. This is consistent with the case when -o flag is given and multiple packages are matched. It's also somewhat consistent with the current behavior with the panic, except that gave return code 2. But it's similar in that it's also non-zero (indicating failure). I've changed the language to be similar to output of go test when an import path pattern matches no packages (it also has a return status of 1): $ go test ...doesntexist warning: "...doesntexist" matched no packages no packages to test LGTM=adg R=golang-codereviews, josharian, gobot, adg CC=golang-codereviews https://codereview.appspot.com/107140043 Committer: Andrew Gerrand <adg@golang.org>
Diffstat (limited to 'src/cmd/go')
-rw-r--r--src/cmd/go/build.go2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go
index 152806f87..7a09471fa 100644
--- a/src/cmd/go/build.go
+++ b/src/cmd/go/build.go
@@ -287,6 +287,8 @@ func runBuild(cmd *Command, args []string) {
if *buildO != "" {
if len(pkgs) > 1 {
fatalf("go build: cannot use -o with multiple packages")
+ } else if len(pkgs) == 0 {
+ fatalf("no packages to build")
}
p := pkgs[0]
p.target = "" // must build - not up to date