if [ -z "$1" ]; then
echo 'Expected a path to an OmniSciDB source folder - e.g. generate_thrift_bindings.sh ../omniscidb'
exit 1
fi
if ! thrift --version | grep -q 'Thrift version 0.13.0'; then
echo 'Thrift version 0.13.0 not installed'
exit 1
fi
MAPD_THRIFT_PATH="$1/mapd.thrift"
if [ ! -f $MAPD_THRIFT_PATH ]; then
echo "$MAPD_THRIFT_PATH not found"
exit 1
fi
if ! thrift -gen rs -recurse -out src $MAPD_THRIFT_PATH; then
echo 'Failed to generate Thrift bindings'
exit 1
fi
fix_clippy () {
if ! grep -q '#!\[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments, type_complexity))\]' $1; then
echo "Clippy line not found in $1"
exit 1
fi
if ! perl -0777 -i -pe 's/#!\[cfg_attr\(feature = "cargo-clippy", allow\(too_many_arguments, type_complexity\)\)\]/#![cfg_attr(feature = "cargo-clippy", allow(clippy::too_many_arguments, clippy::type_complexity))]/g' $1; then
echo "Failed to fix clippy line in $1"
exit 1
fi
}
fix_clippy "src/common.rs"
fix_clippy "src/completion_hints.rs"
fix_clippy "src/extension_functions.rs"
fix_clippy "src/mapd.rs"
fix_clippy "src/serialized_result_set.rs"
if ! perl -0777 -pi -e 's/use common;\nuse completion_hints;\nuse extension_functions;\nuse serialized_result_set;/use crate::common;\nuse crate::completion_hints;\nuse crate::extension_functions;\nuse crate::serialized_result_set;/gs' src/mapd.rs; then
echo "Failed to fix use declarations in mapd.rs"
exit 1
fi
if ! perl -0777 -pi -e 's/use common;/use crate::common;/g' src/serialized_result_set.rs; then
echo "Failed to fix use declarations in serialized_result_set.rs"
exit 1
fi
if ! sed -i "1i\/\/ Generated from OmniSciDB commit $(cd ../omniscidb; git log -n 1 --pretty=format:"%H")" src/common.rs src/completion_hints.rs src/extension_functions.rs src/mapd.rs src/serialized_result_set.rs; then
echo "Failed to add commit hash comments"
exit 1
fi
if ! perl -pi -e 'chomp if eof' src/common.rs src/completion_hints.rs src/extension_functions.rs src/mapd.rs src/serialized_result_set.rs; then
echo "Failed to chomp newlines"
exit 1
fi