Files
moonwell-client-core/crates/moonwell/package_macos.py
T
sindoring da72c705f1 Integrate MoonWell launcher and deployment tools
Integrate the MoonWell launcher and deployment tooling on the local upstream baseline d0d1b5de. Correct the shipped icon path, regenerate the code map, and make source/Lua gates portable to Windows. Classify launcher startup icon access as input plumbing.

Verified on Windows: scripts/gates.sh ALL GATES GREEN; MoonWell release build without dev; 12 deployment tests; deployment and packaging script syntax. Stock MPQ chain excludes the custom patch-3. Thirty-one addon tests skip per data-enabled rung because the corpus is absent. Native macOS/Linux and live login smoke were not run; no declared test account is available.
2026-10-08 14:01:54 +03:00

90 lines
3.4 KiB
Python

#!/usr/bin/env python3
"""Package a macOS player build and an ICNS icon as MoonWell.app."""
import argparse
import os
from pathlib import Path
import plistlib
import shutil
import struct
import tomllib
# Keep the install and writable client state beside the app, outside the bundle.
LAUNCHER = '''#!/bin/sh
set -eu
macos_dir=$(CDPATH= cd -- "$(dirname "$0")" && pwd)
player_dir=$(CDPATH= cd -- "$macos_dir/../../.." && pwd)
if [ "${BENILLA_HOME+x}" != x ]; then
export BENILLA_HOME="$player_dir/benilla-config"
fi
if [ "${WOW_DATA+x}" != x ]; then
for data_dir in "$player_dir/Data" "$player_dir/WoW/Data"; do
if [ -d "$data_dir" ]; then
export WOW_DATA="$data_dir"
break
fi
done
fi
exec "$macos_dir/MoonWell" "$@"
'''
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--binary", type=Path, required=True,
help="MoonWell binary built on macOS without default features")
parser.add_argument("--icon", type=Path, required=True, help="application icon in .icns format")
parser.add_argument("--output", type=Path, default=Path("target/release/bundle/MoonWell.app"))
parser.add_argument("--bundle-id", default="org.moonwell.client")
args = parser.parse_args()
with args.binary.open("rb") as binary:
magic = binary.read(4)
if magic not in (b"\xfe\xed\xfa\xce", b"\xce\xfa\xed\xfe",
b"\xfe\xed\xfa\xcf", b"\xcf\xfa\xed\xfe",
b"\xca\xfe\xba\xbe", b"\xbe\xba\xfe\xca",
b"\xca\xfe\xba\xbf", b"\xbf\xba\xfe\xca"):
parser.error("--binary must be a macOS Mach-O executable, not a Windows EXE")
with args.icon.open("rb") as icon:
header = icon.read(8)
if len(header) != 8 or header[:4] != b"icns" or struct.unpack(">I", header[4:])[0] != args.icon.stat().st_size:
parser.error("--icon must be an ICNS file with a valid container header")
if args.output.suffix != ".app":
parser.error("--output must end in .app")
if args.output.exists():
parser.error("--output already exists; choose a new path or remove the old bundle first")
root = Path(__file__).resolve().parents[2]
with (root / "Cargo.toml").open("rb") as manifest:
version = tomllib.load(manifest)["workspace"]["package"]["version"]
contents = args.output / "Contents"
macos = contents / "MacOS"
resources = contents / "Resources"
macos.mkdir(parents=True)
resources.mkdir()
shutil.copyfile(args.binary, macos / "MoonWell")
(macos / "MoonWell").chmod(0o755)
(macos / "launch").write_text(LAUNCHER, encoding="utf-8", newline="\n")
(macos / "launch").chmod(0o755)
shutil.copyfile(args.icon, resources / "MoonWell.icns")
with (contents / "Info.plist").open("wb") as plist:
plistlib.dump({
"CFBundleName": "MoonWell",
"CFBundleDisplayName": "MoonWell",
"CFBundleExecutable": "launch",
"CFBundleIconFile": "MoonWell.icns",
"CFBundleIdentifier": args.bundle_id,
"CFBundleInfoDictionaryVersion": "6.0",
"CFBundlePackageType": "APPL",
"CFBundleShortVersionString": version,
"CFBundleVersion": version,
"NSHighResolutionCapable": True,
}, plist)
print(os.fspath(args.output.resolve()))
if __name__ == "__main__":
main()