|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +# Get the directory where the script is located |
| 6 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 7 | + |
| 8 | +# Function to display usage information |
| 9 | +usage() { |
| 10 | + echo "Usage: $0 <commit-sha>" |
| 11 | + echo "Example: $0 abcdef1234567890abcdef1234567890abcdef12" |
| 12 | + exit 1 |
| 13 | +} |
| 14 | + |
| 15 | +# Function to print error messages |
| 16 | +error_echo() { |
| 17 | + echo "Error: $1" |
| 18 | +} |
| 19 | + |
| 20 | +# Check if a commit SHA is provided |
| 21 | +if [ -z "${1:-}" ]; then |
| 22 | + error_echo "No commit SHA provided." |
| 23 | + usage |
| 24 | +fi |
| 25 | + |
| 26 | +COMMIT_SHA="$1" |
| 27 | + |
| 28 | +# Validate commit SHA format |
| 29 | +if ! [[ "$COMMIT_SHA" =~ ^[a-fA-F0-9]{40}$ ]]; then |
| 30 | + error_echo "Invalid commit SHA format." |
| 31 | + usage |
| 32 | +fi |
| 33 | + |
| 34 | +# Ensure required commands are available |
| 35 | +required_commands=("git" "cmake" "ninja" "clang2py") |
| 36 | +for cmd in "${required_commands[@]}"; do |
| 37 | + if ! command -v "$cmd" &> /dev/null; then |
| 38 | + error_echo "$cmd is not installed." |
| 39 | + exit 1 |
| 40 | + fi |
| 41 | +done |
| 42 | + |
| 43 | +# Pull the subtree with the provided commit SHA |
| 44 | +echo "Pulling subtree with commit SHA: $COMMIT_SHA" |
| 45 | +git subtree pull --prefix=depend/bitcoin https://github.com/bitcoin/bitcoin "$COMMIT_SHA" --squash |
| 46 | + |
| 47 | +echo "Subtree pulled successfully." |
| 48 | + |
| 49 | +pushd depend/bitcoin |
| 50 | + |
| 51 | +mkdir -p build |
| 52 | +cmake -B build -G Ninja -DBUILD_KERNEL_LIB=ON -DBUILD_UTIL_CHAINSTATE=ON |
| 53 | +cmake --build build |
| 54 | + |
| 55 | +# Install and capture library path |
| 56 | +INSTALL_OUTPUT=$(sudo cmake --install build 2>&1) |
| 57 | +LIB_PATH=$(echo "$INSTALL_OUTPUT" | grep -Eo '/[^ ]+\.(so|dylib|dll)') || true |
| 58 | + |
| 59 | +NM_OPTION="" |
| 60 | +if [[ "${OSTYPE}" == "darwin"* ]]; then |
| 61 | + NM_OPTION="--nm $SCRIPT_DIR/nm_patch.py" |
| 62 | +fi |
| 63 | + |
| 64 | +if [ -z "$LIB_PATH" ]; then |
| 65 | + echo "Error: Library path not found." |
| 66 | + exit 1 |
| 67 | +fi |
| 68 | + |
| 69 | +OUTPUT_FILE="bindings.py.new" |
| 70 | + |
| 71 | +if [ -f "$OUTPUT_FILE" ]; then |
| 72 | + echo "Warning: $OUTPUT_FILE already exists and will be overwritten." |
| 73 | +fi |
| 74 | + |
| 75 | +popd |
| 76 | + |
| 77 | +clang2py "$SCRIPT_DIR/../depend/bitcoin/src/kernel/bitcoinkernel.h" -l "$LIB_PATH" $NM_OPTION > "$OUTPUT_FILE" |
| 78 | + |
| 79 | +echo "Bindings generated successfully at $OUTPUT_FILE." |
0 commit comments