Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.
Swift apple-siliconcustom-formathomebrewiosipaipadipadosiphonemetalnative-portnintendo-switchnxnativeromfsswitch-games
Dependencies: a failed install names its reason and the command that fixes it
LNPANDYb46a5d30bbd4
diff --git a/frontend/Sources/NSPortBuilder/ContentView.swift b/frontend/Sources/NSPortBuilder/ContentView.swiftindex 2b7a33e8..181d8eaa 100644--- a/frontend/Sources/NSPortBuilder/ContentView.swift+++ b/frontend/Sources/NSPortBuilder/ContentView.swift@@ -1835,6 +1835,8 @@ final class BuildModel: ObservableObject {var present: Boolvar installing = falsevar detail = ""+ var lastError = "" // the tool's own first error line after a failed install (brew's, pip's)+ var fixHint = "" // an L10n key: what to type or click, chosen from that linelet installCmd: [String] // run via bash; empty = manual (Xcode from the App Store)}@@ -2167,20 +2169,68 @@ final class BuildModel: ObservableObject {DispatchQueue.main.async { self.append("\n--- 安装输出 ---\n" + r.log) }ok = r.ok} else {+ let collected = LineBox()ok = Self.runCaptured(["/bin/bash", "-c",cmd.map { $0.contains(" ") ? "'" + $0 + "'" : $0 }.joined(separator: " ")],env: ["PATH": "/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin","HOME": NSHomeDirectory(), "NONINTERACTIVE": "1", "USER": NSUserName()])- { line in DispatchQueue.main.async { self.append(line + "\n") } }+ { line in+ collected.append(line)+ DispatchQueue.main.async { self.append(line + "\n") }+ }+ let (error, fix) = Self.failureInfo(collected.lines)+ DispatchQueue.main.async {+ if let j = self.deps.firstIndex(where: { $0.id == dep.id }) {+ self.deps[j].lastError = ok ? "" : error+ self.deps[j].fixHint = ok ? "" : fix+ }+ }}DispatchQueue.main.async {if let j = self.deps.firstIndex(where: { $0.id == dep.id }) { self.deps[j].installing = false }+ if ok, let j = self.deps.firstIndex(where: { $0.id == dep.id }) { self.deps[j].lastError = ""; self.deps[j].fixHint = "" }if !ok { self.doneNote = String(format: self.t("dep.install.fail"), self.t(dep.name)) }self.checkDeps()}}}+ /// The line a failed install should show, and the fix to offer beside it.+ ///+ /// A GUI user sees a spinner turn back into a button; the reason (brew refusing a directory it+ /// does not own is the common one) lived only in the log. Prefer the tool's own `Error:` line,+ /// and map the few causes we can name to the exact command.+ nonisolated static func failureInfo(_ lines: [String]) -> (error: String, fix: String) {+ let meaningful = lines.map { $0.trimmingCharacters(in: .whitespaces) }.filter { !$0.isEmpty }+ let error = meaningful.first { $0.hasPrefix("Error:") }+ ?? meaningful.first { $0.lowercased().contains("error") }+ ?? meaningful.last ?? ""+ let lower = lines.joined(separator: "\n").lowercased()+ let fix: String+ if lower.contains("/opt/homebrew is not writable") || lower.contains("permission denied @ dir_initialize")+ || lower.contains("/usr/local is not writable") {+ fix = "dep.fix.brewOwner"+ } else if lower.contains("command not found") || lower.contains("brew: not found") {+ fix = "dep.fix.brewMissing"+ } else if lower.contains("agreeing to the xcode license") || lower.contains("xcode license") {+ fix = "dep.fix.xcodeLicense"+ } else if lower.contains("could not resolve host") || lower.contains("failed to download")+ || lower.contains("operation timed out") {+ fix = "dep.fix.network"+ } else {+ fix = "dep.fix.log"+ }+ return (error, fix)+ }++ /// The output lines seen so far, from the pipe's threads and read on the main queue.+ final class LineBox: @unchecked Sendable {+ private let lock = NSLock()+ private var box: [String] = []+ func append(_ l: String) { lock.lock(); box.append(l); lock.unlock() }+ var lines: [String] { lock.lock(); defer { lock.unlock() }; return box }+ }+/// Run a command, streaming its output line by line to `line`. Returns success.nonisolated static func runCaptured(_ args: [String], env: [String: String], line: @escaping (String) -> Void) -> Bool {let p = Process()@@ -2806,13 +2856,29 @@ struct BuilderView: View {if m.depsOpen {ForEach(m.deps, id: \.id) { d individer- row(m.t(d.name), detail: m.shortPath(m.depDetail(d)), dot: d.present ? LauncherPalette.ready : LauncherPalette.building,- help: m.t(d.hint)) {- if d.installing {- ProgressView().controlSize(.small)- Text(m.t("dep.installing")).font(.manrope(12)).foregroundStyle(LauncherPalette.building)- } else if !d.present {- Button(d.installCmd.isEmpty ? m.t("dep.openAppStore") : m.t("dep.install")) { m.installDep(d) }+ VStack(alignment: .leading, spacing: 0) {+ row(m.t(d.name), detail: m.shortPath(m.depDetail(d)), dot: d.present ? LauncherPalette.ready : LauncherPalette.building,+ help: m.t(d.hint)) {+ if d.installing {+ ProgressView().controlSize(.small)+ Text(m.t("dep.installing")).font(.manrope(12)).foregroundStyle(LauncherPalette.building)+ } else if !d.present {+ Button(d.installCmd.isEmpty ? m.t("dep.openAppStore") : m.t("dep.install")) { m.installDep(d) }+ }+ }+ // Why the last install failed, and what to do about it: the tool's own+ // error line under the row, the fix (a command or a place to look) below it.+ if !d.lastError.isEmpty {+ VStack(alignment: .leading, spacing: 3) {+ Text(d.lastError).font(.mono(11)).foregroundStyle(LauncherPalette.building)+ .lineLimit(3).help(d.lastError)+ if !d.fixHint.isEmpty {+ Text(m.t(d.fixHint)).font(.manrope(11.5)).foregroundStyle(.secondary)+ .fixedSize(horizontal: false, vertical: true)+ }+ }+ .padding(.leading, 37).padding(.trailing, 18).padding(.bottom, 11)+ .frame(maxWidth: .infinity, alignment: .leading)}}}diff --git a/frontend/Sources/NSPortBuilder/Localization.swift b/frontend/Sources/NSPortBuilder/Localization.swiftindex ff95392a..b3ede95b 100644--- a/frontend/Sources/NSPortBuilder/Localization.swift+++ b/frontend/Sources/NSPortBuilder/Localization.swift@@ -473,6 +473,16 @@ enum L10n {"dep.phase.unpack": ("解压", "Unpack"),"dep.python": ("Python + 包", "Python + packages"),"dep.python.hint": ("lz4 capstone fonttools backports.zstd", "lz4 capstone fonttools backports.zstd"),+ "dep.fix.brewOwner": ("Homebrew 的目录属于其他用户,安装写不进去:在终端运行 sudo chown -R $(whoami) /opt/homebrew,然后重新安装。",+ "Homebrew's folder belongs to another user, so nothing can be installed: run sudo chown -R $(whoami) /opt/homebrew in Terminal, then install again."),+ "dep.fix.brewMissing": ("没装 Homebrew:从 brew.sh 安装(安装程序会要你的密码),再点「重新检测」。",+ "Homebrew is not installed: install it from brew.sh (the installer asks for your password), then press Check again."),+ "dep.fix.xcodeLicense": ("Xcode 的许可协议还没接受:运行 sudo xcodebuild -license accept。",+ "Xcode's license is not accepted yet: run sudo xcodebuild -license accept."),+ "dep.fix.network": ("下载失败了:检查网络(代理或 VPN 可能拦住了 Homebrew 的域名),再试一次。",+ "The download failed: check the network (a proxy or VPN can block Homebrew's hosts) and try again."),+ "dep.fix.log": ("完整输出在 Mac/iPhone 选择下面的日志里。",+ "The full output is in the log under the Mac/iPhone choice."),"dep.python.missing": ("%@ 缺包", "%@ is missing packages"),"dep.install.begin": ("开始安装 %@…", "Installing %@…"),"dep.install.fail": ("安装失败:%@(详情见日志)", "Install failed: %@ (see the log)"),diff --git a/frontend/Tests/NSPortBuilderTests/DependencyFailureTests.swift b/frontend/Tests/NSPortBuilderTests/DependencyFailureTests.swiftnew file mode 100644index 00000000..ea982698--- /dev/null+++ b/frontend/Tests/NSPortBuilderTests/DependencyFailureTests.swift@@ -0,0 +1,44 @@+import XCTest+@testable import NSPortBuilder++/// A failed dependency install must say why and what to type — the report that motivated this+/// showed a spinner turning back into a button with the reason buried in the log.+final class DependencyFailureTests: XCTestCase {+ func testABrewPermissionProblemNamesTheChownCommand() {+ let (error, fix) = BuildModel.failureInfo([+ "Error: ", "/opt/homebrew is not writable. You should change the",+ "ownership and permissions of /opt/homebrew back to your",+ "user account:", " sudo chown -R junli /opt/homebrew",+ "Error: Permission denied @ dir_initialize - /opt/homebrew/Library/Taps"])+ XCTAssertTrue(error.hasPrefix("Error:"))+ XCTAssertEqual(fix, "dep.fix.brewOwner")+ }++ func testAMissingBrewSaysWhereToInstallIt() {+ XCTAssertEqual(BuildModel.failureInfo(["/bin/bash: line 1: brew: command not found"]).fix, "dep.fix.brewMissing")+ }++ func testTheXcodeLicenseIsNamed() {+ XCTAssertEqual(BuildModel.failureInfo(["Error: You have not agreed to the Xcode license."]).fix, "dep.fix.xcodeLicense")+ }++ func testANetworkFailureIsNamed() {+ XCTAssertEqual(BuildModel.failureInfo(["curl: (6) Could not resolve host: github.com"]).fix, "dep.fix.network")+ }++ func testAnUnknownFailurePointsAtTheLog() {+ let (error, fix) = BuildModel.failureInfo(["something odd happened", "still odd"])+ XCTAssertEqual(fix, "dep.fix.log")+ XCTAssertFalse(error.isEmpty)+ }++ func testEveryFixHintHasBothLanguages() {+ for key in ["dep.fix.brewOwner", "dep.fix.brewMissing", "dep.fix.xcodeLicense", "dep.fix.network", "dep.fix.log"] {+ let row = L10n.table[key]+ XCTAssertNotNil(row, key)+ XCTAssertFalse(row?.0.isEmpty ?? true, key)+ XCTAssertFalse(row?.1.isEmpty ?? true, key)+ XCTAssertNotEqual(row?.0, row?.1, "\(key) has the English text twice")+ }+ }+}