package-macos-worker.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env python3
  2. """Package an already-built cgo-free worker in a minimal macOS app bundle."""
  3. import argparse
  4. import plistlib
  5. import shutil
  6. from pathlib import Path
  7. def package_worker(binary, destination):
  8. binary, destination = Path(binary), Path(destination)
  9. if not binary.is_file():
  10. raise ValueError("worker binary does not exist")
  11. if destination.exists():
  12. raise ValueError("destination already exists; choose a new bundle path")
  13. executable = destination / "Contents/MacOS/cfbrowser-worker"
  14. executable.parent.mkdir(parents=True)
  15. shutil.copy2(binary, executable)
  16. executable.chmod(0o755)
  17. metadata = {
  18. "CFBundleExecutable": "cfbrowser-worker",
  19. "CFBundleIdentifier": "dev.clusterflow.cfbrowser.worker",
  20. "CFBundleName": "CFBrowser Worker",
  21. "CFBundlePackageType": "APPL",
  22. "CFBundleVersion": "1",
  23. "CFBundleShortVersionString": "0.1.1",
  24. "LSMinimumSystemVersion": "11.0",
  25. "LSUIElement": True,
  26. # HTTP navigation is intentional browser functionality, including SSH tunnels.
  27. "NSAppTransportSecurity": {
  28. "NSAllowsLocalNetworking": True,
  29. "NSAllowsArbitraryLoadsInWebContent": True,
  30. },
  31. }
  32. with (destination / "Contents/Info.plist").open("wb") as output:
  33. plistlib.dump(metadata, output)
  34. return executable
  35. def main():
  36. parser = argparse.ArgumentParser(description=__doc__)
  37. parser.add_argument("binary")
  38. parser.add_argument("destination")
  39. args = parser.parse_args()
  40. print(package_worker(args.binary, args.destination))
  41. if __name__ == "__main__":
  42. main()