script/generate-bindings - protect from using old incompatible bindgen versions

This commit is contained in:
Andrew Hlynskyi 2023-07-13 00:36:16 +03:00
parent 7afd5a1a8b
commit 45aede8bf5

View file

@ -16,6 +16,18 @@ no_derive_copy=(
)
no_copy=$(IFS='|'; echo "${no_derive_copy[*]}")
file_version=$(head -n1 "$output_path" | cut -d' ' -f6)
tool_version=$(bindgen --version | cut -d' ' -f2)
higher_version=$(echo -e "${file_version}\n${tool_version}" | sort -V | tail -n1)
if [ "$higher_version" != "$tool_version" ]; then
echo "Latest used bindgen version was $file_version" >&2
echo "Currently installed bindgen CLI version is $tool_version" >&2
echo >&2
echo "It's needed to upgrade bindgen CLI first with \`cargo install bindgen-cli\`" >&2
exit 1
fi
bindgen \
--no-layout-tests \
--allowlist-type '^TS.*' \
@ -31,7 +43,7 @@ defines=(
TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION
)
for define in ${defines[@]}; do
define_value=$(egrep "#define $define (.*)" $header_path | cut -d' ' -f3)
for define in "${defines[@]}"; do
define_value=$(grep -E "#define $define (.*)" $header_path | cut -d' ' -f3)
echo "pub const $define: usize = $define_value;" >> $output_path
done