|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# test_macos_build_local.sh - Test macOS wheel build locally |
| 4 | +# |
| 5 | +# This script mirrors the macOS build pipeline from .github/workflows/release.yml |
| 6 | +# but runs locally for testing before pushing to CI. |
| 7 | +# |
| 8 | + |
| 9 | +set -e |
| 10 | + |
| 11 | +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 12 | +ROOT_DIR="$(dirname "$SCRIPT_DIR")" |
| 13 | + |
| 14 | +echo "================================" |
| 15 | +echo "Local macOS Build Test" |
| 16 | +echo "================================" |
| 17 | +echo "" |
| 18 | +echo "This script tests the macOS wheel build pipeline locally." |
| 19 | +echo "" |
| 20 | + |
| 21 | +# Parse arguments |
| 22 | +VERBOSE=false |
| 23 | +CLEAN=false |
| 24 | + |
| 25 | +while [[ $# -gt 0 ]]; do |
| 26 | + case $1 in |
| 27 | + --verbose|-v) |
| 28 | + VERBOSE=true |
| 29 | + shift |
| 30 | + ;; |
| 31 | + --clean) |
| 32 | + CLEAN=true |
| 33 | + shift |
| 34 | + ;; |
| 35 | + --help|-h) |
| 36 | + echo "Usage: $0 [OPTIONS]" |
| 37 | + echo "" |
| 38 | + echo "Options:" |
| 39 | + echo " --clean Clean build artifacts before building" |
| 40 | + echo " --verbose, -v Show verbose output" |
| 41 | + echo " --help, -h Show this help message" |
| 42 | + echo "" |
| 43 | + echo "Examples:" |
| 44 | + echo " $0 # Build wheel for current Python" |
| 45 | + echo " $0 --clean # Clean and build" |
| 46 | + echo " $0 --verbose # Show detailed build output" |
| 47 | + echo "" |
| 48 | + echo "Note: Uses the currently active python3 version" |
| 49 | + echo "" |
| 50 | + exit 0 |
| 51 | + ;; |
| 52 | + *) |
| 53 | + echo "Unknown option: $1" |
| 54 | + echo "Use --help for usage information" |
| 55 | + exit 1 |
| 56 | + ;; |
| 57 | + esac |
| 58 | +done |
| 59 | + |
| 60 | +PYTHON_VERSION=$(python3 --version) |
| 61 | + |
| 62 | +echo "Configuration:" |
| 63 | +echo " Platform: macOS $(sw_vers -productVersion)" |
| 64 | +echo " Architecture: $(uname -m)" |
| 65 | +echo " Python: $PYTHON_VERSION" |
| 66 | +echo " Output Dir: $ROOT_DIR/wheelhouse" |
| 67 | +echo "" |
| 68 | + |
| 69 | +# Create wheelhouse directory |
| 70 | +mkdir -p "$ROOT_DIR/wheelhouse" |
| 71 | + |
| 72 | +# Clean if requested |
| 73 | +if $CLEAN; then |
| 74 | + echo "🧹 Cleaning build artifacts..." |
| 75 | + rm -rf "$ROOT_DIR/wheelhouse"/*.whl |
| 76 | + rm -rf "$ROOT_DIR/build" |
| 77 | + rm -rf "$ROOT_DIR/dist" |
| 78 | + rm -rf "$ROOT_DIR"/*.egg-info |
| 79 | + rm -rf "$ROOT_DIR/src"/*.egg-info |
| 80 | + echo "✅ Clean complete" |
| 81 | + echo "" |
| 82 | +fi |
| 83 | + |
| 84 | +# Check for required tools |
| 85 | +echo "🔍 Checking prerequisites..." |
| 86 | + |
| 87 | +# Check for Homebrew |
| 88 | +if ! command -v brew &> /dev/null; then |
| 89 | + echo "❌ Error: Homebrew is not installed." |
| 90 | + echo " Install it from: https://brew.sh" |
| 91 | + exit 1 |
| 92 | +fi |
| 93 | +echo " ✓ Homebrew found" |
| 94 | + |
| 95 | +# Check for Python 3 |
| 96 | +if ! command -v python3 &> /dev/null; then |
| 97 | + echo "❌ Error: Python 3 is not installed." |
| 98 | + exit 1 |
| 99 | +fi |
| 100 | +echo " ✓ Python found: $PYTHON_VERSION" |
| 101 | + |
| 102 | +# Check for build tool |
| 103 | +if ! python3 -m pip list 2>/dev/null | grep -q "^build "; then |
| 104 | + echo "⚠️ build tool not found, installing..." |
| 105 | + python3 -m pip install build --user -q |
| 106 | +fi |
| 107 | +echo " ✓ build tool found" |
| 108 | + |
| 109 | +echo "" |
| 110 | + |
| 111 | +# Install build dependencies (mirrors the before-all step) |
| 112 | +echo "📦 Installing build dependencies..." |
| 113 | +BREW_PACKAGES="cmake ninja go" |
| 114 | +for pkg in $BREW_PACKAGES; do |
| 115 | + if brew list "$pkg" &>/dev/null; then |
| 116 | + echo " ✓ $pkg already installed" |
| 117 | + else |
| 118 | + echo " Installing $pkg..." |
| 119 | + if $VERBOSE; then |
| 120 | + brew install "$pkg" |
| 121 | + else |
| 122 | + brew install "$pkg" >/dev/null 2>&1 |
| 123 | + fi |
| 124 | + fi |
| 125 | +done |
| 126 | +echo "✅ Dependencies installed" |
| 127 | +echo "" |
| 128 | + |
| 129 | +# Setup vendor dependencies (mirrors the before-build step) |
| 130 | +echo "🔨 Building vendor dependencies..." |
| 131 | +echo " This may take several minutes (BoringSSL, nghttp2)..." |
| 132 | +if $VERBOSE; then |
| 133 | + bash "$ROOT_DIR/scripts/setup_vendors.sh" |
| 134 | +else |
| 135 | + bash "$ROOT_DIR/scripts/setup_vendors.sh" 2>&1 | grep -E "(===|✓|✅|⊘|ERROR|WARNING)" || true |
| 136 | +fi |
| 137 | +echo "" |
| 138 | + |
| 139 | +# Build wheel using python -m build |
| 140 | +echo "🔨 Building wheel..." |
| 141 | +echo "" |
| 142 | + |
| 143 | +cd "$ROOT_DIR" |
| 144 | + |
| 145 | +# Clean previous builds |
| 146 | +rm -rf build/ dist/ |
| 147 | + |
| 148 | +if $VERBOSE; then |
| 149 | + python3 -m build --wheel |
| 150 | +else |
| 151 | + python3 -m build --wheel 2>&1 | grep -E "(Successfully|ERROR|error|failed|Building)" || true |
| 152 | +fi |
| 153 | + |
| 154 | +BUILD_EXIT_CODE=$? |
| 155 | + |
| 156 | +# Copy wheel to wheelhouse if build succeeded |
| 157 | +if [[ $BUILD_EXIT_CODE -eq 0 ]] && [[ -d dist ]]; then |
| 158 | + mkdir -p wheelhouse |
| 159 | + cp dist/*.whl wheelhouse/ 2>/dev/null || true |
| 160 | +fi |
| 161 | + |
| 162 | +echo "" |
| 163 | +echo "════════════════════════════════════════════════════════════════" |
| 164 | +if [[ $BUILD_EXIT_CODE -eq 0 ]]; then |
| 165 | + echo "✅ Build completed successfully!" |
| 166 | + echo "════════════════════════════════════════════════════════════════" |
| 167 | + echo "" |
| 168 | + echo "Wheels are available in: $ROOT_DIR/wheelhouse" |
| 169 | + echo "" |
| 170 | + ls -lh "$ROOT_DIR/wheelhouse"/*.whl 2>/dev/null || echo "No wheels found in wheelhouse" |
| 171 | + echo "" |
| 172 | + echo "To install locally:" |
| 173 | + echo " pip install wheelhouse/httpmorph-*.whl" |
| 174 | + echo "" |
| 175 | + echo "To test the wheel:" |
| 176 | + echo " python3 -c 'import httpmorph; print(httpmorph.version())'" |
| 177 | +else |
| 178 | + echo "❌ Build failed with exit code $BUILD_EXIT_CODE" |
| 179 | + echo "════════════════════════════════════════════════════════════════" |
| 180 | + exit $BUILD_EXIT_CODE |
| 181 | +fi |
0 commit comments