diff options
author | George Burgess IV <gbiv@google.com> | 2019-01-03 11:37:06 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-01-05 22:44:00 -0800 |
commit | e136e0a53ae27ca7ff6ad31e6b4f86fde7238410 (patch) | |
tree | 0d9aa85ce058c0eb319aace087565c29d393adb0 /toolchain_utils_githooks | |
parent | ee75294e8c6f7333640c691ae58c007032ff22fe (diff) | |
download | toolchain-utils-e136e0a53ae27ca7ff6ad31e6b4f86fde7238410.tar.gz |
toolchain-utils: add a `cros lint` git hook
This adds a git hook to run `cros lint` on all of the files we're
committing. It also adds a wrapper around both check-lint and
check-format that runs the two in parallel without making the output
interleave. Better names for check-style are appreciated.
BUG=chromium:918755
TEST=Ran ./check-style on a few Python files. Got the expected
output/lint errors/etc. Works both outside and inside of the
chroot.
CQ-DEPEND=CL:1394285
Change-Id: I30c74662759f27abdfd663083d04002a05260bf7
Reviewed-on: https://chromium-review.googlesource.com/1395807
Commit-Ready: George Burgess <gbiv@chromium.org>
Tested-by: George Burgess <gbiv@chromium.org>
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Diffstat (limited to 'toolchain_utils_githooks')
-rwxr-xr-x | toolchain_utils_githooks/check-lint | 22 | ||||
-rwxr-xr-x | toolchain_utils_githooks/check-style | 44 | ||||
-rwxr-xr-x | toolchain_utils_githooks/pre-push.real | 2 |
3 files changed, 67 insertions, 1 deletions
diff --git a/toolchain_utils_githooks/check-lint b/toolchain_utils_githooks/check-lint new file mode 100755 index 00000000..5b9ade37 --- /dev/null +++ b/toolchain_utils_githooks/check-lint @@ -0,0 +1,22 @@ +#!/bin/bash -u +# Copyright 2019 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +# +# This script runs `cros lint` on everything it's handed. + +if test $# -eq 0; then + echo "No files were given to lint." >&2 + echo "Usage: $0 file1 file2 ..." >&2 + exit 1 +fi + +cros=cros + +if ! type "${cros}" >&/dev/null; then + echo "${cros} isn't on your \$PATH. Please either enter a chroot, or place" \ + "depot_tools on your \$PATH." >&2 + exit 1 +fi + +"${cros}" lint -- $@ diff --git a/toolchain_utils_githooks/check-style b/toolchain_utils_githooks/check-style new file mode 100755 index 00000000..dbc38a71 --- /dev/null +++ b/toolchain_utils_githooks/check-style @@ -0,0 +1,44 @@ +#!/bin/bash -eu +# Copyright 2019 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +# +# Convenient wrapper to run format and lint checks in parallel without +# interleaving output/etc. + +if test $# -eq 0; then + echo "No files were given to check the format of." >&2 + echo "Usage: $0 file1 file2 ..." >&2 + exit 1 +fi + +mydir="$(dirname "$(readlink -m "$0")")" + +tempfile="$(mktemp)" +rm_tempfile() { + rm -f "${tempfile}" +} + +trap rm_tempfile EXIT + +success=true + +# Since we only have two things to do in parallel, we just output the +# stdout/stderr of this to a temp file. When the other check is done, we `cat` +# the temp file, and we're good. +# +# It appears that check-lint will emit colorful output regardless of whether or +# not it's writing to a tty, so we don't lose the nice red "ERROR" text from +# it. +"${mydir}/check-lint" "$@" >"${tempfile}" 2>&1 & +pid="$!" + +"${mydir}/check-format" "$@" || success=false +wait "${pid}" || success=false + +lint_output="$(cat "${tempfile}")" +if ! test -z "${lint_output}"; then + echo "${lint_output}" +fi + +$success diff --git a/toolchain_utils_githooks/pre-push.real b/toolchain_utils_githooks/pre-push.real index 7b65b175..c05a35bf 100755 --- a/toolchain_utils_githooks/pre-push.real +++ b/toolchain_utils_githooks/pre-push.real @@ -46,7 +46,7 @@ while IFS=' ' read local_ref local_sha remote_ref remote_sha; do all_files="$(git show --pretty="format:" --name-only "${range}")" # Note that ${all_files} may include files that were deleted. Hence, we # ignore any complaints about missing files. - IGNORE_MISSING=1 "${mydir}/check-format" ${all_files} || exit 1 + IGNORE_MISSING=1 "${mydir}/check-style" ${all_files} || exit 1 fi done |