Created
August 2, 2025 11:35
-
-
Save davidfstr/5bf0522683d437eca8c16ae2bd3e37f2 to your computer and use it in GitHub Desktop.
verify_universal2 - Claude 4 AI draft (BEFORE) and human draft (AFTER)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Verify that a macOS .app bundle contains all universal2 binaries. | |
| # | |
| # Usage: verify_universal2.sh <APP_PATH> | |
| set -e | |
| APP_PATH="$1" | |
| APP_NAME=$(basename "$APP_PATH") | |
| # Find all binary files | |
| BINARIES=$(find "$APP_PATH" -type f \( -name "*.so" -o -name "*.dylib" -o -perm +111 \) ! -name "*.sh" ! -name "*.pem" 2>/dev/null || true) | |
| if [ -z "$BINARIES" ]; then | |
| echo "WARNING: No binaries found to check" | |
| exit 1 | |
| fi | |
| # Identify any non-universal2 binaries | |
| NON_UNIVERSAL2_BINARIES="" | |
| for binary in $BINARIES; do | |
| # Get relative path for cleaner output | |
| REL_PATH="${binary#$APP_PATH/}" | |
| # Check what architectures the binary supports | |
| ARCH_INFO=$(file "$binary" 2>/dev/null || echo "") | |
| if [[ "$ARCH_INFO" == *"x86_64"* ]] && [[ "$ARCH_INFO" == *"arm64"* ]]; then | |
| : # universal2; do nothing | |
| elif [[ "$ARCH_INFO" == *"x86_64"* ]]; then | |
| NON_UNIVERSAL2_BINARIES="$NON_UNIVERSAL2_BINARIES$REL_PATH - x86_64 only\n" | |
| elif [[ "$ARCH_INFO" == *"arm64"* ]]; then | |
| NON_UNIVERSAL2_BINARIES="$NON_UNIVERSAL2_BINARIES$REL_PATH - arm64 only\n" | |
| elif [ -n "$ARCH_INFO" ]; then | |
| NON_UNIVERSAL2_BINARIES="$NON_UNIVERSAL2_BINARIES$REL_PATH - unknown architecture\n" | |
| fi | |
| done | |
| if [ -n "$NON_UNIVERSAL2_BINARIES" ]; then | |
| echo "Non-universal binaries found:" | |
| echo -e "$NON_UNIVERSAL2_BINARIES" | |
| echo "*** $APP_NAME is NOT fully universal2" | |
| exit 1 | |
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| """ | |
| Verify that a macOS .app bundle contains universal2 binaries. | |
| """ | |
| import os | |
| import subprocess | |
| import sys | |
| from pathlib import Path | |
| def check_binary_architectures(binary_path): | |
| """ | |
| Check what architectures a binary supports using the 'file' command. | |
| Returns a set of architectures found. | |
| """ | |
| try: | |
| result = subprocess.run(['file', str(binary_path)], | |
| capture_output=True, text=True, check=True) | |
| output = result.stdout.lower() | |
| architectures = set() | |
| if 'x86_64' in output or 'x86-64' in output: | |
| architectures.add('x86_64') | |
| if 'arm64' in output: | |
| architectures.add('arm64') | |
| return architectures | |
| except subprocess.CalledProcessError: | |
| return set() | |
| def find_binaries(app_path): | |
| """ | |
| Find all binary files in the .app bundle that should be universal2. | |
| """ | |
| app_path = Path(app_path) | |
| binaries = [] | |
| # Main executable | |
| main_exec = app_path / 'Contents' / 'MacOS' / app_path.stem | |
| if main_exec.exists(): | |
| binaries.append(main_exec) | |
| # Python framework libraries and extensions | |
| lib_path = app_path / 'Contents' / 'Resources' / 'lib' | |
| if lib_path.exists(): | |
| for path in lib_path.rglob('*'): | |
| if path.is_file() and (path.suffix in ['.so', '.dylib'] or | |
| (path.is_file() and os.access(path, os.X_OK) and | |
| not path.suffix)): | |
| binaries.append(path) | |
| return binaries | |
| def main(): | |
| if len(sys.argv) != 2: | |
| print(f"Usage: {sys.argv[0]} <path_to.app>") | |
| sys.exit(1) | |
| app_path = Path(sys.argv[1]) | |
| if not app_path.exists(): | |
| print(f"Error: {app_path} does not exist") | |
| sys.exit(1) | |
| if not app_path.is_dir() or not app_path.name.endswith('.app'): | |
| print(f"Error: {app_path} is not a .app bundle") | |
| sys.exit(1) | |
| print(f"Verifying universal2 support in {app_path.name}...") | |
| binaries = find_binaries(app_path) | |
| if not binaries: | |
| print("Warning: No binaries found to check") | |
| sys.exit(1) | |
| all_universal2 = True | |
| issues = [] | |
| for binary in binaries: | |
| architectures = check_binary_architectures(binary) | |
| # Check relative path for cleaner output | |
| rel_path = binary.relative_to(app_path) | |
| if {'x86_64', 'arm64'} <= architectures: | |
| print(f"✓ {rel_path}: universal2 (x86_64 + arm64)") | |
| elif architectures: | |
| all_universal2 = False | |
| arch_str = ', '.join(sorted(architectures)) | |
| issues.append(f"✗ {rel_path}: {arch_str} only") | |
| else: | |
| all_universal2 = False | |
| issues.append(f"? {rel_path}: could not determine architecture") | |
| if issues: | |
| print("\nIssues found:") | |
| for issue in issues: | |
| print(f" {issue}") | |
| if all_universal2: | |
| print(f"\n✓ {app_path.name} is fully universal2!") | |
| sys.exit(0) | |
| else: | |
| print(f"\n✗ {app_path.name} is NOT fully universal2") | |
| sys.exit(1) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment