Skip to content

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

Explain the final shader split batch in build progress

thehobbit8531abb7f3cb57
diff --git a/frontend/Sources/NX2Apple/LauncherView.swift b/frontend/Sources/NX2Apple/LauncherView.swift
index b519f9d5..dcafc354 100644
--- a/frontend/Sources/NX2Apple/LauncherView.swift
+++ b/frontend/Sources/NX2Apple/LauncherView.swift
@@ -406,16 +406,20 @@ struct LauncherView: View {
Divider().opacity(0.3)
HStack(spacing: 22) {
if m.running {
+ let stage = m.stages.last { $0.state == .running }
Image(systemName: "wrench.and.screwdriver").font(.system(size: 22, weight: .light)).foregroundStyle(.secondary)
VStack(alignment: .leading, spacing: 4) {
Text(loc.t(devices.shellCopy != nil || devices.shellWaiting || m.stages.contains { $0.id == 1003 && $0.state == .running }
? "activity.transfer" : (m.target == BuildTarget.mac ? "activity.mac" : "activity.ios"))).font(.manrope(15, .bold))
TimelineView(.periodic(from: Date(), by: 1)) { context in // the clock ticks while a count may stand still
- Text(m.stages.last(where: { $0.state == .running })
+ Text(stage
.map { [$0.name, $0.detail, $0.clock(at: context.date, left: loc.t("prog.eta"))].filter { !$0.isEmpty }.joined(separator: " · ") }
?? loc.t("library.preparing"))
.font(.manrope(13)).monospacedDigit().foregroundStyle(.secondary).lineLimit(1).truncationMode(.middle)
}
+ if stage?.isScanningLastShaderFiles == true {
+ Text(loc.t("prog.lastShaderFiles")).font(.manrope(13)).fixedSize(horizontal: false, vertical: true)
+ }
}
.frame(minWidth: 180, alignment: .leading)
LauncherProgressBar(value: buildProgress).frame(maxWidth: 480)
@@ -456,7 +460,7 @@ struct LauncherView: View {
}
}
}
- .padding(.horizontal, 30).frame(height: 84)
+ .padding(.horizontal, 30).frame(minHeight: 84)
}
}
diff --git a/frontend/Sources/NXCore/BuildProgress.swift b/frontend/Sources/NXCore/BuildProgress.swift
index 483ed825..2bd3af9a 100644
--- a/frontend/Sources/NXCore/BuildProgress.swift
+++ b/frontend/Sources/NXCore/BuildProgress.swift
@@ -5,6 +5,7 @@ package struct Stage: Identifiable {
package var name: String
package var state: StepState = .running
package var detail: String = ""
+ package var isScanningLastShaderFiles = false
package var percent: Double? = nil
package var started: Date? = nil // when the stage began here: its clock runs while the count may stand still
package var eta: Double? = nil // the script's estimate of the seconds left, as of etaAt
@@ -75,6 +76,15 @@ package enum BuildProgress {
return nil
}
+ /// shader_split.py reports completed batches of up to 16 files. Its fraction is capped at 99% even when all files are done.
+ package static func isScanningLastShaderFiles(_ event: [String: Any]) -> Bool {
+ guard event["name"] as? String == "shader split", event["step"] as? String == "splitting",
+ event["unit"] as? String == "files", event["est"] as? Bool != true,
+ let done = event["done"] as? Int, let total = event["total"] as? Int,
+ done > 0, total > done else { return false }
+ return total - done <= 16
+ }
+
/// "splitting · 1.2 / 3.4 GB", "1,203 / 19,592 shaders", "2,301 files": the step and the count (the time left is the Stage's clock).
package static func progressDetail(_ e: [String: Any]) -> String {
let step = e["step"] as? String ?? "", unit = e["unit"] as? String ?? "", note = e["note"] as? String ?? ""
diff --git a/frontend/Sources/NXModel/BuildStore.swift b/frontend/Sources/NXModel/BuildStore.swift
index 4ba29fdc..b9a3a562 100644
--- a/frontend/Sources/NXModel/BuildStore.swift
+++ b/frontend/Sources/NXModel/BuildStore.swift
@@ -335,21 +335,46 @@ func hop(_ body: @escaping @MainActor () -> Void) {
let name = e["name"] as? String ?? "", step = e["step"] as? String ?? ""
let n = (e["n"] as? NSNumber)?.intValue ?? 0
append("[\(k)/\(n)] \(name)" + (step.isEmpty ? "" : " · \(step)") + " …\n")
- stage { $0.name = Stage.localizedName(name, t); $0.state = .running; $0.detail = step; $0.percent = nil; $0.started = Date(); $0.eta = nil }
+ stage {
+ $0.name = Stage.localizedName(name, t)
+ $0.state = .running
+ $0.started = Date()
+ $0.detail = step
+ $0.percent = nil
+ $0.eta = nil
+ $0.isScanningLastShaderFiles = false
+ }
case "step":
let step = e["step"] as? String ?? ""
append(" · \(step)\n")
- stage { $0.detail = step; $0.percent = nil; $0.eta = nil }
+ stage {
+ $0.detail = step
+ $0.percent = nil
+ $0.eta = nil
+ $0.isScanningLastShaderFiles = false
+ }
case "progress":
let fraction = (e["frac"] as? NSNumber)?.doubleValue
let detail = BuildProgress.progressDetail(e)
let eta = (e["eta"] as? NSNumber)?.doubleValue
- stage { $0.percent = fraction.map { $0 * 100 }; $0.detail = detail; $0.eta = eta; $0.etaAt = eta == nil ? nil : Date() }
+ stage {
+ $0.percent = fraction.map { $0 * 100 }
+ $0.detail = detail
+ $0.eta = eta
+ $0.etaAt = eta == nil ? nil : Date()
+ $0.isScanningLastShaderFiles = BuildProgress.isScanningLastShaderFiles(e)
+ }
case "stage_end":
let ok = e["ok"] as? Bool ?? true, summary = e["summary"] as? String ?? ""
let elapsed = BuildProgress.duration((e["elapsed"] as? NSNumber)?.doubleValue ?? 0)
append("\(ok ? "✓" : "✗") \(e["name"] as? String ?? "") (\(elapsed))" + (summary.isEmpty ? "" : ": \(summary)") + "\n")
- stage { $0.state = ok ? .done : .failed; $0.detail = summary; $0.percent = ok ? 100 : $0.percent; $0.eta = nil }
+ stage {
+ $0.state = ok ? .done : .failed
+ $0.detail = summary
+ $0.percent = ok ? 100 : $0.percent
+ $0.eta = nil
+ $0.isScanningLastShaderFiles = false
+ }
case "say":
let msg = e["msg"] as? String ?? ""
append(msg + "\n")
diff --git a/frontend/Tests/NXModelTests/BuildStoreTests.swift b/frontend/Tests/NXModelTests/BuildStoreTests.swift
index 84c0e21f..a11976b0 100644
--- a/frontend/Tests/NXModelTests/BuildStoreTests.swift
+++ b/frontend/Tests/NXModelTests/BuildStoreTests.swift
@@ -217,6 +217,40 @@ import XCTest
// MARK: The script's events
+ func testLastShaderFileHintFollowsTheReportedBatch() {
+ let store = makeStore()
+ func progress(_ done: Int, _ total: Int, name: String = "shader split", step: String = "splitting",
+ unit: String = "files", estimated: Bool = false) {
+ store.handleEvent("progress", ["k": 2, "name": name, "step": step, "unit": unit,
+ "done": done, "total": total, "est": estimated, "frac": 0.99])
+ }
+
+ progress(304_227, 304_243)
+ XCTAssertTrue(store.stages[0].isScanningLastShaderFiles)
+ XCTAssertEqual(store.stages[0].percent, 99)
+ XCTAssertEqual(store.stages[0].detail, BuildProgress.progressDetail(["step": "splitting", "unit": "files",
+ "done": 304_227, "total": 304_243]))
+ progress(48_145, 48_146)
+ XCTAssertTrue(store.stages[0].isScanningLastShaderFiles)
+ store.handleEvent("step", ["k": 2, "name": "shader split", "step": "checking the outputs"])
+ XCTAssertFalse(store.stages[0].isScanningLastShaderFiles)
+ for done in [0, 48_129, 48_146] {
+ progress(done, 48_146)
+ XCTAssertFalse(store.stages[0].isScanningLastShaderFiles)
+ }
+ progress(48_130, 48_146, name: "extract")
+ XCTAssertFalse(store.stages[0].isScanningLastShaderFiles)
+ progress(48_130, 48_146, step: "checking the inputs")
+ XCTAssertFalse(store.stages[0].isScanningLastShaderFiles)
+ progress(48_130, 48_146, unit: "B")
+ XCTAssertFalse(store.stages[0].isScanningLastShaderFiles)
+ progress(48_130, 48_146, estimated: true)
+ XCTAssertFalse(store.stages[0].isScanningLastShaderFiles)
+ progress(48_130, 48_146)
+ store.handleEvent("stage_end", ["k": 2, "name": "shader split", "ok": false])
+ XCTAssertFalse(store.stages[0].isScanningLastShaderFiles)
+ }
+
func testTheScriptsJSONEventsBecomeStagesAndLogLines() {
let store = makeStore()
store.ingest("{\"ev\":\"stage\",\"k\":1,\"n\":3,\"name\":\"extract\",\"step\":\"keys\"}\n")
diff --git a/frontend/l10n/de.json b/frontend/l10n/de.json
index a5125567..74c155ef 100644
--- a/frontend/l10n/de.json
+++ b/frontend/l10n/de.json
@@ -1219,6 +1219,7 @@
"prog.archiveReused": "vorheriges Image wiederverwendet (%d Dateien unverändert)",
"prog.archiveShort": "Spieldaten-Image",
"prog.eta": "Noch %@",
+ "prog.lastShaderFiles": "Das Durchsuchen der letzten Dateien kann mehrere Minuten dauern.",
"prog.noRomfs": "kein entpacktes RomFS gefunden",
"prog.title": "Build-Fortschritt",
"repo.adopt": "Updatefähig machen",
diff --git a/frontend/l10n/en.json b/frontend/l10n/en.json
index 3725aaed..bc975b75 100644
--- a/frontend/l10n/en.json
+++ b/frontend/l10n/en.json
@@ -1237,6 +1237,7 @@
"prog.archiveReused": "reused the previous image (%d files unchanged)",
"prog.archiveShort": "Game data image",
"prog.eta": "%@ left",
+ "prog.lastShaderFiles": "Scanning the last few files can take several minutes.",
"prog.noRomfs": "no extracted RomFS found",
"prog.title": "Build progress",
"repo.adopt": "Make updatable",
diff --git a/frontend/l10n/fr.json b/frontend/l10n/fr.json
index b93c3393..49739a99 100644
--- a/frontend/l10n/fr.json
+++ b/frontend/l10n/fr.json
@@ -1196,6 +1196,7 @@
"prog.archiveReused": "image précédente réutilisée (%d fichiers inchangés)",
"prog.archiveShort": "Image des données du jeu",
"prog.eta": "%@ restant",
+ "prog.lastShaderFiles": "L’analyse des derniers fichiers peut prendre plusieurs minutes.",
"prog.noRomfs": "aucun RomFS extrait trouvé",
"prog.title": "Progression de la compilation",
"repo.adopt": "Rendre actualisable",
diff --git a/frontend/l10n/it.json b/frontend/l10n/it.json
index 0b64525a..ddf731a5 100644
--- a/frontend/l10n/it.json
+++ b/frontend/l10n/it.json
@@ -1203,6 +1203,7 @@
"prog.archiveReused": "riutilizzata l’immagine precedente (%d file invariati)",
"prog.archiveShort": "Immagine dei dati di gioco",
"prog.eta": "%@ rimanenti",
+ "prog.lastShaderFiles": "La scansione degli ultimi file può richiedere diversi minuti.",
"prog.noRomfs": "nessuna RomFS estratta trovata",
"prog.title": "Avanzamento della build",
"repo.adopt": "Rendi aggiornabile",
diff --git a/frontend/l10n/sv.json b/frontend/l10n/sv.json
index 871e4c74..2d6ac146 100644
--- a/frontend/l10n/sv.json
+++ b/frontend/l10n/sv.json
@@ -1040,6 +1040,7 @@
"prog.archiveReused": "återanvände föregående avbildning (%d filer oförändrade)",
"prog.archiveShort": "Speldataavbildning",
"prog.eta": "%@ kvar",
+ "prog.lastShaderFiles": "Det kan ta flera minuter att läsa igenom de sista filerna.",
"prog.noRomfs": "ingen extraherad RomFS hittades",
"prog.title": "Byggförlopp",
"repo.adopt": "Gör uppdateringsbart",
diff --git a/frontend/l10n/zh.json b/frontend/l10n/zh.json
index 0811947f..4eb9c126 100644
--- a/frontend/l10n/zh.json
+++ b/frontend/l10n/zh.json
@@ -1238,6 +1238,7 @@
"prog.archiveReused": "复用上次的镜像(%d 个文件未变)",
"prog.archiveShort": "游戏数据镜像",
"prog.eta": "还剩 %@",
+ "prog.lastShaderFiles": "扫描最后几个文件可能需要几分钟。",
"prog.noRomfs": "找不到解出的 RomFS",
"prog.title": "构建进度",
"repo.adopt": "设为可更新",