From 12717d16594debd8f2b1e3e169cc9b4700ee25b3 Mon Sep 17 00:00:00 2001 From: Lin Yihai <1161813899@qq.com> Date: Sat, 30 Nov 2024 02:44:41 +0800 Subject: [PATCH] chore(ffi): only backup hyper.h when passing --verify (#3800) --- capi/gen_header.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/capi/gen_header.sh b/capi/gen_header.sh index 2696340b48..d7de2e7a09 100755 --- a/capi/gen_header.sh +++ b/capi/gen_header.sh @@ -11,11 +11,14 @@ set -e CAPI_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +header_file="$CAPI_DIR/include/hyper.h" header_file_backup="$CAPI_DIR/include/hyper.h.backup" - +verify_flag=$1 function cleanup { rm -rf "$WORK_DIR" || true - rm "$header_file_backup" || true + if [[ "--verify" == "$verify_flag" ]]; then + rm "$header_file_backup" || true + fi } trap cleanup EXIT @@ -28,7 +31,10 @@ if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then exit 1 fi -cp "$CAPI_DIR/include/hyper.h" "$header_file_backup" +# backup hyper.h +if [[ "--verify" == "$verify_flag" ]]; then + cp "$header_file" "$header_file_backup" +fi # Expand just the ffi module if ! RUSTFLAGS='--cfg hyper_unstable_ffi' cargo expand --features client,http1,http2,ffi ::ffi 2> $WORK_DIR/expand_stderr.err > $WORK_DIR/expanded.rs; then @@ -39,13 +45,13 @@ fi if ! cbindgen \ --config "$CAPI_DIR/cbindgen.toml" \ --lockfile "$CAPI_DIR/../Cargo.lock" \ - --output "$CAPI_DIR/include/hyper.h" \ + --output "$header_file" \ "${@}"\ $WORK_DIR/expanded.rs 2> $WORK_DIR/cbindgen_stderr.err; then bindgen_exit_code=$? - if [[ "--verify" == "$1" ]]; then + if [[ "--verify" == "$verify_flag" ]]; then echo "Changes from previous header (old < > new)" - diff -u "$header_file_backup" "$CAPI_DIR/include/hyper.h" + diff -u "$header_file_backup" "$header_file" else echo "cbindgen failed:" cat $WORK_DIR/cbindgen_stderr.err