aboutsummaryrefslogtreecommitdiff
path: root/toolchain_utils_githooks/check-style
blob: dbc38a71f1a403f219d88f405f4b2273aa604ee9 (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
#!/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