Skip to content

Commit 3b7b013

Browse files
committed
Restore bundle script
1 parent a240e87 commit 3b7b013

File tree

1 file changed

+156
-0
lines changed

1 file changed

+156
-0
lines changed

scripts/bundle-axe.sh

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#!/bin/bash
2+
3+
# Build script for AXe artifacts
4+
# This script downloads pre-built AXe artifacts from GitHub releases and bundles them
5+
6+
set -e
7+
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
10+
BUNDLED_DIR="$PROJECT_ROOT/bundled"
11+
AXE_LOCAL_DIR="/Volumes/Developer/AXe"
12+
AXE_TEMP_DIR="/tmp/axe-download-$$"
13+
14+
echo "🔨 Preparing AXe artifacts for bundling..."
15+
16+
# Clean up any existing bundled directory
17+
if [ -d "$BUNDLED_DIR" ]; then
18+
echo "🧹 Cleaning existing bundled directory..."
19+
rm -rf "$BUNDLED_DIR"
20+
fi
21+
22+
# Create bundled directory
23+
mkdir -p "$BUNDLED_DIR"
24+
25+
# Use local AXe build if available, otherwise download from GitHub releases
26+
if [ -d "$AXE_LOCAL_DIR" ] && [ -f "$AXE_LOCAL_DIR/Package.swift" ]; then
27+
echo "🏠 Using local AXe source at $AXE_LOCAL_DIR"
28+
cd "$AXE_LOCAL_DIR"
29+
30+
# Build AXe in release configuration
31+
echo "🔨 Building AXe in release configuration..."
32+
swift build --configuration release
33+
34+
# Check if build succeeded
35+
if [ ! -f ".build/release/axe" ]; then
36+
echo "❌ AXe build failed - binary not found"
37+
exit 1
38+
fi
39+
40+
echo "✅ AXe build completed successfully"
41+
42+
# Copy binary to bundled directory
43+
echo "📦 Copying AXe binary..."
44+
cp ".build/release/axe" "$BUNDLED_DIR/"
45+
46+
# Fix rpath to find frameworks in Frameworks/ subdirectory
47+
echo "🔧 Configuring AXe binary rpath for bundled frameworks..."
48+
install_name_tool -add_rpath "@executable_path/Frameworks" "$BUNDLED_DIR/axe"
49+
50+
# Create Frameworks directory and copy frameworks
51+
echo "📦 Copying frameworks..."
52+
mkdir -p "$BUNDLED_DIR/Frameworks"
53+
54+
# Copy frameworks with better error handling
55+
for framework in .build/release/*.framework; do
56+
if [ -d "$framework" ]; then
57+
echo "📦 Copying framework: $(basename "$framework")"
58+
cp -r "$framework" "$BUNDLED_DIR/Frameworks/"
59+
60+
# Only copy nested frameworks if they exist
61+
if [ -d "$framework/Frameworks" ]; then
62+
echo "📦 Found nested frameworks in $(basename "$framework")"
63+
cp -r "$framework/Frameworks"/* "$BUNDLED_DIR/Frameworks/" 2>/dev/null || true
64+
fi
65+
fi
66+
done
67+
else
68+
echo "📥 Downloading latest AXe release from GitHub..."
69+
70+
# Get latest release download URL
71+
LATEST_RELEASE_URL="https://github.com/cameroncooke/AXe/releases/download/v1.0.0/AXe-macOS-v1.0.0.tar.gz"
72+
73+
# Create temp directory
74+
mkdir -p "$AXE_TEMP_DIR"
75+
cd "$AXE_TEMP_DIR"
76+
77+
# Download and extract the release
78+
echo "📥 Downloading AXe release archive..."
79+
curl -L -o "axe-release.tar.gz" "$LATEST_RELEASE_URL"
80+
81+
echo "📦 Extracting AXe release archive..."
82+
tar -xzf "axe-release.tar.gz"
83+
84+
# Find the extracted directory (might be named differently)
85+
EXTRACTED_DIR=$(find . -type d -name "*AXe*" -o -name "*axe*" | head -1)
86+
if [ -z "$EXTRACTED_DIR" ]; then
87+
# If no AXe directory found, assume files are in current directory
88+
EXTRACTED_DIR="."
89+
fi
90+
91+
cd "$EXTRACTED_DIR"
92+
93+
# Copy binary
94+
if [ -f "axe" ]; then
95+
echo "📦 Copying AXe binary..."
96+
cp "axe" "$BUNDLED_DIR/"
97+
chmod +x "$BUNDLED_DIR/axe"
98+
elif [ -f "bin/axe" ]; then
99+
echo "📦 Copying AXe binary from bin/..."
100+
cp "bin/axe" "$BUNDLED_DIR/"
101+
chmod +x "$BUNDLED_DIR/axe"
102+
else
103+
echo "❌ AXe binary not found in release archive"
104+
ls -la
105+
exit 1
106+
fi
107+
108+
# Copy frameworks if they exist
109+
echo "📦 Copying frameworks..."
110+
mkdir -p "$BUNDLED_DIR/Frameworks"
111+
112+
if [ -d "Frameworks" ]; then
113+
cp -r Frameworks/* "$BUNDLED_DIR/Frameworks/"
114+
elif [ -d "lib" ]; then
115+
# Look for frameworks in lib directory
116+
find lib -name "*.framework" -exec cp -r {} "$BUNDLED_DIR/Frameworks/" \;
117+
else
118+
echo "⚠️ No frameworks directory found in release archive"
119+
echo "📂 Contents of release archive:"
120+
find . -type f -name "*.framework" -o -name "*.dylib" | head -10
121+
fi
122+
fi
123+
124+
# Verify frameworks were copied
125+
FRAMEWORK_COUNT=$(find "$BUNDLED_DIR/Frameworks" -name "*.framework" | wc -l)
126+
echo "📦 Copied $FRAMEWORK_COUNT frameworks"
127+
128+
# List the frameworks for verification
129+
echo "🔍 Bundled frameworks:"
130+
ls -la "$BUNDLED_DIR/Frameworks/"
131+
132+
# Verify binary can run with bundled frameworks
133+
echo "🧪 Testing bundled AXe binary..."
134+
if DYLD_FRAMEWORK_PATH="$BUNDLED_DIR/Frameworks" "$BUNDLED_DIR/axe" --version > /dev/null 2>&1; then
135+
echo "✅ Bundled AXe binary test passed"
136+
else
137+
echo "❌ Bundled AXe binary test failed"
138+
exit 1
139+
fi
140+
141+
# Get AXe version for logging
142+
AXE_VERSION=$(DYLD_FRAMEWORK_PATH="$BUNDLED_DIR/Frameworks" "$BUNDLED_DIR/axe" --version 2>/dev/null || echo "unknown")
143+
echo "📋 AXe version: $AXE_VERSION"
144+
145+
# Clean up temp directory if it was used
146+
if [ -d "$AXE_TEMP_DIR" ]; then
147+
echo "🧹 Cleaning up temporary files..."
148+
rm -rf "$AXE_TEMP_DIR"
149+
fi
150+
151+
# Show final bundle size
152+
BUNDLE_SIZE=$(du -sh "$BUNDLED_DIR" | cut -f1)
153+
echo "📊 Final bundle size: $BUNDLE_SIZE"
154+
155+
echo "🎉 AXe bundling completed successfully!"
156+
echo "📁 Bundled artifacts location: $BUNDLED_DIR"

0 commit comments

Comments
 (0)