Skip to content

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

4.2 KB
Raw Blame
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: v0lumehi <[email protected]>
Date: Wed, 28 Oct 2026 13:33:53 +0100
Subject: [PATCH] NSP script: HOME from the password database, DOTNET_CLI_HOME,
 no .NET telemetry

Every child of the build gets a usable HOME and DOTNET_CLI_HOME; DOTNET_CLI_TELEMETRY_OPTOUT and DOTNET_NOLOGO default on.

Upstream-Status: pending
Reason: A GUI launch can hand the build an empty HOME, and .NET first-run configure dies on it; telemetry and the banner are off for the build
Issue: LNPANDY/NX2Apple#10
---
 scripts/build_ipa_from_nsp.py | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/scripts/build_ipa_from_nsp.py b/scripts/build_ipa_from_nsp.py
index 15bebe3..771182e 100755
--- a/scripts/build_ipa_from_nsp.py
+++ b/scripts/build_ipa_from_nsp.py
@@ -33,7 +33,7 @@
 # unless ALLOW_OTHER_METAL / --allow-other-metal. Issue #242 reported corruption with another compiler; the cause is still unconfirmed.
 # Python 3.12+ is required for bounded archive mappings inside images. The Python running this file needs lz4, capstone 5.x, fonttools and zbic (and backports.zstd before Python 3.14); also needed: Xcode, xcodegen, .NET SDK 10, zstd. SPIRV-Cross is the in-repo build. A first run takes 2 (Metroid Dread) to 10 minutes (Breath of the Wild: 5 of them the shader split), longer when shader libraries must be compiled; a repeat run with unchanged inputs takes about 20 s (Metroid Dread), mostly packing the IPA. Key values are never printed.
 # The console shows one line per stage ([k/n] stage, with a bar, done/total, percent, elapsed time and ETA where the work can be counted); the tools' own output goes only to logs/ (PROGRESS / --progress). --progress json writes newline-delimited JSON events to stdout.
-import ast, collections, contextlib, ctypes, errno, getpass, hashlib, importlib.util, json, os, re, shlex, shutil, struct, subprocess, sys, tempfile, threading, time, types
+import ast, collections, contextlib, ctypes, errno, getpass, pwd, hashlib, importlib.util, json, os, re, shlex, shutil, struct, subprocess, sys, tempfile, threading, time, types
 from pathlib import Path
 sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "dm/tools"))
 import romfs as rfs
@@ -2952,6 +2952,24 @@ def main(args=None):
     if not want_lang: raise BuildError(f'unknown game language {lang_in!r}; give one of {language_list([c for c, _ in nacp.LANGUAGES])}, by code or by name')
     env = dict(os.environ, PATH=os.pathsep.join(TOOL_PATHS + [os.environ.get('PATH', '/usr/bin:/bin:/usr/sbin:/sbin')]))
     env.setdefault('USER', getpass.getuser())   # xcodegen fails without USER (Couldn't find current username)
+    # HOME and DOTNET_CLI_HOME for every child: a GUI launch (LaunchServices) can hand the app a
+    # process environment with HOME missing or empty, and .NET's first-run configure then builds a
+    # mutex path from "" and dies with 'NuGet-Migrations' + lstat("") == ENOENT — before any project
+    # is read (issue #10, where the app's own DOTNET_ROOT workaround did not help because the empty
+    # HOME came from the launch, not from the app). Derive it from the password database when the
+    # environment has nothing usable, so the pipeline is correct however it was started.
+    if not env.get('HOME') or not os.path.isdir(env['HOME']):
+        try: home = Path(pwd.getpwuid(os.getuid()).pw_dir)
+        except Exception: home = Path.home()
+        if home.is_dir():
+            env['HOME'] = os.environ['HOME'] = str(home)
+            say(f'HOME: {home} (taken from the password database; the environment had none)')
+    env.setdefault('DOTNET_CLI_HOME', env['HOME'])   # .NET writes its first-run state here
+    # No first-run banner, no telemetry: a build neither wants nor reads either, and the telemetry
+    # call can hang the first run on a network that cannot reach Microsoft. setdefault, so a user
+    # who wants telemetry on keeps it.
+    env.setdefault('DOTNET_CLI_TELEMETRY_OPTOUT', '1')
+    env.setdefault('DOTNET_NOLOGO', '1')
     configure_dotnet(env)
     env.setdefault('J', str(os.cpu_count() or 8))   # shader_split.py's and dmsh_build.py's workers (their default is 8)
     py = sys.executable