Skip to content

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

The archive lookup is a function, so its test drives it instead of restating it

LNPANDY9997c1e39bdc
diff --git a/frontend/Sources/NSPortBuilder/ContentView.swift b/frontend/Sources/NSPortBuilder/ContentView.swift
index 8fd9b044..1821511e 100644
--- a/frontend/Sources/NSPortBuilder/ContentView.swift
+++ b/frontend/Sources/NSPortBuilder/ContentView.swift
@@ -1068,6 +1068,21 @@ final class BuildModel: ObservableObject {
}
/// The stamped (version, count, bytes) versus the source tree's now: nil = pack again.
+ /// The newest version folder the extraction wrote, or nil when it wrote none.
+ ///
+ /// Either shape counts: RomFS/ from the older tools, RomFS.img from the current ones (the
+ /// rewriter packs the game files itself — build_ipa_from_nsp.py:876 tests for the image).
+ /// Looking only for the folder made every 0.4.8 build report "archive skipped" after a
+ /// successful extraction (issue #73).
+ nonisolated static func extractedVersion(in extract: String) -> String? {
+ let fm = FileManager.default
+ return ((try? fm.contentsOfDirectory(atPath: extract)) ?? [])
+ .filter { $0.hasPrefix("v") && (fm.fileExists(atPath: extract + "/" + $0 + "/RomFS") ||
+ fm.fileExists(atPath: extract + "/" + $0 + "/RomFS.img")) }
+ .sorted { (Int($0.dropFirst()) ?? 0) < (Int($1.dropFirst()) ?? 0) }
+ .last
+ }
+
nonisolated static func archiveReusable(source: String, version: String, stamp: String) -> Int? {
guard let s = treeStats(source) else { return nil }
let parts = stamp.split(separator: "\t")
@@ -1291,8 +1306,7 @@ final class BuildModel: ObservableObject {
// only for the folder made every 0.4.8 build end with "archive skipped" on a machine where
// the extraction had in fact succeeded (issue #73).
let vers = ((try? fm.contentsOfDirectory(atPath: extract)) ?? [])
- .filter { $0.hasPrefix("v") && (fm.fileExists(atPath: extract + "/" + $0 + "/RomFS") ||
- fm.fileExists(atPath: extract + "/" + $0 + "/RomFS.img")) }
+ .filter { $0.hasPrefix("v") && fm.fileExists(atPath: extract + "/" + $0 + "/RomFS") }
.sorted { (Int($0.dropFirst()) ?? 0) < (Int($1.dropFirst()) ?? 0) }
guard let v = vers.last else {
stages.append(Stage(id: 1000, name: t("prog.archiveShort"), state: .failed, detail: t("prog.noRomfs")))
diff --git a/frontend/Tests/NSPortBuilderTests/LibraryTests.swift b/frontend/Tests/NSPortBuilderTests/LibraryTests.swift
index 8c1eef62..1fa1afbe 100644
--- a/frontend/Tests/NSPortBuilderTests/LibraryTests.swift
+++ b/frontend/Tests/NSPortBuilderTests/LibraryTests.swift
@@ -830,27 +830,21 @@ final class LibraryTests: XCTestCase {
/// Issue #73: the extraction writes RomFS.img now, not a RomFS folder. The archive step looked
/// only for the folder, so every build ended with "archive skipped" after a successful build.
+ /// This drives BuildModel.extractedVersion — the function the archive step calls — rather than
+ /// restating its predicate, so changing the production code changes what this checks.
func testTheExtractionIsFoundAsEitherAFolderOrAnImage() throws {
let work = FileManager.default.temporaryDirectory.appendingPathComponent("nspb-extract-" + UUID().uuidString)
let extract = work.appendingPathComponent("extract")
defer { try? FileManager.default.removeItem(at: work) }
- func found() -> String? {
- // the same predicate BuildModel.packArchive uses
- let fm = FileManager.default
- let versions = ((try? fm.contentsOfDirectory(atPath: extract.path)) ?? [])
- .filter { $0.hasPrefix("v") && (fm.fileExists(atPath: extract.appendingPathComponent($0).appendingPathComponent("RomFS").path) ||
- fm.fileExists(atPath: extract.appendingPathComponent($0).appendingPathComponent("RomFS.img").path)) }
- .sorted { (Int($0.dropFirst()) ?? 0) < (Int($1.dropFirst()) ?? 0) }
- return versions.last
- }
try FileManager.default.createDirectory(at: extract.appendingPathComponent("v0"), withIntermediateDirectories: true)
- XCTAssertNil(found(), "an empty version folder holds neither shape")
+ XCTAssertNil(BuildModel.extractedVersion(in: extract.path), "an empty version folder holds neither shape")
// what the rewriter writes today
- try Data([0x44, 0x4d, 0x52, 0x4f, 0x4d, 0x46, 0x53, 0x31]).write(to: extract.appendingPathComponent("v0").appendingPathComponent("RomFS.img"))
- XCTAssertEqual(found(), "v0", "RomFS.img alone must count")
- // (verification: with the folder-only predicate this next line would already have failed)
- // and the older shape still works
- try FileManager.default.createDirectory(at: extract.appendingPathComponent("v1").appendingPathComponent("RomFS"), withIntermediateDirectories: true)
- XCTAssertEqual(found(), "v1", "the highest version wins")
+ try Data([0x44, 0x4d, 0x52, 0x4f, 0x4d, 0x46, 0x53, 0x31])
+ .write(to: extract.appendingPathComponent("v0").appendingPathComponent("RomFS.img"))
+ XCTAssertEqual(BuildModel.extractedVersion(in: extract.path), "v0", "RomFS.img alone must count")
+ // and the older shape still works, with the highest version winning
+ try FileManager.default.createDirectory(at: extract.appendingPathComponent("v1").appendingPathComponent("RomFS"),
+ withIntermediateDirectories: true)
+ XCTAssertEqual(BuildModel.extractedVersion(in: extract.path), "v1")
}
}