Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Only backup when passing --verify #3800

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions capi/gen_header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down