fix_macos_uvx.shโข5.71 kB
#!/bin/bash
# Final OR-Tools fix for uvx on macOS - robust and dynamic
# No hardcoded versions, smart library detection
set -e
echo "๐ฏ Final macOS uvx OR-Tools fix (dynamic detection)"
# Function to find homebrew path
find_homebrew_path() {
if [[ -d "/opt/homebrew" ]]; then
echo "/opt/homebrew"
elif [[ -d "/usr/local" ]]; then
echo "/usr/local"
else
echo "โ Homebrew not found"
return 1
fi
}
# Function to detect hardcoded paths from existing OR-Tools cache
detect_hardcoded_paths() {
echo "๐ Detecting hardcoded paths from OR-Tools cache..."
local found_paths=()
# Look in uvx cache for OR-Tools .so files
local cache_pattern="/Users/$USER/.cache/uv/archive-v0/*/lib/python*/site-packages/ortools"
for ortools_dir in $cache_pattern; do
if [[ -d "$ortools_dir" ]]; then
echo " ๐ฆ Found OR-Tools cache: $(dirname "$ortools_dir")"
# Find .so files and extract their dependencies
local so_files=($(find "$ortools_dir" -name "*.so" 2>/dev/null | head -5))
for so_file in "${so_files[@]}"; do
if [[ -f "$so_file" ]]; then
# Extract hardcoded libscip paths using otool
local deps=$(otool -L "$so_file" 2>/dev/null | grep -o '/[^[:space:]]*corentinl[^[:space:]]*/libscip[^[:space:]]*.dylib' || true)
if [[ -n "$deps" ]]; then
while IFS= read -r dep; do
[[ -n "$dep" ]] && found_paths+=("$dep")
done <<< "$deps"
fi
fi
done
fi
done
# Remove duplicates and return unique paths
if [[ ${#found_paths[@]} -gt 0 ]]; then
printf '%s\n' "${found_paths[@]}" | sort -u
else
# Fallback to common patterns if no cache found
echo "/Users/corentinl/work/stable/temp_python3.13/lib/libscip.9.2.dylib"
echo "/Users/corentinl/work/stable/temp_python3.12/lib/libscip.9.2.dylib"
echo "/Users/corentinl/work/stable/temp_python3.11/lib/libscip.9.2.dylib"
fi
}
# Main execution
echo "๐ Step 1: Environment detection"
HOMEBREW_PATH=$(find_homebrew_path)
if [[ $? -ne 0 ]]; then
echo "โ Homebrew required but not found"
exit 1
fi
echo "โ
Homebrew: $HOMEBREW_PATH"
echo ""
echo "๐ฆ Step 2: Dependencies check"
# Check and install dependencies quietly
for package in or-tools scip; do
if ! brew list "$package" &>/dev/null; then
echo "Installing $package..."
brew install "$package" >/dev/null 2>&1 || echo "โ ๏ธ $package installation issues"
else
echo "โ
$package already installed"
fi
done
echo ""
echo "๐ Step 3: Library discovery"
# Find SCIP libraries
SCIP_LIBS=($(find "$HOMEBREW_PATH/lib" -name "*libscip*.dylib" 2>/dev/null | sort))
if [[ ${#SCIP_LIBS[@]} -eq 0 ]]; then
echo "โ No SCIP libraries found"
exit 1
fi
echo "Available SCIP libraries:"
for lib in "${SCIP_LIBS[@]}"; do
echo " ๐ $(basename "$lib")"
done
# Select best library (prefer versioned)
PRIMARY_LIB="${SCIP_LIBS[0]}"
for lib in "${SCIP_LIBS[@]}"; do
if [[ "$(basename "$lib")" =~ ^libscip\.[0-9]+\.[0-9]+\.dylib$ ]]; then
PRIMARY_LIB="$lib"
break
fi
done
echo "โ
Primary library: $(basename "$PRIMARY_LIB")"
echo ""
echo "๐ฏ Step 4: Hardcoded path detection"
readarray -t HARDCODED_PATHS < <(detect_hardcoded_paths)
echo "Detected hardcoded paths:"
for path in "${HARDCODED_PATHS[@]}"; do
echo " ๐ $path"
done
echo ""
echo "๐ง Step 5: Symbolic link creation"
links_created=0
skipped=0
for hardcoded_path in "${HARDCODED_PATHS[@]}"; do
# Skip empty lines
[[ -z "$hardcoded_path" ]] && continue
target_dir=$(dirname "$hardcoded_path")
# Check if already exists
if [[ -L "$hardcoded_path" ]] || [[ -f "$hardcoded_path" ]]; then
echo "โ
Exists: $(basename "$hardcoded_path")"
((skipped++))
continue
fi
# Create directory if needed
if [[ ! -d "$target_dir" ]]; then
echo "๐ Creating: $target_dir"
if ! sudo mkdir -p "$target_dir" 2>/dev/null; then
echo "โ ๏ธ Cannot create directory: $target_dir"
continue
fi
fi
# Create symbolic link
echo "๐ Creating: $(basename "$hardcoded_path") -> $(basename "$PRIMARY_LIB")"
if sudo ln -sf "$PRIMARY_LIB" "$hardcoded_path" 2>/dev/null; then
((links_created++))
else
echo "โ ๏ธ Cannot create symlink: $hardcoded_path"
fi
done
echo ""
echo "โ
Links created: $links_created, skipped: $skipped"
echo ""
echo "๐งช Step 6: Quick verification"
# Quick test without hanging
echo "Testing uvx functionality..."
if command -v uvx >/dev/null 2>&1; then
echo "โ
uvx command available"
# Test is now manual to avoid hanging
echo "๐ Manual test recommended: uvx mcp-optimizer --help"
else
echo "โ ๏ธ uvx command not found"
fi
echo ""
echo "๐ Final macOS uvx fix completed!"
echo ""
echo "๐ Summary:"
echo " ๐ Homebrew: $HOMEBREW_PATH"
echo " ๐ SCIP libraries: ${#SCIP_LIBS[@]} available"
echo " ๐ฏ Hardcoded paths: ${#HARDCODED_PATHS[@]} processed"
echo " ๐ Symlinks created: $links_created"
echo " ๐ฆ Primary library: $(basename "$PRIMARY_LIB")"
echo ""
echo "๐ก Usage examples:"
echo " uvx mcp-optimizer --help"
echo " uvx mcp-optimizer --transport stdio"
echo " uvx --python python3.12 mcp-optimizer --transport stdio"
echo ""
echo "๐ฏ This provides dynamic OR-Tools support without hardcoded versions!"