Skip to content

Commit 12717d1

Browse files
authored
chore(ffi): only backup hyper.h when passing --verify (#3800)
1 parent 8cf1121 commit 12717d1

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

capi/gen_header.sh

+12-6
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111
set -e
1212

1313
CAPI_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
14+
header_file="$CAPI_DIR/include/hyper.h"
1415
header_file_backup="$CAPI_DIR/include/hyper.h.backup"
15-
16+
verify_flag=$1
1617
function cleanup {
1718
rm -rf "$WORK_DIR" || true
18-
rm "$header_file_backup" || true
19+
if [[ "--verify" == "$verify_flag" ]]; then
20+
rm "$header_file_backup" || true
21+
fi
1922
}
2023

2124
trap cleanup EXIT
@@ -28,7 +31,10 @@ if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then
2831
exit 1
2932
fi
3033

31-
cp "$CAPI_DIR/include/hyper.h" "$header_file_backup"
34+
# backup hyper.h
35+
if [[ "--verify" == "$verify_flag" ]]; then
36+
cp "$header_file" "$header_file_backup"
37+
fi
3238

3339
# Expand just the ffi module
3440
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
3945
if ! cbindgen \
4046
--config "$CAPI_DIR/cbindgen.toml" \
4147
--lockfile "$CAPI_DIR/../Cargo.lock" \
42-
--output "$CAPI_DIR/include/hyper.h" \
48+
--output "$header_file" \
4349
"${@}"\
4450
$WORK_DIR/expanded.rs 2> $WORK_DIR/cbindgen_stderr.err; then
4551
bindgen_exit_code=$?
46-
if [[ "--verify" == "$1" ]]; then
52+
if [[ "--verify" == "$verify_flag" ]]; then
4753
echo "Changes from previous header (old < > new)"
48-
diff -u "$header_file_backup" "$CAPI_DIR/include/hyper.h"
54+
diff -u "$header_file_backup" "$header_file"
4955
else
5056
echo "cbindgen failed:"
5157
cat $WORK_DIR/cbindgen_stderr.err

0 commit comments

Comments
 (0)