| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- #!/usr/bin/env python3
- """Package an already-built cgo-free worker in a minimal macOS app bundle."""
- import argparse
- import plistlib
- import shutil
- from pathlib import Path
- def package_worker(binary, destination):
- binary, destination = Path(binary), Path(destination)
- if not binary.is_file():
- raise ValueError("worker binary does not exist")
- if destination.exists():
- raise ValueError("destination already exists; choose a new bundle path")
- executable = destination / "Contents/MacOS/cfbrowser-worker"
- executable.parent.mkdir(parents=True)
- shutil.copy2(binary, executable)
- executable.chmod(0o755)
- metadata = {
- "CFBundleExecutable": "cfbrowser-worker",
- "CFBundleIdentifier": "dev.clusterflow.cfbrowser.worker",
- "CFBundleName": "CFBrowser Worker",
- "CFBundlePackageType": "APPL",
- "CFBundleVersion": "1",
- "CFBundleShortVersionString": "0.1.1",
- "LSMinimumSystemVersion": "11.0",
- "LSUIElement": True,
- # HTTP navigation is intentional browser functionality, including SSH tunnels.
- "NSAppTransportSecurity": {
- "NSAllowsLocalNetworking": True,
- "NSAllowsArbitraryLoadsInWebContent": True,
- },
- }
- with (destination / "Contents/Info.plist").open("wb") as output:
- plistlib.dump(metadata, output)
- return executable
- def main():
- parser = argparse.ArgumentParser(description=__doc__)
- parser.add_argument("binary")
- parser.add_argument("destination")
- args = parser.parse_args()
- print(package_worker(args.binary, args.destination))
- if __name__ == "__main__":
- main()
|