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
The .NET row checks the dotnet the build runs, and wants an SDK 10 from it
Aaron Oliphant2cb46c444468
diff --git a/frontend-qt/nspb_qt/localization.py b/frontend-qt/nspb_qt/localization.pyindex 0406a382..7c967576 100644--- a/frontend-qt/nspb_qt/localization.py+++ b/frontend-qt/nspb_qt/localization.py@@ -722,6 +722,7 @@ TABLE: dict[str, tuple[str, str, str, str]] = {'dep.dotnet': ('.NET SDK 10', '.NET SDK 10', '.NET SDK 10', '.NET SDK 10'),'dep.dotnet.hint': ('dotnet-install.sh 装到 ~/.dotnet', 'dotnet-install.sh into ~/.dotnet', 'dotnet-install.sh till ~/.dotnet', 'dotnet-install.sh nach ~/.dotnet'),'dep.dotnet.missing': ('没找到带 SDK 10 的 dotnet', 'no dotnet with SDK 10 found', 'ingen dotnet med SDK 10 hittades', 'kein dotnet mit SDK 10 gefunden'),+ 'dep.dotnet.shadowed': ('构建会先用 %@,它没有 SDK 10。点「修复」把 %@ 放到它前面', 'the build runs %@, which has no SDK 10. Fix puts %@ in front of it', 'bygget kör %@, som saknar SDK 10. Åtgärda lägger %@ före den', 'der Build nutzt %@, das kein SDK 10 hat. Beheben stellt %@ davor'),'dep.dotnet.downloading': ('正在下载 .NET SDK 10…(约 287 MB,解压后约 900 MB)', 'Downloading .NET SDK 10… (about 287 MB, about 900 MB unpacked)', 'Hämtar .NET SDK 10 … (ungefär 287 MB, ungefär 900 MB uppackat)', '.NET SDK 10 wird geladen … (etwa 287 MB, entpackt etwa 900 MB)'),'dep.dotnet.done': ('.NET SDK 已安装:%@', '.NET SDK installed: %@', '.NET SDK installerat: %@', '.NET SDK installiert: %@'),'dep.phase.download': ('下载', 'Download', 'Hämta', 'Download'),diff --git a/frontend/Sources/NSPortBuilder/ContentView.swift b/frontend/Sources/NSPortBuilder/ContentView.swiftindex fed375d5..d4f5d805 100644--- a/frontend/Sources/NSPortBuilder/ContentView.swift+++ b/frontend/Sources/NSPortBuilder/ContentView.swift@@ -2631,19 +2631,62 @@ final class BuildModel: ObservableObject {return parseDotnetRoot(out)}+ /// Where the build looks for `dotnet`, in its order: build_ipa_from_nsp.py puts TOOL_PATHS (/opt/homebrew/bin,+ /// /usr/local/bin, /usr/local/share/dotnet, ~/.dotnet) in front of PATH, so `dotnet build` runs the first of these+ /// that exists. Checking ~/.dotnet first said .NET was fine on a Mac whose /usr/local/share/dotnet held an Intel+ /// .NET 7, while every build ran that one and stopped at NETSDK1045.+ nonisolated static func dotnetCandidates(home: String = NSHomeDirectory()) -> [String] {+ ["/opt/homebrew/bin/dotnet", "/usr/local/bin/dotnet", "/usr/local/share/dotnet/dotnet", home + "/.dotnet/dotnet"]+ }++ /// Whether `dotnet --list-sdks` names an SDK the extractor builds with (it targets net10.0, so 10 or newer).+ nonisolated static func hasSDK10(_ listSdks: String) -> Bool {+ listSdks.split(separator: "\n").contains { ln in+ Int(ln.prefix { $0.isNumber }).map { $0 >= 10 } ?? false+ }+ }++ nonisolated static func dotnetHasSDK10(_ d: String) -> Bool {+ let p = Process()+ p.executableURL = URL(fileURLWithPath: d)+ p.arguments = ["--list-sdks"]+ p.environment = ["PATH": "/usr/bin:/bin", "HOME": NSHomeDirectory(), "TMPDIR": NSTemporaryDirectory()]+ let pipe = Pipe()+ p.standardOutput = pipe; p.standardError = Pipe(); p.standardInput = FileHandle.nullDevice+ guard (try? p.run()) != nil else { return false }+ let out = String(data: pipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8) ?? ""+ p.waitUntilExit()+ return p.terminationStatus == 0 && hasSDK10(out)+ }++ /// The dotnet the build runs, and whether it has an SDK 10 (an SDK, not just a runtime: the extractor is built).nonisolated static func findDotnet() -> (path: String, ok: Bool) {- let cands = [NSHomeDirectory() + "/.dotnet/dotnet",- "/usr/local/share/dotnet/dotnet",- "/opt/homebrew/bin/dotnet",- "/usr/local/bin/dotnet"]- if let d = firstExisting(cands) {- // the extractor targets net10.0, so an SDK (not just a runtime) is needed- let ok = runOK(d, ["--list-sdks"], env: ["DOTNET_ROOT": (d as NSString).deletingLastPathComponent,- "PATH": "/usr/bin:/bin", "HOME": NSHomeDirectory(),- "TMPDIR": NSTemporaryDirectory()])- return (d, ok)+ guard let d = firstExisting(dotnetCandidates()) else { return ("dotnet", false) }+ return (d, dotnetHasSDK10(d))+ }++ /// The .NET row's action: dotnet-install.sh into ~/.dotnet unless it already has an SDK 10, then, when another+ /// dotnet comes first for the build (`first`), a link to ~/.dotnet's in /usr/local/bin, which the build tries+ /// before /usr/local/share/dotnet.+ nonisolated static func dotnetInstallCommand(first: String?, home: String = NSHomeDirectory()) -> [String] {+ let own = home + "/.dotnet/dotnet"+ var script = "if ! \"$HOME/.dotnet/dotnet\" --list-sdks 2>/dev/null | grep -Eq '^[1-9][0-9]+\\.'; then "+ + "curl -sSL https://dot.net/v1/dotnet-install.sh -o /tmp/di.sh && chmod +x /tmp/di.sh && /tmp/di.sh --channel 10.0 --install-dir $HOME/.dotnet; fi"+ if let first, first != own, first != "/opt/homebrew/bin/dotnet" {+ script += " && mkdir -p /usr/local/bin && ln -sf \"$HOME/.dotnet/dotnet\" /usr/local/bin/dotnet"}- return ("dotnet", false)+ return ["/bin/bash", "-c", script]+ }++ /// The .NET row. `first` is the dotnet the build runs (nil: none), `ok` whether it has an SDK 10, `usable` a dotnet behind it+ /// that has one. Another dotnet ahead of a good one keeps the row from being ready, and Fix puts the good one in front.+ nonisolated static func dotnetDep(first: String?, ok: Bool, usable: String?, home: String = NSHomeDirectory()) -> Dep {+ let shadowed = ok ? nil : first+ var detail = "dep.dotnet.missing", action = ""+ if ok { detail = first ?? "" }+ else if let shadowed, let usable { detail = "dep.dotnet.shadowed:\(shadowed):\(usable)"; action = "dep.xcode.fix" }+ return Dep(id: "dotnet", name: "dep.dotnet", hint: "dep.dotnet.hint", present: ok, detail: detail, actionLabel: action,+ installCmd: dotnetInstallCommand(first: shadowed, home: home))}/// Whether the selected developer directory exists (`xcode-select -p`), which is the same@@ -2810,10 +2853,10 @@ final class BuildModel: ObservableObject {brew: firstExisting(["/opt/homebrew/bin/brew", "/usr/local/bin/brew"]))let (dn, dnOK) = findDotnet()- out.append(Dep(id: "dotnet", name: "dep.dotnet", hint: "dep.dotnet.hint",- present: dnOK, detail: dnOK ? dn : "dep.dotnet.missing",- installCmd: ["/bin/bash", "-c",- "curl -sSL https://dot.net/v1/dotnet-install.sh -o /tmp/di.sh && chmod +x /tmp/di.sh && /tmp/di.sh --channel 10.0 --install-dir $HOME/.dotnet"]))+ let found = FileManager.default.isExecutableFile(atPath: dn)+ // A good dotnet behind the one the build runs+ let usable = found && !dnOK ? dotnetCandidates().drop { $0 != dn }.dropFirst().first { firstExisting([$0]) != nil && dotnetHasSDK10($0) } : nil+ out.append(dotnetDep(first: found ? dn : nil, ok: dnOK, usable: usable))let (py, pyOK) = findPython()// A too-old interpreter is a different problem from a missing package: say which one it is,diff --git a/frontend/Sources/NSPortBuilder/Localization.swift b/frontend/Sources/NSPortBuilder/Localization.swiftindex a18c1436..1467027a 100644--- a/frontend/Sources/NSPortBuilder/Localization.swift+++ b/frontend/Sources/NSPortBuilder/Localization.swift@@ -824,6 +824,7 @@ enum L10n {"dep.dotnet": (".NET SDK 10", ".NET SDK 10"),"dep.dotnet.hint": ("dotnet-install.sh 装到 ~/.dotnet", "dotnet-install.sh into ~/.dotnet"),"dep.dotnet.missing": ("没找到带 SDK 10 的 dotnet", "no dotnet with SDK 10 found"),+ "dep.dotnet.shadowed": ("构建会先用 %@,它没有 SDK 10。点「修复」把 %@ 放到它前面", "the build runs %@, which has no SDK 10. Fix puts %@ in front of it"),"dep.dotnet.downloading": ("正在下载 .NET SDK 10…(约 287 MB,解压后约 900 MB)", "Downloading .NET SDK 10… (about 287 MB, about 900 MB unpacked)"),"dep.dotnet.done": (".NET SDK 已安装:%@", ".NET SDK installed: %@"),"dep.phase.download": ("下载", "Download"),@@ -1659,6 +1660,7 @@ enum L10n {"dep.dotnet": ".NET SDK 10","dep.dotnet.hint": "dotnet-install.sh till ~/.dotnet","dep.dotnet.missing": "ingen dotnet med SDK 10 hittades",+ "dep.dotnet.shadowed": "bygget kör %@, som saknar SDK 10. Åtgärda lägger %@ före den","dep.dotnet.downloading": "Hämtar .NET SDK 10 … (ungefär 287 MB, ungefär 900 MB uppackat)","dep.dotnet.done": ".NET SDK installerat: %@","dep.phase.download": "Hämta",@@ -2584,6 +2586,7 @@ enum L10n {"dep.dotnet": ".NET SDK 10","dep.dotnet.hint": "dotnet-install.sh nach ~/.dotnet","dep.dotnet.missing": "kein dotnet mit SDK 10 gefunden",+ "dep.dotnet.shadowed": "der Build nutzt %@, das kein SDK 10 hat. Beheben stellt %@ davor","dep.dotnet.downloading": ".NET SDK 10 wird geladen … (etwa 287 MB, entpackt etwa 900 MB)","dep.dotnet.done": ".NET SDK installiert: %@","dep.phase.download": "Download",diff --git a/frontend/Tests/NSPortBuilderTests/DotnetDetectionTests.swift b/frontend/Tests/NSPortBuilderTests/DotnetDetectionTests.swiftnew file mode 100644index 00000000..ce13ea73--- /dev/null+++ b/frontend/Tests/NSPortBuilderTests/DotnetDetectionTests.swift@@ -0,0 +1,104 @@+import XCTest+import SwiftUI+@testable import NSPortBuilder++/// The .NET row checks the dotnet the build runs, in the build's own order, and wants an SDK 10 from it.+final class DotnetDetectionTests: XCTestCase {+ func testTheBuildsOrder() {+ // build_ipa_from_nsp.py's TOOL_PATHS: Homebrew, /usr/local/bin, the installer's folder, then ~/.dotnet+ XCTAssertEqual(BuildModel.dotnetCandidates(home: "/Users/p"),+ ["/opt/homebrew/bin/dotnet", "/usr/local/bin/dotnet", "/usr/local/share/dotnet/dotnet", "/Users/p/.dotnet/dotnet"])+ }++ func testOnlyAnSDK10Counts() {+ XCTAssertFalse(BuildModel.hasSDK10("7.0.402 [/usr/local/share/dotnet/sdk]\n")) // an Intel .NET 7 in front of ~/.dotnet+ XCTAssertFalse(BuildModel.hasSDK10(""))+ XCTAssertFalse(BuildModel.hasSDK10("8.0.318 [/x/sdk]\n9.0.100 [/x/sdk]"))+ XCTAssertTrue(BuildModel.hasSDK10("7.0.402 [/a/sdk]\n10.0.403 [/b/sdk]\n"))+ XCTAssertTrue(BuildModel.hasSDK10("11.0.100-preview.1 [/b/sdk]"))+ }++ func testFixLinksOnlyWhenAnotherDotnetComesFirst() {+ let plain = BuildModel.dotnetInstallCommand(first: nil, home: "/Users/p").last!+ XCTAssertTrue(plain.contains("--install-dir $HOME/.dotnet"))+ XCTAssertFalse(plain.contains("ln -sf"))+ let own = BuildModel.dotnetInstallCommand(first: "/Users/p/.dotnet/dotnet", home: "/Users/p").last!+ XCTAssertFalse(own.contains("ln -sf"))+ let shadowed = BuildModel.dotnetInstallCommand(first: "/usr/local/share/dotnet/dotnet", home: "/Users/p").last!+ XCTAssertTrue(shadowed.hasSuffix("ln -sf \"$HOME/.dotnet/dotnet\" /usr/local/bin/dotnet"))+ // a link in /usr/local/bin cannot get ahead of Homebrew's own+ XCTAssertFalse(BuildModel.dotnetInstallCommand(first: "/opt/homebrew/bin/dotnet", home: "/Users/p").last!.contains("ln -sf"))+ }++ func testTheRow() {+ let shadowed = BuildModel.dotnetDep(first: "/usr/local/share/dotnet/dotnet", ok: false, usable: "/Users/p/.dotnet/dotnet", home: "/Users/p")+ XCTAssertFalse(shadowed.present)+ XCTAssertEqual(shadowed.detail, "dep.dotnet.shadowed:/usr/local/share/dotnet/dotnet:/Users/p/.dotnet/dotnet")+ XCTAssertEqual(shadowed.actionLabel, "dep.xcode.fix")+ XCTAssertTrue(shadowed.installCmd.last!.contains("ln -sf"))++ let ready = BuildModel.dotnetDep(first: "/usr/local/bin/dotnet", ok: true, usable: nil, home: "/Users/p")+ XCTAssertTrue(ready.present)+ XCTAssertEqual(ready.detail, "/usr/local/bin/dotnet")++ let none = BuildModel.dotnetDep(first: nil, ok: false, usable: nil, home: "/Users/p")+ XCTAssertEqual(none.detail, "dep.dotnet.missing")+ XCTAssertEqual(none.actionLabel, "")+ XCTAssertFalse(none.installCmd.last!.contains("ln -sf"))++ // an old SDK in front and none anywhere else: Install brings .NET 10 into ~/.dotnet and puts it in front+ let old = BuildModel.dotnetDep(first: "/usr/local/share/dotnet/dotnet", ok: false, usable: nil, home: "/Users/p")+ XCTAssertEqual(old.detail, "dep.dotnet.missing")+ XCTAssertEqual(old.actionLabel, "")+ XCTAssertTrue(old.installCmd.last!.contains("ln -sf"))+ }++ @MainActor func testTheShadowedRowNamesBothPaths() {+ let model = BuildModel()+ model.lang = .en+ XCTAssertEqual(model.depDetail(BuildModel.dotnetDep(first: "/usr/local/share/dotnet/dotnet", ok: false, usable: "/opt/x/dotnet")),+ "the build runs /usr/local/share/dotnet/dotnet, which has no SDK 10. Fix puts /opt/x/dotnet in front of it")+ }++ /// Opt-in native rendering for pull request screenshots (NX_LAUNCHER_CAPTURE_DIR): Settings with the .NET row of a Mac whose+ /// /usr/local/share/dotnet holds an older .NET in front of the .NET 10 in ~/.dotnet, and the same row once Fix has run.+ @MainActor func testRenderTheDotnetRowForVisualQA() throws {+ guard let directory = ProcessInfo.processInfo.environment["NX_LAUNCHER_CAPTURE_DIR"] else { throw XCTSkip("Set NX_LAUNCHER_CAPTURE_DIR to capture native views") }+ let output = URL(fileURLWithPath: directory)+ let temporary = FileManager.default.temporaryDirectory.appendingPathComponent("dotnet-capture-\(UUID().uuidString)")+ try FileManager.default.createDirectory(at: output, withIntermediateDirectories: true)+ try FileManager.default.createDirectory(at: temporary, withIntermediateDirectories: true)+ defer { try? FileManager.default.removeItem(at: temporary) }+ NSApplication.shared.setActivationPolicy(.accessory)+ let oldRepo = UserDefaults.standard.object(forKey: "repoPath"), oldExpanded = UserDefaults.standard.object(forKey: "depsExpanded")+ defer {+ UserDefaults.standard.set(oldRepo, forKey: "repoPath")+ UserDefaults.standard.set(oldExpanded, forKey: "depsExpanded")+ }+ let model = BuildModel()+ model.repoPath = URL(fileURLWithPath: #filePath).deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent().path+ model.lang = CaptureLanguage.current(.en)+ model.depsChecked = true+ model.depsExpanded = true+ let rows = [BuildModel.Dep(id: "xcode", name: "dep.xcode", hint: "dep.xcode.hint", present: true, installCmd: []),+ BuildModel.Dep(id: "metal", name: "dep.metal", hint: "dep.metal.hint", present: true, installCmd: [])]+ let python = BuildModel.Dep(id: "python", name: "dep.python", hint: "dep.python.hint", present: true, detail: "dep.bundled", installCmd: [])+ let library = GameLibrary(file: temporary.appendingPathComponent("library.json"))+ for (name, dotnet) in [("dotnet-shadowed", BuildModel.dotnetDep(first: "/usr/local/share/dotnet/dotnet", ok: false, usable: NSHomeDirectory() + "/.dotnet/dotnet")),+ ("dotnet-fixed", BuildModel.dotnetDep(first: "/usr/local/bin/dotnet", ok: true, usable: nil))] {+ model.deps = rows + [dotnet, python]+ let host = NSHostingView(rootView: ContentView(model: model, library: library, initialPage: .settings, performStartupChecks: false))+ let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 1440, height: 1400), styleMask: [.titled, .closable, .resizable],+ backing: .buffered, defer: false)+ window.contentView = host+ window.orderFront(nil)+ RunLoop.main.run(until: Date().addingTimeInterval(0.5))+ host.layoutSubtreeIfNeeded()+ let rep = try XCTUnwrap(host.bitmapImageRepForCachingDisplay(in: host.bounds))+ host.cacheDisplay(in: host.bounds, to: rep)+ try XCTUnwrap(rep.representation(using: .png, properties: [:]))+ .write(to: output.appendingPathComponent("\(name)-\(model.lang.rawValue).png"))+ window.orderOut(nil)+ }+ }+}