mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
ci/print_toolchain_versions: robust/portable version detection.
Detect command line tool versions without using "command". Command may be a builting in some shells, leading to unportability. The new version uses the status code to correctly detect a non-existent command. This allows it to differentiate between error in the tool and not-found errors. It also works with compound commands, for example `python -m callable_module".
This commit is contained in:
parent
6a4c764c95
commit
9926ac1ffa
24
dist/tools/ci/print_toolchain_versions.sh
vendored
24
dist/tools/ci/print_toolchain_versions.sh
vendored
@ -5,21 +5,17 @@ get_cmd_version() {
|
||||
return
|
||||
fi
|
||||
|
||||
local cmd="$1"
|
||||
if command -v "$cmd" 2>&1 >/dev/null; then
|
||||
ver=$("$cmd" --version 2> /dev/null | head -n 1)
|
||||
# some tools (eg. openocd) print version info to stderr
|
||||
if [ -z "$ver" ]; then
|
||||
ver=$("$cmd" --version 2>&1 | head -n 1)
|
||||
fi
|
||||
if [ -z "$ver" ]; then
|
||||
ver="error"
|
||||
fi
|
||||
else
|
||||
ver="missing"
|
||||
VERSION_RAW=$( ($@ --version) 2>&1)
|
||||
ERR=$?
|
||||
VERSION=$(echo "$VERSION_RAW" | head -n 1)
|
||||
|
||||
if [ $ERR -eq 127 ] ; then # 127 means command not found
|
||||
VERSION="missing"
|
||||
elif [ $ERR -ne 0 ] ; then
|
||||
VERSION="error: ${VERSION}"
|
||||
fi
|
||||
|
||||
printf "%s" "$ver"
|
||||
printf "%s" "$VERSION"
|
||||
}
|
||||
|
||||
get_define() {
|
||||
@ -123,7 +119,7 @@ for c in \
|
||||
python2 \
|
||||
python3 \
|
||||
; do
|
||||
printf "%23s: %s\n" "$c" "$(get_cmd_version $c)"
|
||||
printf "%23s: %s\n" "$c" "$(get_cmd_version "${c}")"
|
||||
done
|
||||
printf "%23s: %s\n" "coccinelle" "$(get_cmd_version spatch)"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user