aboutsummaryrefslogtreecommitdiff
path: root/toolchain_utils_githooks
diff options
context:
space:
mode:
authorGeorge Burgess IV <gbiv@google.com>2019-03-08 20:32:09 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-03-13 21:05:17 -0700
commitca7fa0584faba419510cc03c98aa598254b3fe73 (patch)
tree4a720227ba1bddccf995111cc98b67821302abc7 /toolchain_utils_githooks
parentb75a3e7bb0f91b246894af7cbb26cc8fef574800 (diff)
downloadtoolchain-utils-ca7fa0584faba419510cc03c98aa598254b3fe73.tar.gz
[githooks] Refactor/rename check-style; NFC
It sounds like we want to start using check-style as part of a test runner. Refactoring check-style a bit allows us to trivially do that cleanly in parallel with code style/lint checks. No functional change is intended. BUG=None TEST=repo upload Change-Id: I1fea43922dd37e571b7d2695656f480d5b458460 Reviewed-on: https://chromium-review.googlesource.com/1516417 Commit-Ready: George Burgess <gbiv@chromium.org> Tested-by: George Burgess <gbiv@chromium.org> Reviewed-by: Luis Lozano <llozano@chromium.org>
Diffstat (limited to 'toolchain_utils_githooks')
-rwxr-xr-xtoolchain_utils_githooks/check-style49
1 files changed, 25 insertions, 24 deletions
diff --git a/toolchain_utils_githooks/check-style b/toolchain_utils_githooks/check-style
index 0ce11877..fa06fa3e 100755
--- a/toolchain_utils_githooks/check-style
+++ b/toolchain_utils_githooks/check-style
@@ -3,8 +3,8 @@
# 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.
+# Convenient wrapper to run presubmit checks in parallel without interleaving
+# output/etc.
if [[ $# -eq 0 ]]; then
echo "No files were given to check the style of. Exiting." >&2
@@ -13,31 +13,32 @@ fi
mydir="$(dirname "$(readlink -m "$0")")"
-tempfile="$(mktemp)"
-rm_tempfile() {
- rm -f "${tempfile}"
+tempfiles=()
+rm_tempfiles() {
+ rm -f "${tempfiles[@]}"
}
-trap rm_tempfile EXIT
+trap rm_tempfiles EXIT
-success=true
+child_pids=()
+spawn_child() {
+ local tempfile
+ tempfile="$(mktemp)"
+ tempfiles+=( "${tempfile}" )
+ "$@" >"${tempfile}" 2>&1 &
+ child_pids+=( "$!" )
+}
-# 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 [[ -n "${lint_output}" ]]; then
- echo "${lint_output}"
-fi
+# We have a few things to do in parallel here. To avoid interleaving their
+# output, we pipe them all to tempfiles, then cat those tempfiles.
+
+spawn_child "${mydir}/check-lint" "$@"
+spawn_child "${mydir}/check-format" "$@"
+
+success=true
+for i in "${!child_pids[@]}"; do
+ wait "${child_pids[$i]}" || success=false
+ cat "${tempfiles[$i]}"
+done
"${success}"