Skip to content

Commit 72691f7

Browse files
ojedafbq
authored andcommitted
kbuild: rust_is_available: handle failures calling $RUSTC/$BINDGEN
The script already checks if `$RUSTC` and `$BINDGEN` exists via `command`, but the environment variables may point to a non-executable file, or the programs may fail for some other reason. While the script successfully exits with a failure as it should, the error given can be quite confusing depending on the shell and the behavior of its `command`. For instance, with `dash`: $ RUSTC=./mm BINDGEN=bindgen CC=clang scripts/rust_is_available.sh scripts/rust_is_available.sh: 19: arithmetic expression: expecting primary: "100000 * + 100 * + " Thus detect failure exit codes when calling `$RUSTC` and `$BINDGEN` and print a better message, in a similar way to what we do when extracting the `libclang` version found by `bindgen`. Link: https://lore.kernel.org/rust-for-linux/CAK7LNAQYk6s11MASRHW6oxtkqF00EJVqhHOP=5rynWt-QDUsXw@mail.gmail.com/ Signed-off-by: Miguel Ojeda <[email protected]> Reviewed-by: Nathan Chancellor <[email protected]> Reviewed-by: Martin Rodriguez Reboredo <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 2f0691e commit 72691f7

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

scripts/rust_is_available.sh

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,20 @@ fi
8181
# Check that the Rust compiler version is suitable.
8282
#
8383
# Non-stable and distributions' versions may have a version suffix, e.g. `-dev`.
84+
rust_compiler_output=$( \
85+
LC_ALL=C "$RUSTC" --version 2>/dev/null
86+
) || rust_compiler_code=$?
87+
if [ -n "$rust_compiler_code" ]; then
88+
echo >&2 "***"
89+
echo >&2 "*** Running '$RUSTC' to check the Rust compiler version failed with"
90+
echo >&2 "*** code $rust_compiler_code. See output and docs below for details:"
91+
echo >&2 "***"
92+
echo >&2 "$rust_compiler_output"
93+
echo >&2 "***"
94+
exit 1
95+
fi
8496
rust_compiler_version=$( \
85-
LC_ALL=C "$RUSTC" --version 2>/dev/null \
97+
echo "$rust_compiler_output" \
8698
| sed -nE '1s:.*rustc ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p'
8799
)
88100
rust_compiler_min_version=$($min_tool_version rustc)
@@ -108,8 +120,20 @@ fi
108120
# Check that the Rust bindings generator is suitable.
109121
#
110122
# Non-stable and distributions' versions may have a version suffix, e.g. `-dev`.
123+
rust_bindings_generator_output=$( \
124+
LC_ALL=C "$BINDGEN" --version 2>/dev/null
125+
) || rust_bindings_generator_code=$?
126+
if [ -n "$rust_bindings_generator_code" ]; then
127+
echo >&2 "***"
128+
echo >&2 "*** Running '$BINDGEN' to check the Rust bindings generator version failed with"
129+
echo >&2 "*** code $rust_bindings_generator_code. See output and docs below for details:"
130+
echo >&2 "***"
131+
echo >&2 "$rust_bindings_generator_output"
132+
echo >&2 "***"
133+
exit 1
134+
fi
111135
rust_bindings_generator_version=$( \
112-
LC_ALL=C "$BINDGEN" --version 2>/dev/null \
136+
echo "$rust_bindings_generator_output" \
113137
| sed -nE '1s:.*bindgen ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p'
114138
)
115139
rust_bindings_generator_min_version=$($min_tool_version bindgen)

0 commit comments

Comments
 (0)