• Dmitri Shuralyov's avatar
    cmd/go: fix build -o panic when import path pattern matches 0 pkgs · 3e801416
    Dmitri Shuralyov authored
    Fixes #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://golang.org/cl/107140043
    3e801416
Name
Last commit
Last update
..
testdata Loading commit data...
bootstrap.go Loading commit data...
build.go Loading commit data...
clean.go Loading commit data...
context.go Loading commit data...
discovery.go Loading commit data...
doc.go Loading commit data...
env.go Loading commit data...
fix.go Loading commit data...
fmt.go Loading commit data...
get.go Loading commit data...
go11.go Loading commit data...
help.go Loading commit data...
http.go Loading commit data...
list.go Loading commit data...
main.go Loading commit data...
match_test.go Loading commit data...
mkdoc.sh Loading commit data...
pkg.go Loading commit data...
pkg_test.go Loading commit data...
run.go Loading commit data...
script Loading commit data...
script.txt Loading commit data...
signal.go Loading commit data...
signal_notunix.go Loading commit data...
signal_unix.go Loading commit data...
tag_test.go Loading commit data...
test.bash Loading commit data...
test.go Loading commit data...
testflag.go Loading commit data...
tool.go Loading commit data...
vcs.go Loading commit data...
version.go Loading commit data...
vet.go Loading commit data...