aboutsummaryrefslogtreecommitdiff
path: root/toolchain_utils_githooks/check-presubmit
blob: e67611f5bbd22c94cab34e366b7757d92a0f9194 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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}"