kbuild: rust_is_available: handle failures calling `$RUSTC`/`$BINDGEN`
authorMiguel Ojeda <ojeda@kernel.org>
Fri, 16 Jun 2023 00:16:29 +0000 (02:16 +0200)
committerMiguel Ojeda <ojeda@kernel.org>
Wed, 9 Aug 2023 23:18:34 +0000 (01:18 +0200)
commitf295522886a4ebb628cadb2cd74d0661d6292978
tree87490c3cb9df92237c60b2fce7a634d7ce4bff13
parent7cd6a3e1f94bab4f2a3425e06f70ab13eb8190d4
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/
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
Link: https://lore.kernel.org/r/20230616001631.463536-10-ojeda@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
scripts/rust_is_available.sh