Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

Sync patcher: the work-dir patch handles upstream #278's block too (from PR #17)

LNPANDY73a986af6274
diff --git a/scripts/sync_upstream.py b/scripts/sync_upstream.py
index 476f81cb..39f1da4d 100644
--- a/scripts/sync_upstream.py
+++ b/scripts/sync_upstream.py
@@ -368,20 +368,30 @@ def patch_nsp(t):
# Two separate one-line anchors: upstream inserts lines between them whenever it adds a check
# (ffcd910 put a mac_pack check right above `work`), which broke the old three-line anchor and
# stopped the daily sync for two days (issue #13). `work` and that out_ipa line each appear once.
- # One replacement for both lines: `out_ipa` reads `work`, so patching them separately let the
- # out_ipa patch land above the work patch (issue: PR #15, an UnboundLocalError on every build
- # without -o). The anchor covers upstream's three-line block and puts work first.
- P.append(('work-dir paths', 'args.work_dir', [(
- " out_ipa = Path(os.path.expanduser(args.out or OUT_IPA)).resolve() if (args.out or OUT_IPA) else nsp_dir / g.get('ipa') # by default in the NSP folder, next to the NSPs and <id>_build/\n"
- " if shadowed and not (args.out or OUT_IPA): out_ipa = out_ipa.with_name(out_ipa.stem + '-provisional.ipa') # never over the IPA of the game's real profile\n"
- " if mac_pack and (args.out or OUT_IPA) and out_ipa.suffix != '.app': raise BuildError(f'the Mac app (-o / OUT_IPA) must end in .app: {out_ipa}')\n"
- " work = nsp_dir / f'{g.id}_build'",
- " work = Path(os.path.expanduser(args.work_dir)).resolve() if args.work_dir else nsp_dir / f'{g.id}_build' # the folder holding the NSPs by default; --work-dir puts the build elsewhere\n"
- " # out_ipa reads `work`, so `work` must be assigned first (upstream's order had them the other\n"
- " # way round; the --work-dir patch moved `work` up here and this line had to follow it).\n"
- " out_ipa = Path(os.path.expanduser(args.out or OUT_IPA)).resolve() if (args.out or OUT_IPA) else work.parent / g.get('ipa') # by default next to the NSPs and <id>_build/\n"
- " if shadowed and not (args.out or OUT_IPA): out_ipa = out_ipa.with_name(out_ipa.stem + '-provisional.ipa') # never over the IPA of the game's real profile\n"
- " if mac_pack and (args.out or OUT_IPA) and out_ipa.suffix != '.app': raise BuildError(f'the Mac app (-o / OUT_IPA) must end in .app: {out_ipa}')")]))
+ # `out_ipa` reads `work`, so `work` must be assigned first: patched separately they once landed
+ # in the wrong order (PR #15 — an UnboundLocalError on every build without -o). One replacement
+ # per shape of upstream's block keeps them in order:
+ # - before upstream #278: one out_ipa line, the two checks, then `work`;
+ # - after #278: out_ipa under `if want_ios:` (8 spaces) plus an out_app block, `work` still last.
+ # Each shape is ONE (old, new) pair rather than a delete plus an insert: a two-step edit that
+ # removes `work` and puts it back leaves the tree without the assignment if the second step ever
+ # stops matching.
+ work_line = " work = Path(os.path.expanduser(args.work_dir)).resolve() if args.work_dir else nsp_dir / f'{g.id}_build' # the folder holding the NSPs by default; --work-dir puts the build elsewhere"
+ oipa_old = "out_ipa = Path(os.path.expanduser(args.out or OUT_IPA)).resolve() if (args.out or OUT_IPA) else nsp_dir / g.get('ipa') # by default in the NSP folder, next to the NSPs and <id>_build/"
+ oipa_new = "out_ipa = Path(os.path.expanduser(args.out or OUT_IPA)).resolve() if (args.out or OUT_IPA) else work.parent / g.get('ipa') # by default next to the NSPs and <id>_build/"
+ shadowed_line = " if shadowed and not (args.out or OUT_IPA): out_ipa = out_ipa.with_name(out_ipa.stem + '-provisional.ipa') # never over the IPA of the game's real profile"
+ macpack_line = " if mac_pack and (args.out or OUT_IPA) and out_ipa.suffix != '.app': raise BuildError(f'the Mac app (-o / OUT_IPA) must end in .app: {out_ipa}')"
+ if "\n out_ipa = None\n if want_ios:\n" in t: # upstream #278's shape
+ P.append(('work-dir paths', 'args.work_dir', [(
+ " out_ipa = None\n if want_ios:\n " + oipa_old + "\n",
+ work_line + "\n out_ipa = None\n if want_ios:\n " + oipa_new + "\n")]))
+ else:
+ P.append(('work-dir paths', 'args.work_dir', [(
+ " " + oipa_old + "\n" + shadowed_line + "\n" + macpack_line + "\n work = nsp_dir / f'{g.id}_build'",
+ work_line + "\n"
+ " # out_ipa reads `work`, so `work` must be assigned first (upstream's order had them the other\n"
+ " # way round; the --work-dir patch moved `work` up here and this line had to follow it).\n"
+ " " + oipa_new + "\n" + shadowed_line + "\n" + macpack_line)]))
P.append(('DOTNET_ROOT', 'list-runtimes', [(
" env.setdefault('USER', getpass.getuser()) # xcodegen fails without USER (Couldn't find current username)",
""" env.setdefault('USER', getpass.getuser()) # xcodegen fails without USER (Couldn't find current username)