diff options
Diffstat (limited to 'toolchain_utils_githooks/check-presubmit')
-rwxr-xr-x | toolchain_utils_githooks/check-presubmit | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/toolchain_utils_githooks/check-presubmit b/toolchain_utils_githooks/check-presubmit new file mode 100755 index 00000000..e67611f5 --- /dev/null +++ b/toolchain_utils_githooks/check-presubmit @@ -0,0 +1,52 @@ +#!/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 presubmit checks in parallel without interleaving +# output/etc. + +if [[ $# -eq 0 ]]; then + echo "No files were given to check the style of. Exiting." >&2 + exit +fi + +mydir="$(dirname "$(readlink -m "$0")")" +pydir="${mydir}/.." + +if [[ -z "${PYTHONPATH:-}" ]]; then + export PYTHONPATH="${pydir}" +else + export PYTHONPATH="${pydir}:${PYTHONPATH}" +fi + +tempfiles=() +rm_tempfiles() { + rm -f "${tempfiles[@]}" +} + +trap rm_tempfiles EXIT + +child_pids=() +spawn_child() { + local tempfile + tempfile="$(mktemp)" + tempfiles+=( "${tempfile}" ) + "$@" >"${tempfile}" 2>&1 & + child_pids+=( "$!" ) +} + +# 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" "$@" +spawn_child "${mydir}/../run_tests_for.py" "$@" + +success=true +for i in "${!child_pids[@]}"; do + wait "${child_pids[$i]}" || success=false + cat "${tempfiles[$i]}" +done + +"${success}" |