| 1 | """Bundle the local development app. Distribution signing is a separate step.""" |
| 2 | from pathlib import Path |
| 3 | import plistlib |
| 4 | import shutil |
| 5 | import subprocess |
| 6 | import sys |
| 7 | |
| 8 | configuration = sys.argv[1] if len(sys.argv) > 1 else 'debug' |
| 9 | if configuration not in ('debug', 'release'): raise ValueError('invalid build configuration') |
| 10 | root = Path(__file__).resolve().parent.parent |
| 11 | products = Path(subprocess.check_output(['swift', 'build', '--package-path', str(root / 'apple'), '--configuration', configuration, '--show-bin-path'], text=True).strip()) |
| 12 | bundle = root / 'build/Calls.app/Contents' |
| 13 | if bundle.parent.exists(): shutil.rmtree(bundle.parent) |
| 14 | (bundle / 'MacOS').mkdir(parents=True, exist_ok=True) |
| 15 | (bundle / 'Frameworks').mkdir(parents=True, exist_ok=True) |
| 16 | (bundle / 'Resources').mkdir(parents=True, exist_ok=True) |
| 17 | shutil.copy2(products / 'CallsMac', bundle / 'MacOS/CallsMac') |
| 18 | subprocess.run(['swift', str(root / 'scripts/generate-mac-icon.swift')], check=True) |
| 19 | icon = root / 'apple/Sources/CallsMac/Resources/MacIcon.png' |
| 20 | shutil.copy2(icon, bundle / 'Resources/MacIcon.png') |
| 21 | shutil.copy2(root / 'LICENSE.lucide', bundle / 'Resources/LICENSE.lucide') |
| 22 | shutil.copy2(root / 'LICENSE.rnnoise', bundle / 'Resources/LICENSE.rnnoise') |
| 23 | shutil.copy2(root / 'LICENSE.deepfilternet', bundle / 'Resources/LICENSE.deepfilternet') |
| 24 | # The Rust crates libdf links (scripts/deepfilter-notices.py) and WebRTC's |
| 25 | # own licence, for the LiveKitWebRTC framework embedded below. |
| 26 | shutil.copy2(root / 'LICENSE.deepfilternet-crates', bundle / 'Resources/LICENSE.deepfilternet-crates') |
| 27 | shutil.copy2(root / 'LICENSE.webrtc', bundle / 'Resources/LICENSE.webrtc') |
| 28 | shutil.copy2(root / 'PATENTS.webrtc', bundle / 'Resources/PATENTS.webrtc') |
| 29 | # The Mac's noise suppressor model (scripts/build-deepfilter.sh). Without |
| 30 | # it the app falls back to RNNoise. |
| 31 | shutil.copy2(root / 'build/DeepFilterNet3_onnx.tar.gz', bundle / 'Resources/DeepFilterNet3_onnx.tar.gz') |
| 32 | # Finder reads the ICNS before the app launches; the PNG also supplies the |
| 33 | # runtime Dock icon. Generate each required representation from the master. |
| 34 | iconset = root / 'build/AppIcon.iconset' |
| 35 | iconset.mkdir(parents=True, exist_ok=True) |
| 36 | for size in (16, 32, 128, 256, 512): |
| 37 | for scale in (1, 2): |
| 38 | name = f'icon_{size}x{size}' + ('@2x' if scale == 2 else '') + '.png' |
| 39 | subprocess.run(['sips', '-z', str(size * scale), str(size * scale), |
| 40 | str(icon), '--out', str(iconset / name)], |
| 41 | check=True, stdout=subprocess.DEVNULL) |
| 42 | subprocess.run(['iconutil', '-c', 'icns', str(iconset), '-o', |
| 43 | str(bundle / 'Resources/CallsMac.icns')], check=True) |
| 44 | info = { |
| 45 | 'CFBundleURLTypes': [{'CFBundleURLName': 'net.amadan.oficina.calls.join', |
| 46 | 'CFBundleURLSchemes': ['oficina-calls']}], |
| 47 | 'CFBundleName': 'Calls', 'CFBundleDisplayName': 'Calls', |
| 48 | 'CFBundleIdentifier': 'net.amadan.oficina.calls', |
| 49 | 'CFBundleExecutable': 'CallsMac', 'CFBundlePackageType': 'APPL', |
| 50 | 'CFBundleIconFile': 'CallsMac.icns', |
| 51 | 'CFBundleShortVersionString': '0.1.0', 'CFBundleVersion': '1', |
| 52 | 'LSMinimumSystemVersion': '14.0', 'NSHighResolutionCapable': True, |
| 53 | 'NSCameraUseContinuityCameraDeviceType': True, |
| 54 | 'NSCameraUsageDescription': 'Calls uses your camera to share video in a meeting.', |
| 55 | 'NSMicrophoneUsageDescription': 'Calls uses your microphone so people in the meeting can hear you.', |
| 56 | } |
| 57 | (bundle / 'Info.plist').write_bytes(plistlib.dumps(info)) |
| 58 | # SwiftPM links dynamic binary dependencies using @rpath. Embed just the macOS |
| 59 | # slice rather than shipping iOS and simulator frameworks inside the Mac app. |
| 60 | for xc in [root / 'build/CallsBridge.xcframework', *list((root / 'apple/.build/artifacts').rglob('LiveKitWebRTC.xcframework'))]: |
| 61 | manifest = plistlib.loads((xc / 'Info.plist').read_bytes()) |
| 62 | for lib in manifest['AvailableLibraries']: |
| 63 | if lib['SupportedPlatform'] != 'macos': |
| 64 | continue |
| 65 | source = xc / lib['LibraryIdentifier'] / lib['LibraryPath'] |
| 66 | binary = source / source.stem |
| 67 | if 'dynamically linked' not in subprocess.check_output(['file', str(binary)], text=True): |
| 68 | continue |
| 69 | dest = bundle / 'Frameworks' / source.name |
| 70 | if dest.exists(): shutil.rmtree(dest) |
| 71 | shutil.copytree(source, dest, symlinks=True) |
| 72 | for resource in products.glob('*.bundle'): |
| 73 | shutil.copytree(resource, bundle / 'Resources' / resource.name, symlinks=True) |
| 74 | subprocess.run(['install_name_tool', '-add_rpath', '@executable_path/../Frameworks', str(bundle / 'MacOS/CallsMac')], check=True) |
| 75 | |