Make make fail better with bad inputs
				
					
				
			Ultimately, we're hitting places where bash is just hard to get right.
Instead of:
```
$ make WHAT=nonexist
stat /home/thockin/src/kubernetes/nonexist: directory not found
!!! [0228 12:07:12] Call tree:
!!! [0228 12:07:12]  1: /home/thockin/src/kubernetes/hack/lib/golang.sh:930 kube::golang::normalize_go_targets(...)
!!! [0228 12:07:12]  2: hack/make-rules/build.sh:27 kube::golang::build_binaries(...)
+++ [0228 12:07:12] Building go targets for linux/amd64
     (non-static)
no Go files in /home/thockin/src/kubernetes
!!! [0228 12:07:12] Call tree:
!!! [0228 12:07:12]  1: /home/thockin/src/kubernetes/hack/lib/golang.sh:820 kube::golang::build_some_binaries(...)
!!! [0228 12:07:12]  2: /home/thockin/src/kubernetes/hack/lib/golang.sh:974 kube::golang::build_binaries_for_platform(...)
!!! [0228 12:07:12]  3: hack/make-rules/build.sh:27 kube::golang::build_binaries(...)
!!! [0228 12:07:12] Call tree:
!!! [0228 12:07:12]  1: hack/make-rules/build.sh:27 kube::golang::build_binaries(...)
!!! [0228 12:07:12] Call tree:
!!! [0228 12:07:12]  1: hack/make-rules/build.sh:27 kube::golang::build_binaries(...)
make: *** [Makefile:95: all] Error 1
```
We now get:
```
$ make WHAT=nonexist
+++ [0228 12:33:49] Building go targets for linux/amd64
    ./nonexist (non-static)
stat /home/thockin/src/kubernetes/nonexist: directory not found
!!! [0228 12:33:49] Call tree:
!!! [0228 12:33:49]  1: /home/thockin/src/kubernetes/hack/lib/golang.sh:823 kube::golang::build_some_binaries(...)
!!! [0228 12:33:49]  2: /home/thockin/src/kubernetes/hack/lib/golang.sh:976 kube::golang::build_binaries_for_platform(...)
!!! [0228 12:33:49]  3: hack/make-rules/build.sh:27 kube::golang::build_binaries(...)
!!! [0228 12:33:49] Call tree:
!!! [0228 12:33:49]  1: hack/make-rules/build.sh:27 kube::golang::build_binaries(...)
!!! [0228 12:33:49] Call tree:
!!! [0228 12:33:49]  1: hack/make-rules/build.sh:27 kube::golang::build_binaries(...)
make: *** [Makefile:95: all] Error 1
$ make test WHAT=nonexist
+++ [0228 12:33:53] Set GOMAXPROCS automatically to 6
+++ [0228 12:33:53] Running tests without code coverage and with -race
stat /home/thockin/src/kubernetes/nonexist: directory not found
make: *** [Makefile:190: test] Error 1
```
			
			
This commit is contained in:
		| @@ -417,6 +417,9 @@ kube::golang::best_guess_go_targets() { | |||||||
| # be Go-style names (e.g. example.com/foo/bar or ./foo/bar) or just local paths | # be Go-style names (e.g. example.com/foo/bar or ./foo/bar) or just local paths | ||||||
| # (e.g. foo/bar) and produces a respective list (on stdout) of Go package | # (e.g. foo/bar) and produces a respective list (on stdout) of Go package | ||||||
| # names. | # names. | ||||||
|  | # | ||||||
|  | # If this cannot find (go list -find -e) one or more inputs, it will emit the | ||||||
|  | # them on stdout, so callers can at least get a useful error. | ||||||
| kube::golang::normalize_go_targets() { | kube::golang::normalize_go_targets() { | ||||||
|   local targets=() |   local targets=() | ||||||
|   kube::util::read-array targets < <(kube::golang::best_guess_go_targets "$@") |   kube::util::read-array targets < <(kube::golang::best_guess_go_targets "$@") | ||||||
| @@ -430,7 +433,7 @@ kube::golang::normalize_go_targets() { | |||||||
|       local tst |       local tst | ||||||
|       tst="$(basename "${target}")" |       tst="$(basename "${target}")" | ||||||
|       local pkg |       local pkg | ||||||
|       pkg="$(go list -find "${dir}")" |       pkg="$(go list -find -e "${dir}")" | ||||||
|       echo "${pkg}/${tst}" |       echo "${pkg}/${tst}" | ||||||
|       continue |       continue | ||||||
|     fi |     fi | ||||||
| @@ -438,11 +441,11 @@ kube::golang::normalize_go_targets() { | |||||||
|       local dir |       local dir | ||||||
|       dir="$(dirname "${target}")" |       dir="$(dirname "${target}")" | ||||||
|       local pkg |       local pkg | ||||||
|       pkg="$(go list -find "${dir}")" |       pkg="$(go list -find -e "${dir}")" | ||||||
|       echo "${pkg}/..." |       echo "${pkg}/..." | ||||||
|       continue |       continue | ||||||
|     fi |     fi | ||||||
|     go list -find "${target}" |     go list -find -e "${target}" | ||||||
|   done |   done | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Tim Hockin
					Tim Hockin