Skip to content

Commit beb5dad

Browse files
authored
Merge pull request #80 from eleuzi01/issue-74
Move scripts used by all-core.sh to the framework
2 parents 150bf84 + b5100e3 commit beb5dad

File tree

5 files changed

+303
-3
lines changed

5 files changed

+303
-3
lines changed

scripts/all-core.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ setup_quiet_wrappers()
266266
# unless there is an error. This reduces logging overhead in the CI.
267267
#
268268
# Note that the cmake wrapper breaks unless we use an absolute path here.
269-
if [[ -e ${PWD}/tests/scripts/quiet ]]; then
270-
export PATH=${PWD}/tests/scripts/quiet:$PATH
269+
if [[ -e ${PWD}/framework/scripts/quiet ]]; then
270+
export PATH=${PWD}/framework/scripts/quiet:$PATH
271271
fi
272272
}
273273
@@ -861,7 +861,7 @@ pre_check_tools () {
861861
*) set "$@" RUN_ARMCC=0;;
862862
esac
863863
# Use a path relative to the currently-sourced file.
864-
"$@" "${BASH_SOURCE%/*}"/../../scripts/output_env.sh
864+
"$@" "${BASH_SOURCE%/*}"/output_env.sh
865865
}
866866
867867
pre_generate_files() {

scripts/output_env.sh

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
#! /usr/bin/env sh
2+
3+
# output_env.sh
4+
#
5+
# Copyright The Mbed TLS Contributors
6+
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
7+
#
8+
# Purpose
9+
#
10+
# To print out all the relevant information about the development environment.
11+
#
12+
# This includes:
13+
# - architecture of the system
14+
# - type and version of the operating system
15+
# - version of make and cmake
16+
# - version of armcc, clang, gcc-arm and gcc compilers
17+
# - version of libc, clang, asan and valgrind if installed
18+
# - version of gnuTLS and OpenSSL
19+
20+
print_version()
21+
{
22+
BIN="$1"
23+
shift
24+
ARGS="$1"
25+
shift
26+
VARIANT="$1"
27+
shift
28+
29+
if [ -n "$VARIANT" ]; then
30+
VARIANT=" ($VARIANT)"
31+
fi
32+
33+
if ! type "$BIN" > /dev/null 2>&1; then
34+
echo " * ${BIN##*/}$VARIANT: Not found."
35+
return 0
36+
fi
37+
38+
BIN=`which "$BIN"`
39+
VERSION_STR=`$BIN $ARGS 2>&1`
40+
41+
# Apply all filters
42+
while [ $# -gt 0 ]; do
43+
FILTER="$1"
44+
shift
45+
VERSION_STR=`echo "$VERSION_STR" | $FILTER`
46+
done
47+
48+
if [ -z "$VERSION_STR" ]; then
49+
VERSION_STR="Version could not be determined."
50+
fi
51+
52+
echo " * ${BIN##*/}$VARIANT: ${BIN} : ${VERSION_STR} "
53+
}
54+
55+
echo "** Platform:"
56+
echo
57+
58+
if [ `uname -s` = "Linux" ]; then
59+
echo "Linux variant"
60+
lsb_release -d -c
61+
else
62+
echo "Unknown Unix variant"
63+
fi
64+
65+
echo
66+
67+
print_version "uname" "-a" ""
68+
69+
echo
70+
echo
71+
echo "** Tool Versions:"
72+
echo
73+
74+
print_version "make" "--version" "" "head -n 1"
75+
echo
76+
77+
print_version "cmake" "--version" "" "head -n 1"
78+
echo
79+
80+
if [ "${RUN_ARMCC:-1}" -ne 0 ]; then
81+
: "${ARMC6_CC:=armclang}"
82+
print_version "$ARMC6_CC" "--vsn" "" "head -n 2"
83+
echo
84+
fi
85+
86+
print_version "arm-none-eabi-gcc" "--version" "" "head -n 1"
87+
echo
88+
89+
print_version "gcc" "--version" "" "head -n 1"
90+
echo
91+
92+
if [ -n "${GCC_EARLIEST+set}" ]; then
93+
print_version "${GCC_EARLIEST}" "--version" "" "head -n 1"
94+
else
95+
echo " GCC_EARLIEST : Not configured."
96+
fi
97+
echo
98+
99+
if [ -n "${GCC_LATEST+set}" ]; then
100+
print_version "${GCC_LATEST}" "--version" "" "head -n 1"
101+
else
102+
echo " GCC_LATEST : Not configured."
103+
fi
104+
echo
105+
106+
print_version "clang" "--version" "" "head -n 2"
107+
echo
108+
109+
if [ -n "${CLANG_EARLIEST+set}" ]; then
110+
print_version "${CLANG_EARLIEST}" "--version" "" "head -n 2"
111+
else
112+
echo " CLANG_EARLIEST : Not configured."
113+
fi
114+
echo
115+
116+
if [ -n "${CLANG_LATEST+set}" ]; then
117+
print_version "${CLANG_LATEST}" "--version" "" "head -n 2"
118+
else
119+
echo " CLANG_LATEST : Not configured."
120+
fi
121+
echo
122+
123+
print_version "ldd" "--version" "" "head -n 1"
124+
echo
125+
126+
print_version "valgrind" "--version" ""
127+
echo
128+
129+
print_version "gdb" "--version" "" "head -n 1"
130+
echo
131+
132+
print_version "perl" "--version" "" "head -n 2" "grep ."
133+
echo
134+
135+
print_version "python" "--version" "" "head -n 1"
136+
echo
137+
138+
print_version "python3" "--version" "" "head -n 1"
139+
echo
140+
141+
# Find the installed version of Pylint. Installed as a distro package this can
142+
# be pylint3 and as a PEP egg, pylint. In test scripts We prefer pylint over
143+
# pylint3
144+
if type pylint >/dev/null 2>/dev/null; then
145+
print_version "pylint" "--version" "" "sed /^.*config/d" "grep pylint"
146+
elif type pylint3 >/dev/null 2>/dev/null; then
147+
print_version "pylint3" "--version" "" "sed /^.*config/d" "grep pylint"
148+
else
149+
echo " * pylint or pylint3: Not found."
150+
fi
151+
echo
152+
153+
: ${OPENSSL:=openssl}
154+
print_version "$OPENSSL" "version" "default"
155+
echo
156+
157+
if [ -n "${OPENSSL_NEXT+set}" ]; then
158+
print_version "$OPENSSL_NEXT" "version" "next"
159+
else
160+
echo " * openssl (next): Not configured."
161+
fi
162+
echo
163+
164+
: ${GNUTLS_CLI:=gnutls-cli}
165+
print_version "$GNUTLS_CLI" "--version" "default" "head -n 1"
166+
echo
167+
168+
: ${GNUTLS_SERV:=gnutls-serv}
169+
print_version "$GNUTLS_SERV" "--version" "default" "head -n 1"
170+
echo
171+
172+
echo " * Installed asan versions:"
173+
if type dpkg-query >/dev/null 2>/dev/null; then
174+
if ! dpkg-query -f '${Status} ${Package}: ${Version}\n' -W 'libasan*' |
175+
awk '$3 == "installed" && $4 !~ /-/ {print $4, $5}' |
176+
grep .
177+
then
178+
echo " No asan versions installed."
179+
fi
180+
else
181+
echo " Unable to determine the asan version without dpkg."
182+
fi
183+
echo

scripts/quiet/cmake

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#! /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+
12+
# export VERBOSE_LOGS=1
13+
14+
# don't silence invocations containing these arguments
15+
NO_SILENCE=" --version "
16+
17+
TOOL="cmake"
18+
19+
. "$(dirname "$0")/quiet.sh"

scripts/quiet/make

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#! /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+
12+
# export VERBOSE_LOGS=1
13+
14+
# don't silence invocations containing these arguments
15+
NO_SILENCE=" --version | test "
16+
17+
TOOL="make"
18+
19+
. "$(dirname "$0")/quiet.sh"

scripts/quiet/quiet.sh

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# -*-mode: sh; sh-shell: 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+
#
12+
# VERBOSE_LOGS=1
13+
#
14+
# This script provides most of the functionality for the adjacent make and cmake
15+
# wrappers.
16+
#
17+
# It requires two variables to be set:
18+
#
19+
# TOOL - the name of the tool that is being wrapped (with no path), e.g. "make"
20+
#
21+
# NO_SILENCE - a regex that describes the commandline arguments for which output will not
22+
# be silenced, e.g. " --version | test ". In this example, "make lib test" will
23+
# not be silent, but "make lib" will be.
24+
25+
# Identify path to original tool. There is an edge-case here where the quiet wrapper is on the path via
26+
# a symlink or relative path, but "type -ap" yields the wrapper with it's normalised path. We use
27+
# the -ef operator to compare paths, to avoid picking the wrapper in this case (to avoid infinitely
28+
# recursing).
29+
while IFS= read -r ORIGINAL_TOOL; do
30+
if ! [[ $ORIGINAL_TOOL -ef "$0" ]]; then break; fi
31+
done < <(type -ap -- "$TOOL")
32+
33+
print_quoted_args() {
34+
# similar to printf '%q' "$@"
35+
# but produce more human-readable results for common/simple cases like "a b"
36+
for a in "$@"; do
37+
# Get bash to quote the string
38+
printf -v q '%q' "$a"
39+
simple_pattern="^([-[:alnum:]_+./:@]+=)?([^']*)$"
40+
if [[ "$a" != "$q" && $a =~ $simple_pattern ]]; then
41+
# a requires some quoting (a != q), but has no single quotes, so we can
42+
# simplify the quoted form - e.g.:
43+
# a b -> 'a b'
44+
# CFLAGS=a b -> CFLAGS='a b'
45+
q="${BASH_REMATCH[1]}'${BASH_REMATCH[2]}'"
46+
fi
47+
printf " %s" "$q"
48+
done
49+
}
50+
51+
if [[ ! " $* " =~ " --version " ]]; then
52+
# Display the command being invoked - if it succeeds, this is all that will
53+
# be displayed. Don't do this for invocations with --version, because
54+
# this output is often parsed by scripts, so we don't want to modify it.
55+
printf %s "${TOOL}" 1>&2
56+
print_quoted_args "$@" 1>&2
57+
echo 1>&2
58+
fi
59+
60+
if [[ " $@ " =~ $NO_SILENCE || -n "${VERBOSE_LOGS}" ]]; then
61+
# Run original command with no output supression
62+
exec "${ORIGINAL_TOOL}" "$@"
63+
else
64+
# Run original command and capture output & exit status
65+
TMPFILE=$(mktemp "quiet-${TOOL}.XXXXXX")
66+
"${ORIGINAL_TOOL}" "$@" > "${TMPFILE}" 2>&1
67+
EXIT_STATUS=$?
68+
69+
if [[ $EXIT_STATUS -ne 0 ]]; then
70+
# On error, display the full output
71+
cat "${TMPFILE}"
72+
fi
73+
74+
# Remove tmpfile
75+
rm "${TMPFILE}"
76+
77+
# Propagate the exit status
78+
exit $EXIT_STATUS
79+
fi

0 commit comments

Comments
 (0)