Skip to content

Commit cd5258a

Browse files
ojedafbq
authored andcommitted
kbuild: rust_is_available: check that output looks as expected
The script already checks for `$RUSTC` and `$BINDGEN` existing and exiting without failure. However, one may still pass an unexpected binary that does not output what the later parsing expects. The script still successfully reports a failure as expected, but the error is confusing. For instance: $ RUSTC=true BINDGEN=bindgen CC=clang scripts/rust_is_available.sh scripts/rust_is_available.sh: 19: arithmetic expression: expecting primary: "100000 * + 100 * + " *** *** Please see Documentation/rust/quick-start.rst for details *** on how to set up the Rust support. *** Thus add an explicit check and a proper message for unexpected output from the called command. Similarly, do so for the `libclang` version parsing, too. 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 72691f7 commit cd5258a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

scripts/rust_is_available.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ rust_compiler_version=$( \
9797
echo "$rust_compiler_output" \
9898
| sed -nE '1s:.*rustc ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p'
9999
)
100+
if [ -z "$rust_compiler_version" ]; then
101+
echo >&2 "***"
102+
echo >&2 "*** Running '$RUSTC' to check the Rust compiler version did not return"
103+
echo >&2 "*** an expected output. See output and docs below for details:"
104+
echo >&2 "***"
105+
echo >&2 "$rust_compiler_output"
106+
echo >&2 "***"
107+
exit 1
108+
fi
100109
rust_compiler_min_version=$($min_tool_version rustc)
101110
rust_compiler_cversion=$(get_canonical_version $rust_compiler_version)
102111
rust_compiler_min_cversion=$(get_canonical_version $rust_compiler_min_version)
@@ -136,6 +145,15 @@ rust_bindings_generator_version=$( \
136145
echo "$rust_bindings_generator_output" \
137146
| sed -nE '1s:.*bindgen ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p'
138147
)
148+
if [ -z "$rust_bindings_generator_version" ]; then
149+
echo >&2 "***"
150+
echo >&2 "*** Running '$BINDGEN' to check the bindings generator version did not return"
151+
echo >&2 "*** an expected output. See output and docs below for details:"
152+
echo >&2 "***"
153+
echo >&2 "$rust_bindings_generator_output"
154+
echo >&2 "***"
155+
exit 1
156+
fi
139157
rust_bindings_generator_min_version=$($min_tool_version bindgen)
140158
rust_bindings_generator_cversion=$(get_canonical_version $rust_bindings_generator_version)
141159
rust_bindings_generator_min_cversion=$(get_canonical_version $rust_bindings_generator_min_version)
@@ -184,6 +202,16 @@ bindgen_libclang_version=$( \
184202
echo "$bindgen_libclang_output" \
185203
| sed -nE 's:.*clang version ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p'
186204
)
205+
if [ -z "$bindgen_libclang_version" ]; then
206+
echo >&2 "***"
207+
echo >&2 "*** Running '$BINDGEN' to check the libclang version (used by the Rust"
208+
echo >&2 "*** bindings generator) did not return an expected output. See output"
209+
echo >&2 "*** and docs below for details:"
210+
echo >&2 "***"
211+
echo >&2 "$bindgen_libclang_output"
212+
echo >&2 "***"
213+
exit 1
214+
fi
187215
bindgen_libclang_min_version=$($min_tool_version llvm)
188216
bindgen_libclang_cversion=$(get_canonical_version $bindgen_libclang_version)
189217
bindgen_libclang_min_cversion=$(get_canonical_version $bindgen_libclang_min_version)

0 commit comments

Comments
 (0)