Makefile: Use 'git diff' to show gofmt changes
This makes fixing errors easier. Before this commit, errors looked like [1]: $ make gofmt !!! 'gofmt -s' needs to be run on the following files: ./lib/config.go make: *** [gofmt] Error 1 But that's not very helpful when your local gofmt thinks the file is fine. With this commit, errors will look like: $ make gofmt find . -name '*.go' ! -path './vendor/*' -exec gofmt -s -w {} \+ git diff --exit-code diff --git a/lib/config.go b/lib/config.go index 1acca8c7..6a63b2b0 100644 --- a/lib/config.go +++ b/lib/config.go @@ -2,7 +2,7 @@ package lib import ( "bytes" -"io/ioutil" + "io/ioutil" "github.com/BurntSushi/toml" "github.com/kubernetes-incubator/cri-o/oci" make: *** [Makefile:68: gofmt] Error 1 (or whatever, I just stuffed in a formatting error for demonstration purposes). Also remove the helper script in favor of direct Makefile calls, because with Git handling difference reporting and exit status, this becomes a simpler check. find's -exec, !, and -path arguments are specified in POSIX [2]. [1]: https://travis-ci.org/kubernetes-incubator/cri-o/jobs/331949394#L1075 [2]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html Signed-off-by: W. Trevor King <wking@tremily.us>
This commit is contained in:
parent
ddb14b7303
commit
8dbc2d1fff
2 changed files with 2 additions and 22 deletions
3
Makefile
3
Makefile
|
@ -64,7 +64,8 @@ lint: .gopathok
|
||||||
@./.tool/lint
|
@./.tool/lint
|
||||||
|
|
||||||
gofmt:
|
gofmt:
|
||||||
@./hack/verify-gofmt.sh
|
find . -name '*.go' ! -path './vendor/*' -exec gofmt -s -w {} \+
|
||||||
|
git diff --exit-code
|
||||||
|
|
||||||
conmon:
|
conmon:
|
||||||
$(MAKE) -C $@
|
$(MAKE) -C $@
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -o errexit
|
|
||||||
set -o nounset
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
find_files() {
|
|
||||||
find . -not \( \
|
|
||||||
\( \
|
|
||||||
-wholename '*/vendor/*' \
|
|
||||||
\) -prune \
|
|
||||||
\) -name '*.go'
|
|
||||||
}
|
|
||||||
|
|
||||||
GOFMT="gofmt -s"
|
|
||||||
bad_files=$(find_files | xargs $GOFMT -l)
|
|
||||||
if [[ -n "${bad_files}" ]]; then
|
|
||||||
echo "!!! '$GOFMT' needs to be run on the following files: "
|
|
||||||
echo "${bad_files}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
Loading…
Reference in a new issue