blob: ea1474f877f43998d16b26e63b1a361101784fc3 [file] [log] [blame]
Dave Rodgman3e2c61d2024-01-04 16:20:20 +00001#! /usr/bin/env bash
2#
3# Copyright The Mbed TLS Contributors
4# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
5#
6# This swallows the output of the wrapped tool, unless there is an error.
7# This helps reduce excess logging in the CI.
8
9# If you are debugging a build / CI issue, you can get complete unsilenced logs
10# by un-commenting the following line (or setting VERBOSE_LOGS in your environment):
11# VERBOSE_LOGS=1
12
13# don't silence invocations containing these arguments
14NO_SILENCE=" --version "
15
16TOOL=$(basename "$0")
17
18# Locate original tool
19ORIGINAL_TOOL=$(type -ap ${TOOL} | grep -v "$0" | head -n1 )
20
21if [[ " $@ " =~ $NO_SILENCE || -n "${VERBOSE_LOGS}" ]]; then
22 ${ORIGINAL_TOOL} "$@"
23 EXIT_STATUS=$?
24else
25 # Display the command being invoked - if it succeeds, this is all that will
26 # be displayed.
27 echo "${TOOL} $@"
28
29 # Run original command and capture output & exit status
30 TMPFILE=$(mktemp /tmp/quiet-${TOOL}.XXXXXX)
31 ${ORIGINAL_TOOL} "$@" > ${TMPFILE} 2>&1
32 EXIT_STATUS=$?
33
34 if [[ $EXIT_STATUS -ne 0 ]]; then
35 # On error, display the full output
36 cat ${TMPFILE}
37 fi
38
39 # Remove tmpfile
40 rm ${TMPFILE}
41fi
42
43# Propagate the exit status
44exit $EXIT_STATUS