Skip to content

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

Stop a build whose folder is in iCloud Drive and explain why

v0lumehi5cd0df0e80bd
diff --git a/frontend-qt/nspb_qt/build_failure.py b/frontend-qt/nspb_qt/build_failure.py
index bcbe1bc3..be8e0a77 100644
--- a/frontend-qt/nspb_qt/build_failure.py
+++ b/frontend-qt/nspb_qt/build_failure.py
@@ -26,6 +26,7 @@ KEYS = 'keys'
SEVERAL_GAMES = 'severalGames'
NO_TITLE_ID = 'noTitleID'
DISK_FULL = 'diskFull'
+CLOUD_FOLDER = 'cloudFolder'
UNKNOWN = 'unknown'
# (id, kind, regular expression searched in the log)
@@ -45,6 +46,7 @@ TABLE: list[tuple[str, str, str]] = [
('games.noTitleID', NO_TITLE_ID, r'no NSP with a readable title ID in '),
('disk.low', DISK_FULL, r'less than [0-9]+ GB free on the volume of '),
('disk.full', DISK_FULL, r'No space left on device'),
+ ('icloud.detritus', CLOUD_FOLDER, r'resource fork, Finder information, or similar detritus not allowed'),
]
# The script's override for a stop, offered as "Build anyway". The others cannot be built around.
@@ -55,9 +57,10 @@ OVERRIDE_FLAGS = {
}
KINDS = [ROSETTA, TRANSLATOR, ZBIC, IOS_SDK, CLT_SELECTED, OTHER_METAL, SHADER_REGRESSION, DAMAGED_NSP, A32_PROGRAM,
- KEYS, SEVERAL_GAMES, NO_TITLE_ID, DISK_FULL]
+ KEYS, SEVERAL_GAMES, NO_TITLE_ID, DISK_FULL, CLOUD_FOLDER]
# The Swift app has four more rows that no log line sets (a drive that is gone, a signing team, a device transfer):
# they belong to the Mac launcher's install on a device and to /Volumes, which this front end does not have.
+# cloudFolder is a row of the table, so it is here, but the check that stops a build before it starts is the Mac launcher's.
_A32_NAME = re.compile(r'^(?:\[RED\] )?(.+?) \([0-9A-Fa-f]{16}\) is a 32-bit ARM program', re.M)
diff --git a/frontend-qt/nspb_qt/localization.py b/frontend-qt/nspb_qt/localization.py
index f34caa9a..db39e16c 100644
--- a/frontend-qt/nspb_qt/localization.py
+++ b/frontend-qt/nspb_qt/localization.py
@@ -784,6 +784,9 @@ TABLE: dict[str, tuple[str, str, str, str]] = {
'fail.diskFull.what': ('构建时硬盘的可用空间用完了。', 'The drive ran out of free space for the build.', 'Disken fick slut på ledigt utrymme under bygget.', 'Auf dem Laufwerk ist kein freier Speicherplatz mehr für den Build.'),
'fail.diskFull.whatNeeds': ('可用空间不足,构建在这块硬盘上至少需要 %@ GB。', 'There is not enough free space. The build needs at least %@ GB on the drive.', 'Det finns för lite ledigt utrymme. Bygget behöver minst %@ GB på disken.', 'Es ist nicht genug Speicherplatz frei. Der Build braucht mindestens %@ GB auf dem Laufwerk.'),
'fail.diskFull.next': ('请释放存放构建文件夹的硬盘空间,也就是游戏文件旁边以 _build 结尾的那个文件夹。游戏菜单里的「释放空间」会清除已完成的构建不再需要的内容。然后再构建。', "Free up space on the drive that holds the build folder, the one ending in _build beside your game files. Free space in a game's menu removes what a finished build no longer needs. Then build again.", 'Frigör utrymme på disken som innehåller byggmappen, den som slutar på _build bredvid dina spelfiler. Frigör utrymme i ett spels meny tar bort det som ett färdigt bygge inte längre behöver. Bygg sedan igen.', 'Gib Speicherplatz auf dem Laufwerk frei, auf dem der Build-Ordner liegt, also der mit der Endung _build neben deinen Spieldateien. „Speicherplatz freigeben“ im Menü eines Spiels entfernt, was ein fertiger Build nicht mehr braucht. Baue dann erneut.'),
+ 'fail.cloudFolder.what': ('构建文件夹在 iCloud 云盘或其他云端文件夹里。', 'The build folder is in iCloud Drive or another cloud folder.', 'Byggmappen ligger i iCloud Drive eller en annan molnmapp.', 'Der Build-Ordner liegt in iCloud Drive oder einem anderen Cloud-Ordner.'),
+ 'fail.cloudFolder.next': ('云端文件夹会给每个文件加上隐藏的附加数据,构建最后的签名步骤不接受这些数据。请把游戏文件移出 iCloud 云盘,或者在「保存到」里选一个云盘之外的文件夹。然后再构建。', 'Cloud folders add hidden data to every file. The signing step at the end of the build refuses it. Move your game files out of iCloud Drive, or choose a folder outside it under Save to. Then build again.', 'Molnmappar lägger till dold data på varje fil. Signeringssteget i slutet av bygget godtar den inte. Flytta dina spelfiler ut ur iCloud Drive eller välj en mapp utanför det under Spara till. Bygg sedan igen.', 'Cloud-Ordner fügen jeder Datei versteckte Zusatzdaten hinzu. Der Signierschritt am Ende des Builds lehnt sie ab. Verschiebe deine Spieldateien aus iCloud Drive heraus oder wähle unter „Sichern in“ einen Ordner außerhalb. Baue dann erneut.'),
+ 'fail.cloudFolder.button': ('选择其他文件夹', 'Choose another folder', 'Välj en annan mapp', 'Anderen Ordner wählen'),
'fail.teamTaken.what': ('这个游戏的 App ID 已注册给另一个 Apple 团队。', "The game's app ID is registered to another Apple team.", 'Spelets app-ID är registrerat hos ett annat Apple-team.', 'Die App-ID des Spiels ist bei einem anderen Apple-Team registriert.'),
'fail.teamTaken.next': ('Xcode 对你的团队拒绝了它,用你的团队专属的 ID 变体也不行。请打开 Xcode > 设置 > 账户,登录以前安装这个游戏的那个 Apple ID,或者在这里选另一个签名团队,然后再构建。', "Xcode refused it for your team, also with your team's own variant of the ID. Open Xcode > Settings > Accounts and sign in with the Apple ID that installed this game before, or choose a different signing team here. Then build again.", 'Xcode nekade det för ditt team, även med teamets egen variant av ID:t. Öppna Xcode > Inställningar > Konton och logga in med det Apple-ID som installerade spelet tidigare, eller välj ett annat signeringsteam här. Bygg sedan igen.', 'Xcode hat sie für dein Team abgelehnt, auch mit der eigenen Variante der ID für dein Team. Öffne in Xcode „Settings → Accounts“ und melde dich mit der Apple-ID an, mit der dieses Spiel zuvor installiert wurde, oder wähle hier ein anderes Signierteam. Baue dann erneut.'),
'fail.noSigningAccount.what': ('Xcode 里没有所选团队的签名账户。', 'Xcode has no signing account for the chosen team.', 'Xcode har inget signeringskonto för det valda teamet.', 'Xcode hat kein Signierkonto für das gewählte Team.'),
diff --git a/frontend-qt/tests/test_build_failure_hints.py b/frontend-qt/tests/test_build_failure_hints.py
index b2a5ca40..298f8dc7 100644
--- a/frontend-qt/tests/test_build_failure_hints.py
+++ b/frontend-qt/tests/test_build_failure_hints.py
@@ -53,6 +53,8 @@ class Classifier(unittest.TestCase):
if f['source'] == 'errno': # the system's own text, not the script's
self.assertEqual(os.strerror(errno.ENOSPC), f['fragment'])
continue
+ if f['source'] == 'codesign': # Apple's text, from a tool the script runs
+ continue
there = f['fragment'] in (ROOT / f['source']).read_text(encoding='utf-8')
if f.get('pending_sync'):
self.assertFalse(there, f"{f['id']} is in {f['source']} now: remove pending_sync ({f['pending_sync']}) from the fixture")
diff --git a/frontend/Sources/NSPortBuilder/BuildFailure.swift b/frontend/Sources/NSPortBuilder/BuildFailure.swift
index a64e683f..d82723c6 100644
--- a/frontend/Sources/NSPortBuilder/BuildFailure.swift
+++ b/frontend/Sources/NSPortBuilder/BuildFailure.swift
@@ -10,6 +10,9 @@ enum BuildFailureKind: String, CaseIterable {
case keys, severalGames, noTitleID, driveMissing
/// The build's and the install's own steps.
case diskFull, teamTaken, noSigningAccount, deviceTransfer
+ /// The build folder is in iCloud Drive or another cloud folder (CloudFolder.swift): the launcher stops before the build, and the
+ /// codesign line of xcodebuild is the same stop for a build that got past that check.
+ case cloudFolder
case unknown
/// The script's override for this stop, offered as "Build anyway". Only these three have one that the launcher
@@ -58,6 +61,7 @@ enum BuildFailureClassifier {
("games.noTitleID", .noTitleID, "no NSP with a readable title ID in "),
("disk.low", .diskFull, "less than [0-9]+ GB free on the volume of "),
("disk.full", .diskFull, "No space left on device"),
+ ("icloud.detritus", .cloudFolder, "resource fork, Finder information, or similar detritus not allowed"),
]
/// What the launcher itself knows when the log says nothing it can use. The keys file and the game files are checked
diff --git a/frontend/Sources/NSPortBuilder/BuildFailureView.swift b/frontend/Sources/NSPortBuilder/BuildFailureView.swift
index f0865f68..56e13772 100644
--- a/frontend/Sources/NSPortBuilder/BuildFailureView.swift
+++ b/frontend/Sources/NSPortBuilder/BuildFailureView.swift
@@ -47,6 +47,8 @@ struct BuildFailureCard: View {
fix(kind, "fail.keys.button")
case .severalGames, .noTitleID, .diskFull:
fix(kind, "fail.showFolder")
+ case .cloudFolder:
+ fix(kind, "fail.cloudFolder.button")
case .teamTaken, .noSigningAccount:
if BuildModel.installedXcode() != nil { fix(kind, "fail.openXcode") }
case .deviceTransfer:
diff --git a/frontend/Sources/NSPortBuilder/CloudFolder.swift b/frontend/Sources/NSPortBuilder/CloudFolder.swift
new file mode 100644
index 00000000..8e532637
--- /dev/null
+++ b/frontend/Sources/NSPortBuilder/CloudFolder.swift
@@ -0,0 +1,42 @@
+import Foundation
+
+/// A folder that a cloud service syncs: iCloud Drive (`~/Library/Mobile Documents`), a File Provider cloud folder
+/// (`~/Library/CloudStorage`: OneDrive, Google Drive, Dropbox), or a folder iCloud syncs from elsewhere, such as Desktop and
+/// Documents when they are turned on in iCloud Drive. The service adds extended attributes to the files in it. codesign refuses
+/// them ("resource fork, Finder information, or similar detritus not allowed"), so a build folder there fails at its last step,
+/// often after an hour (issue #263).
+enum CloudFolder {
+ /// The folders under the home folder that are cloud folders by their place.
+ static let homeRoots = ["Library/Mobile Documents", "Library/CloudStorage"]
+
+ /// Whether `path` is in a cloud folder. The path may not exist yet (a build folder is made by the build): the nearest folder
+ /// above it that exists decides. Symlinks are resolved first, so a link to a cloud folder counts as one.
+ /// `isSynced` answers for an existing folder that is not in a root: the default asks the system whether iCloud syncs it.
+ static func contains(_ path: String, home: String = NSHomeDirectory(),
+ isSynced: (URL) -> Bool = CloudFolder.systemSyncs) -> Bool {
+ guard !path.isEmpty else { return false }
+ let here = resolved(path)
+ for root in homeRoots.map({ resolved(home + "/" + $0) }) where here == root || here.hasPrefix(root + "/") { return true }
+ return isSynced(URL(fileURLWithPath: nearestExisting(here)))
+ }
+
+ /// iCloud's own answer for a file or folder: true when it is in an iCloud container, which includes Desktop and Documents
+ /// while they are synced.
+ static func systemSyncs(_ url: URL) -> Bool {
+ (try? url.resourceValues(forKeys: [.isUbiquitousItemKey]))?.isUbiquitousItem ?? false
+ }
+
+ private static func nearestExisting(_ path: String) -> String {
+ var url = URL(fileURLWithPath: path)
+ while url.path != "/", !FileManager.default.fileExists(atPath: url.path) { url.deleteLastPathComponent() }
+ return url.path
+ }
+
+ /// The path with its symlinks resolved as far as it exists, and the rest of it as written.
+ private static func resolved(_ path: String) -> String {
+ let existing = nearestExisting(path)
+ let base = URL(fileURLWithPath: existing).resolvingSymlinksInPath().path
+ let rest = String(URL(fileURLWithPath: path).standardized.path.dropFirst(URL(fileURLWithPath: existing).standardized.path.count))
+ return rest.isEmpty ? base : (base == "/" ? "" : base) + rest
+ }
+}
diff --git a/frontend/Sources/NSPortBuilder/ContentView.swift b/frontend/Sources/NSPortBuilder/ContentView.swift
index dbd473bd..76636a20 100644
--- a/frontend/Sources/NSPortBuilder/ContentView.swift
+++ b/frontend/Sources/NSPortBuilder/ContentView.swift
@@ -1185,6 +1185,12 @@ final class BuildModel: ObservableObject {
}
let tidHex = Self.titleID(basePath).map { String(format: "%016llX", $0) } ?? "game"
let workDir = (outDir.isEmpty ? baseDir : outDir) + "/" + tidHex + "_build"
+ // The build's signing step refuses the attributes a cloud folder adds, after the long steps: stop here instead.
+ if cloudFolderCheck(workDir) {
+ failure = BuildFailure(kind: .cloudFolder, gameName: nil, detail: workDir)
+ fail(failureWhat(failure!))
+ return
+ }
var inputDir = baseDir
if dirs.count > 1 || !unpicked.isEmpty {
// A stable folder per game (#132): the script's fingerprints name its files and its profile path.
@@ -1369,6 +1375,17 @@ final class BuildModel: ObservableObject {
doneNote = failureWhat(f)
}
+ /// Whether the build folder is in a cloud folder. Tests stand in for the system's answer.
+ var cloudFolderCheck: (String) -> Bool = { CloudFolder.contains($0) }
+
+ /// The Save to folder, picked in a panel. Clears the cloud-folder stop, since the next build looks at the new folder.
+ func chooseBuildFolder() {
+ let d = NSOpenPanel(); d.canChooseDirectories = true; d.canChooseFiles = false
+ guard d.runModal() == .OK, let u = d.url else { return }
+ outDir = u.path
+ if failure?.kind == .cloudFolder { failure = nil; doneNote = "" }
+ }
+
/// What the classifier may check besides the log: the keys file and where the game files are.
func failureInputs() -> BuildFailureClassifier.Inputs {
BuildFailureClassifier.Inputs(keysPath: keysPath, paths: ([basePath, updatePath, gameDir] + dlcPaths).filter { !$0.isEmpty },
@@ -1430,6 +1447,8 @@ final class BuildModel: ObservableObject {
if let chooseKeys { chooseKeys() } else { pickFiles(kind: .keys) } // the same picker as the keys row
case .severalGames, .noTitleID, .diskFull:
showFailureFolder()
+ case .cloudFolder:
+ chooseBuildFolder()
case .teamTaken, .noSigningAccount:
openXcode()
case .deviceTransfer:
@@ -3152,10 +3171,7 @@ struct BuilderView: View {
}
divider
row(m.t("build.saveTo"), detail: m.outDir.isEmpty ? m.t("build.saveDefault") : m.shortPath(m.outDir), help: m.outDir) {
- Button(m.t("data.change")) {
- let d = NSOpenPanel(); d.canChooseDirectories = true; d.canChooseFiles = false
- if d.runModal() == .OK, let u = d.url { m.outDir = u.path }
- }
+ Button(m.t("data.change")) { m.chooseBuildFolder() }
}
}
.task(id: KeyCheck.Inputs(keys: m.keysPath, files: [m.basePath, m.updatePath] + m.dlcPaths)) {
diff --git a/frontend/Sources/NSPortBuilder/Localization.swift b/frontend/Sources/NSPortBuilder/Localization.swift
index d2fa2248..814e10e4 100644
--- a/frontend/Sources/NSPortBuilder/Localization.swift
+++ b/frontend/Sources/NSPortBuilder/Localization.swift
@@ -946,6 +946,9 @@ enum L10n {
"fail.diskFull.what": ("构建时硬盘的可用空间用完了。", "The drive ran out of free space for the build."),
"fail.diskFull.whatNeeds": ("可用空间不足,构建在这块硬盘上至少需要 %@ GB。", "There is not enough free space. The build needs at least %@ GB on the drive."),
"fail.diskFull.next": ("请释放存放构建文件夹的硬盘空间,也就是游戏文件旁边以 _build 结尾的那个文件夹。游戏菜单里的「释放空间」会清除已完成的构建不再需要的内容。然后再构建。", "Free up space on the drive that holds the build folder, the one ending in _build beside your game files. Free space in a game's menu removes what a finished build no longer needs. Then build again."),
+ "fail.cloudFolder.what": ("构建文件夹在 iCloud 云盘或其他云端文件夹里。", "The build folder is in iCloud Drive or another cloud folder."),
+ "fail.cloudFolder.next": ("云端文件夹会给每个文件加上隐藏的附加数据,构建最后的签名步骤不接受这些数据。请把游戏文件移出 iCloud 云盘,或者在「保存到」里选一个云盘之外的文件夹。然后再构建。", "Cloud folders add hidden data to every file. The signing step at the end of the build refuses it. Move your game files out of iCloud Drive, or choose a folder outside it under Save to. Then build again."),
+ "fail.cloudFolder.button": ("选择其他文件夹", "Choose another folder"),
"fail.teamTaken.what": ("这个游戏的 App ID 已注册给另一个 Apple 团队。", "The game's app ID is registered to another Apple team."),
"fail.teamTaken.next": ("Xcode 对你的团队拒绝了它,用你的团队专属的 ID 变体也不行。请打开 Xcode > 设置 > 账户,登录以前安装这个游戏的那个 Apple ID,或者在这里选另一个签名团队,然后再构建。", "Xcode refused it for your team, also with your team's own variant of the ID. Open Xcode > Settings > Accounts and sign in with the Apple ID that installed this game before, or choose a different signing team here. Then build again."),
"fail.noSigningAccount.what": ("Xcode 里没有所选团队的签名账户。", "Xcode has no signing account for the chosen team."),
@@ -1750,6 +1753,9 @@ enum L10n {
"fail.diskFull.what": "Disken fick slut på ledigt utrymme under bygget.",
"fail.diskFull.whatNeeds": "Det finns för lite ledigt utrymme. Bygget behöver minst %@ GB på disken.",
"fail.diskFull.next": "Frigör utrymme på disken som innehåller byggmappen, den som slutar på _build bredvid dina spelfiler. Frigör utrymme i ett spels meny tar bort det som ett färdigt bygge inte längre behöver. Bygg sedan igen.",
+ "fail.cloudFolder.what": "Byggmappen ligger i iCloud Drive eller en annan molnmapp.",
+ "fail.cloudFolder.next": "Molnmappar lägger till dold data på varje fil. Signeringssteget i slutet av bygget godtar den inte. Flytta dina spelfiler ut ur iCloud Drive eller välj en mapp utanför det under Spara till. Bygg sedan igen.",
+ "fail.cloudFolder.button": "Välj en annan mapp",
"fail.teamTaken.what": "Spelets app-ID är registrerat hos ett annat Apple-team.",
"fail.teamTaken.next": "Xcode nekade det för ditt team, även med teamets egen variant av ID:t. Öppna Xcode > Inställningar > Konton och logga in med det Apple-ID som installerade spelet tidigare, eller välj ett annat signeringsteam här. Bygg sedan igen.",
"fail.noSigningAccount.what": "Xcode har inget signeringskonto för det valda teamet.",
@@ -2523,6 +2529,9 @@ enum L10n {
"fail.diskFull.what": "Auf dem Laufwerk ist kein freier Speicherplatz mehr für den Build.",
"fail.diskFull.whatNeeds": "Es ist nicht genug Speicherplatz frei. Der Build braucht mindestens %@ GB auf dem Laufwerk.",
"fail.diskFull.next": "Gib Speicherplatz auf dem Laufwerk frei, auf dem der Build-Ordner liegt, also der mit der Endung _build neben deinen Spieldateien. „Speicherplatz freigeben“ im Menü eines Spiels entfernt, was ein fertiger Build nicht mehr braucht. Baue dann erneut.",
+ "fail.cloudFolder.what": "Der Build-Ordner liegt in iCloud Drive oder einem anderen Cloud-Ordner.",
+ "fail.cloudFolder.next": "Cloud-Ordner fügen jeder Datei versteckte Zusatzdaten hinzu. Der Signierschritt am Ende des Builds lehnt sie ab. Verschiebe deine Spieldateien aus iCloud Drive heraus oder wähle unter „Sichern in“ einen Ordner außerhalb. Baue dann erneut.",
+ "fail.cloudFolder.button": "Anderen Ordner wählen",
"fail.teamTaken.what": "Die App-ID des Spiels ist bei einem anderen Apple-Team registriert.",
"fail.teamTaken.next": "Xcode hat sie für dein Team abgelehnt, auch mit der eigenen Variante der ID für dein Team. Öffne in Xcode „Settings → Accounts“ und melde dich mit der Apple-ID an, mit der dieses Spiel zuvor installiert wurde, oder wähle hier ein anderes Signierteam. Baue dann erneut.",
"fail.noSigningAccount.what": "Xcode hat kein Signierkonto für das gewählte Team.",
diff --git a/frontend/Tests/Fixtures/build_failures.json b/frontend/Tests/Fixtures/build_failures.json
index c41fc0a4..75a50a65 100644
--- a/frontend/Tests/Fixtures/build_failures.json
+++ b/frontend/Tests/Fixtures/build_failures.json
@@ -106,5 +106,12 @@
"source": "errno",
"fragment": "No space left on device",
"text": "[RED] OSError: [Errno 28] No space left on device"
+ },
+ {
+ "id": "icloud.detritus",
+ "kind": "cloudFolder",
+ "source": "codesign",
+ "fragment": "resource fork, Finder information, or similar detritus not allowed",
+ "text": "CodeSign /Users/x/Library/Mobile\\ Documents/com~apple~CloudDocs/Downloads/0100152000022000_build/xcode-derived-data/Build/Products/Release-iphoneos/DmIOS.app (in target 'DmIOS' from project 'DmIOS')\n/Users/x/Library/Mobile Documents/com~apple~CloudDocs/Downloads/0100152000022000_build/xcode-derived-data/Build/Products/Release-iphoneos/DmIOS.app: resource fork, Finder information, or similar detritus not allowed\nCommand CodeSign failed with a nonzero exit code"
}
]
diff --git a/frontend/Tests/NSPortBuilderTests/BuildFailureRowsTests.swift b/frontend/Tests/NSPortBuilderTests/BuildFailureRowsTests.swift
index 599e79e6..a44f43cf 100644
--- a/frontend/Tests/NSPortBuilderTests/BuildFailureRowsTests.swift
+++ b/frontend/Tests/NSPortBuilderTests/BuildFailureRowsTests.swift
@@ -116,8 +116,8 @@ final class BuildFailureRowsTests: XCTestCase {
}
func testTheNewRowsAreInAllThreeLanguagesWithoutSemicolonsOrTheProductName() {
- var keys = ["fail.showFolder", "fail.openXcode", "fail.retry", "fail.keys.button", "fail.driveMissing.whatNamed", "fail.diskFull.whatNeeds"]
- let kinds = BuildFailureTests.stateKinds.union([.keys, .severalGames, .noTitleID, .diskFull])
+ var keys = ["fail.showFolder", "fail.openXcode", "fail.retry", "fail.keys.button", "fail.driveMissing.whatNamed", "fail.diskFull.whatNeeds", "fail.cloudFolder.button"]
+ let kinds = BuildFailureTests.stateKinds.union([.keys, .severalGames, .noTitleID, .diskFull, .cloudFolder])
for k in BuildFailureKind.allCases where kinds.contains(k) { keys += [k.whatKey, k.nextKey] }
for key in keys {
let row = L10n.table[key]
diff --git a/frontend/Tests/NSPortBuilderTests/BuildFailureTests.swift b/frontend/Tests/NSPortBuilderTests/BuildFailureTests.swift
index 12f2a3a6..50cc53dd 100644
--- a/frontend/Tests/NSPortBuilderTests/BuildFailureTests.swift
+++ b/frontend/Tests/NSPortBuilderTests/BuildFailureTests.swift
@@ -44,6 +44,7 @@ final class BuildFailureTests: XCTestCase {
XCTAssertEqual(String(cString: strerror(ENOSPC)), f.fragment, f.id)
continue
}
+ if f.source == "codesign" { continue } // Apple's text, from a tool the script runs
let source = try String(contentsOf: Self.root.appendingPathComponent(f.source), encoding: .utf8)
let there = source.contains(f.fragment)
XCTAssertTrue(there, "\(f.id): \(f.source) no longer contains \"\(f.fragment)\": update the pattern and the fixture")
diff --git a/frontend/Tests/NSPortBuilderTests/CloudFolderTests.swift b/frontend/Tests/NSPortBuilderTests/CloudFolderTests.swift
new file mode 100644
index 00000000..c7d091ef
--- /dev/null
+++ b/frontend/Tests/NSPortBuilderTests/CloudFolderTests.swift
@@ -0,0 +1,131 @@
+import XCTest
+@testable import NSPortBuilder
+
+/// #263: a build folder in iCloud Drive fails at the signing step ("resource fork, Finder information, or similar detritus not
+/// allowed"). The launcher says so before the build starts, and reads the same words from a log.
+final class CloudFolderTests: XCTestCase {
+ private var home: URL!
+ private var saved: [(String, Any?)] = []
+
+ override func setUpWithError() throws {
+ saved = ["repoPath", "buildOutputDirectory"].map { ($0, UserDefaults.standard.object(forKey: $0)) }
+ home = FileManager.default.temporaryDirectory.appendingPathComponent("nspb-cloud-" + UUID().uuidString)
+ try FileManager.default.createDirectory(at: home, withIntermediateDirectories: true)
+ }
+
+ override func tearDownWithError() throws {
+ for (key, value) in saved { UserDefaults.standard.set(value, forKey: key) }
+ try? FileManager.default.removeItem(at: home)
+ }
+
+ private func folder(_ rel: String) throws -> String {
+ let url = home.appendingPathComponent(rel)
+ try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)
+ return url.path
+ }
+
+ private func contains(_ path: String, synced: Bool = false) -> Bool {
+ CloudFolder.contains(path, home: home.path, isSynced: { _ in synced })
+ }
+
+ // ---- by place
+
+ func testICloudDriveAndFileProviderFoldersAreCloudFolders() throws {
+ let drive = try folder("Library/Mobile Documents/com~apple~CloudDocs/Downloads")
+ let provider = try folder("Library/CloudStorage/OneDrive-Personal")
+ XCTAssertTrue(contains(drive))
+ XCTAssertTrue(contains(drive + "/0100152000022000_build"), "a build folder that does not exist yet")
+ XCTAssertTrue(contains(drive + "/a/b/c/0100152000022000_build"), "several levels that do not exist yet")
+ XCTAssertTrue(contains(provider + "/Games"))
+ XCTAssertTrue(contains(home.path + "/Library/Mobile Documents"), "the root itself")
+ }
+
+ func testOtherFoldersAreNot() throws {
+ let games = try folder("Games")
+ _ = try folder("Library/Mobile Documents")
+ let lookalike = try folder("Library/Mobile Documents Backup")
+ XCTAssertFalse(contains(games))
+ XCTAssertFalse(contains(games + "/0100152000022000_build"))
+ XCTAssertFalse(contains(lookalike), "only a folder inside the root counts")
+ XCTAssertFalse(contains("/Volumes/NX/games/0100152000022000_build"))
+ XCTAssertFalse(contains(""))
+ }
+
+ func testALinkIntoACloudFolderIsOne() throws {
+ let target = try folder("Library/Mobile Documents/com~apple~CloudDocs/Games")
+ let link = home.appendingPathComponent("Games")
+ try FileManager.default.createSymbolicLink(atPath: link.path, withDestinationPath: target)
+ XCTAssertTrue(contains(link.path + "/0100152000022000_build"))
+ let outside = try folder("Elsewhere")
+ let away = home.appendingPathComponent("Library/Mobile Documents/com~apple~CloudDocs/Away")
+ try FileManager.default.createSymbolicLink(atPath: away.path, withDestinationPath: outside)
+ XCTAssertFalse(contains(away.path + "/x_build"), "a link out of iCloud Drive leads out of it")
+ }
+
+ // ---- by the system's answer (Desktop and Documents synced to iCloud)
+
+ func testAFolderTheSystemSaysIsSyncedIsOne() throws {
+ let documents = try folder("Documents/Games")
+ XCTAssertFalse(contains(documents))
+ XCTAssertTrue(contains(documents, synced: true))
+ var asked: [String] = []
+ XCTAssertFalse(CloudFolder.contains(documents + "/x_build", home: home.path, isSynced: { asked.append($0.path); return false }))
+ XCTAssertEqual(asked.map { URL(fileURLWithPath: $0).standardizedFileURL.lastPathComponent }, ["Games"], "the nearest folder that exists is asked")
+ }
+
+ func testTheSystemAnswerForAnOrdinaryFolderIsNo() throws {
+ XCTAssertFalse(CloudFolder.systemSyncs(URL(fileURLWithPath: try folder("Plain"))))
+ }
+
+ // ---- the log
+
+ func testTheCodesignLineOfTheIssueIsTheCloudFolderStop() throws {
+ let f = try XCTUnwrap(BuildFailureTests().fixtures().first { $0.id == "icloud.detritus" })
+ XCTAssertEqual(BuildFailureClassifier.classify(f.text).kind, .cloudFolder)
+ let log = "FAIL: ad-hoc signature with the entitlements\nCodeSign /Users/x/DmIOS.app\n/Users/x/DmIOS.app: resource fork, Finder information, or similar detritus not allowed\n"
+ XCTAssertEqual(BuildFailureClassifier.classify(log).kind, .cloudFolder)
+ XCTAssertEqual(BuildFailureClassifier.classify("FAIL: ad-hoc signature with the entitlements").kind, .unknown, "another signing failure keeps its note")
+ }
+
+ func testTheHintHasAllFourLanguagesAndNoSemicolons() {
+ let keys = [BuildFailureKind.cloudFolder.whatKey, BuildFailureKind.cloudFolder.nextKey, "fail.cloudFolder.button"]
+ for key in keys {
+ let row = L10n.table[key]
+ XCTAssertNotNil(row, key)
+ let texts = [row?.zh ?? "", row?.en ?? "", L10n.sv[key] ?? "", L10n.de[key] ?? ""]
+ for text in texts {
+ XCTAssertFalse(text.isEmpty, key)
+ XCTAssertFalse(text.contains(";") || text.contains("\u{FF1B}") || text.contains("\u{2014}"), "\(key) has a semicolon or a dash")
+ }
+ XCTAssertEqual(Set(texts).count, 4, "\(key) has a text twice")
+ }
+ XCTAssertTrue(L10n.table[BuildFailureKind.cloudFolder.nextKey]!.en.contains("iCloud Drive"))
+ }
+
+ // ---- before the build
+
+ @MainActor func testABuildInACloudFolderStopsBeforeItStarts() throws {
+ let repo = home.appendingPathComponent("repo")
+ for f in BuildModel.requiredTools + ["dm/tools/nx_extract/Program.cs"] {
+ let url = repo.appendingPathComponent(f)
+ try FileManager.default.createDirectory(at: url.deletingLastPathComponent(), withIntermediateDirectories: true)
+ try "x".write(to: url, atomically: true, encoding: .utf8)
+ }
+ let m = BuildModel()
+ m.repoPath = repo.path
+ m.outDir = ""
+ m.updateSlot("base") { $0.paths = ["/Games/Game [0100152000022000].nsp"] }
+ var asked: [String] = []
+ m.cloudFolderCheck = { asked.append($0); return true }
+ m.startBuild()
+ XCTAssertEqual(asked, ["/Games/0100152000022000_build"], "the build folder next to the game files")
+ XCTAssertFalse(m.running)
+ XCTAssertEqual(m.failure?.kind, .cloudFolder)
+ XCTAssertEqual(m.doneNote, m.t(BuildFailureKind.cloudFolder.whatKey))
+
+ m.outDir = "/Volumes/NX/out"
+ asked = []
+ m.startBuild()
+ XCTAssertEqual(asked, ["/Volumes/NX/out/0100152000022000_build"], "Save to wins when it is set")
+ }
+}