Skip to content

Commit 0441689

Browse files
ojedavtta
authored andcommitted
kbuild: rust_is_available: normalize version matching
In order to match the version string, `sed` is used in a couple cases, and `grep` and `head` in a couple others. Make the script more consistent and easier to understand by using the same method, `sed`, for all of them. This makes the version matching also a bit more strict for the changed cases, since the strings `rustc ` and `bindgen ` will now be required, which should be fine since `rustc` complains if one attempts to call it with another program name, and `bindgen` uses a hardcoded string. In addition, clarify why one of the existing `sed` commands does not provide an address like the others. Reviewed-by: Nathan Chancellor <nathan@kernel.org> Reviewed-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com> Link: https://lore.kernel.org/r/20230616001631.463536-9-ojeda@kernel.org Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent 727bd7d commit 0441689

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

scripts/rust_is_available.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ fi
8383
# Non-stable and distributions' versions may have a version suffix, e.g. `-dev`.
8484
rust_compiler_version=$( \
8585
LC_ALL=C "$RUSTC" --version 2>/dev/null \
86-
| head -n 1 \
87-
| grep -oE '[0-9]+\.[0-9]+\.[0-9]+' \
86+
| sed -nE '1s:.*rustc ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p'
8887
)
8988
rust_compiler_min_version=$($min_tool_version rustc)
9089
rust_compiler_cversion=$(get_canonical_version $rust_compiler_version)
@@ -111,8 +110,7 @@ fi
111110
# Non-stable and distributions' versions may have a version suffix, e.g. `-dev`.
112111
rust_bindings_generator_version=$( \
113112
LC_ALL=C "$BINDGEN" --version 2>/dev/null \
114-
| head -n 1 \
115-
| grep -oE '[0-9]+\.[0-9]+\.[0-9]+' \
113+
| sed -nE '1s:.*bindgen ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p'
116114
)
117115
rust_bindings_generator_min_version=$($min_tool_version bindgen)
118116
rust_bindings_generator_cversion=$(get_canonical_version $rust_bindings_generator_version)
@@ -155,6 +153,9 @@ fi
155153

156154
# `bindgen` returned successfully, thus use the output to check that the version
157155
# of the `libclang` found by the Rust bindings generator is suitable.
156+
#
157+
# Unlike other version checks, note that this one does not necessarily appear
158+
# in the first line of the output, thus no `sed` address is provided.
158159
bindgen_libclang_version=$( \
159160
echo "$bindgen_libclang_output" \
160161
| sed -nE 's:.*clang version ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p'

0 commit comments

Comments
 (0)