#!/usr/bin/env python3 """Copy the client root into the iOS app's Documents directory (development builds). The .app holds code only; on iOS the client runs in its Documents directory and reads the same flattened client root as Android (assets/loose + test-rundir + upstream/python-root + python27.zip). The tree is staged by android/push_assets.py --stage-only --lowercase into build/ios-data/root (all names ASCII lower-case: iOS file systems are case-sensitive and the client opens lower-cased paths), then: simulator copied into `xcrun simctl get_app_container data`/Documents as APFS clones (cp -c: no extra disk space, and the app cannot write through to the checkout) device sent with `xcrun devicectl device copy to` into the app data container Install the app first (ios/build.sh), since the container only exists after install. usage: ios/push_assets.py [device] [--simulator UDID] [--device ID] [--stdlib ZIP] [--pack-maker DIR] """ import argparse import os import re import shutil import subprocess import sys from pathlib import Path ROOT = Path(__file__).resolve().parent.parent BUNDLE_ID = os.environ.get("AVA2_IOS_BUNDLE_ID", "com.metin2.ava2") def booted_simulator(): out = subprocess.run(["xcrun", "simctl", "list", "devices", "booted"], check=True, capture_output=True, text=True).stdout match = re.search(r"\(([0-9A-F-]{36})\) \(Booted\)", out) return match.group(1) if match else None def main(): parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument("target", nargs="?", choices=["sim", "simulator", "device"], default="simulator") parser.add_argument("--simulator", default=os.environ.get("AVA2_IOS_SIMULATOR"), help="UDID (default: booted)") parser.add_argument("--device", default=os.environ.get("AVA2_IOS_DEVICE"), help="devicectl device id") parser.add_argument("--stdlib", help="python27.zip (default: the matching ios/build.sh output)") parser.add_argument("--pack-maker", help="passed to android/push_assets.py") parser.add_argument("--stage", type=Path, default=ROOT / "build/ios-data/root") args = parser.parse_args() device = args.target == "device" stdlib = args.stdlib or ROOT / f"build/ios-{'iphoneos' if device else 'iphonesimulator'}/python27.zip" if not Path(stdlib).is_file(): sys.exit(f"{stdlib} not found; run ios/build.sh first or pass --stdlib") # iOS file systems are case-sensitive while the client lower-cases the paths it opens # (ResourceManager::NormalizePath) and the data mixes cases, so stage every name lower-case. stage_cmd = [sys.executable, str(ROOT / "android/push_assets.py"), "--stage-only", "--lowercase", "--stage", str(args.stage), "--stdlib", str(stdlib)] if args.pack_maker: stage_cmd += ["--pack-maker", args.pack_maker] subprocess.run(stage_cmd, check=True) if not device: udid = args.simulator or booted_simulator() if not udid: sys.exit("no booted simulator; run ios/build.sh or pass --simulator") container = subprocess.run(["xcrun", "simctl", "get_app_container", udid, BUNDLE_ID, "data"], check=True, capture_output=True, text=True).stdout.strip() docs = Path(container) / "Documents" docs.mkdir(parents=True, exist_ok=True) # Trailing "/." copies the directory's contents; -c clones, plain copy across volumes. if subprocess.run(["cp", "-Rc", f"{args.stage}/.", str(docs)]).returncode != 0: subprocess.run(["cp", "-R", f"{args.stage}/.", str(docs)], check=True) print(f"copied to {docs}") return if not args.device: out = subprocess.run(["xcrun", "devicectl", "list", "devices"], check=True, capture_output=True, text=True).stdout ids = [line.split()[2] for line in out.splitlines() if re.search(r"available|connected", line) and re.search(r"iPhone|iPad", line)] if not ids: sys.exit("no device attached") args.device = ids[0] subprocess.run(["xcrun", "devicectl", "device", "copy", "to", "--device", args.device, "--domain-type", "appDataContainer", "--domain-identifier", BUNDLE_ID, "--source", str(args.stage), "--destination", "Documents"], check=True) print(f"copied to {args.device}:{BUNDLE_ID}/Documents") if __name__ == "__main__": main()