Run a virtual iPhone on an Apple Silicon Mac.
Swift
Keep a patch log in Launchpad and clear restore files after first boot
Lakr03a0fbc90911
diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Control/VPhoneLaunchpadControlCommands.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Control/VPhoneLaunchpadControlCommands.swiftindex 60af43fb..22d022ed 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Control/VPhoneLaunchpadControlCommands.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Control/VPhoneLaunchpadControlCommands.swift@@ -400,7 +400,8 @@ struct VPhoneLaunchpadControlCommands {case nil, "console": ""case "create": "-create"case "dfu": "-dfu"- case let kind?: throw VPhoneLaunchpadError("--kind is console, create or dfu, not \(kind).")+ case "patch": "-patch"+ case let kind?: throw VPhoneLaunchpadError("--kind is console, create, dfu or patch, not \(kind).")}var count = 200if let text = request.option("lines") {diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstrings b/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstringsindex 312f41d6..e13581f2 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstrings+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstrings@@ -9817,6 +9817,40 @@}}},+ "Show Patch Log" : {+ "localizations" : {+ "en" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Show Patch Log"+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "パッチログを表示"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "패치 로그 보기"+ }+ },+ "vi" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Hiển thị nhật ký vá"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "显示补丁日志"+ }+ }+ }+ },"Show Progress" : {"localizations" : {"en" : {diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadCreationPipeline.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadCreationPipeline.swiftindex b285c3ed..e61e8990 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadCreationPipeline.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadCreationPipeline.swift@@ -195,9 +195,40 @@ final class VPhoneLaunchpadCreationPipeline {return}}+ if !options.keepArtifacts {+ await removeRestoreFiles()+ }append("● \(options.name) is ready.")}+ /// Removes the `iPhone*_Restore` tree once the machine has booted, as+ /// `cfw install` does without `--keep-artifacts`. Only a real folder is+ /// removed; a link by that name is left alone. A failure here does not+ /// fail the creation.+ private func removeRestoreFiles() async {+ let bundle = machine.url+ let lines = await Task.detached { () -> [String] in+ let manager = FileManager.default+ let entries = (try? manager.contentsOfDirectory(atPath: bundle.path)) ?? []+ var lines: [String] = []+ for name in entries where name.hasPrefix("iPhone") && name.hasSuffix("_Restore") {+ let url = bundle.appendingPathComponent(name)+ let values = try? url.resourceValues(forKeys: [.isSymbolicLinkKey, .isDirectoryKey])+ guard values?.isDirectory == true, values?.isSymbolicLink == false else {+ continue+ }+ do {+ try manager.removeItem(at: url)+ lines.append("removed restore files \(name)/ to save space")+ } catch {+ lines.append("warning: could not remove \(name)/: \(error.localizedDescription)")+ }+ }+ return lines+ }.value+ lines.forEach(append)+ }+private func append(_ line: String) {log.write(line)}@@ -214,9 +245,9 @@ final class VPhoneLaunchpadCreationPipeline {let log = loglet output: @Sendable (String) -> Void = { line in log.write(line) }- func run(_ arguments: [String]) async throws {- append("$ \(VPhoneLaunchpadCommandLine.display(arguments))")- try await commandLine.runChecked(arguments, onLine: output)+ func run(_ arguments: [String], onLine: @escaping @Sendable (String) -> Void = output) async throws {+ onLine("$ \(VPhoneLaunchpadCommandLine.display(arguments))")+ try await commandLine.runChecked(arguments, onLine: onLine)}switch step {@@ -235,11 +266,19 @@ final class VPhoneLaunchpadCreationPipeline {case .patch:// The preset rides on `fw patch` itself; per-patch overrides are// recorded first, the way `vm config` follows `vm new` above. Both- // lines reach the log.+ // lines reach the log. The creation log starts over on a retry, so+ // the patch output is also kept in a log of its own for later+ // diagnosis.+ let patchLog = VPhoneLaunchpadLogWriter(url: VPhoneLaunchpadMachineLibrary.consoleLog(machine, suffix: "-patch"))+ patchLog.write("# \(options.name), \(Date().formatted(.iso8601)), Core Bundle \(bundles.activeVersion ?? "?")")+ let tee: @Sendable (String) -> Void = { line in+ log.write(line)+ patchLog.write(line)+ }if options.patches.hasOverrides {- try await run(["fw", "set-patches", name] + options.patches.setPatchesArguments + library)+ try await run(["fw", "set-patches", name] + options.patches.setPatchesArguments + library, onLine: tee)}- try await run(patchArguments + library)+ try await run(patchArguments + library, onLine: tee)case .bootDFU:let arguments = ["vm", "launch", name, "--dfu"] + library@@ -309,7 +348,10 @@ final class VPhoneLaunchpadCreationPipeline {machineName: name,libraryRoot: Self.canonicalPath(URL(fileURLWithPath: options.libraryRoot, isDirectory: true)),forceDyldSharedCacheMaxSlide: options.forceDyldSharedCacheMaxSlide,- keepArtifacts: options.keepArtifacts,+ // The restore tree stays until first boot succeeds, so a+ // failed boot can still be restored again without preparing+ // the firmware anew. `removeRestoreFiles()` reclaims it then.+ keepArtifacts: true,onLine: output,)guard status == 0 else {diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachinesView.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachinesView.swiftindex 51dfdfcf..c2f5f6e8 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachinesView.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachinesView.swift@@ -205,6 +205,10 @@ struct VPhoneLaunchpadMachinesView: View {Button("Show Console Log") {NSWorkspace.shared.open(VPhoneLaunchpadMachineLibrary.consoleLog(machine.path))}+ Button("Show Patch Log") {+ NSWorkspace.shared.open(VPhoneLaunchpadMachineLibrary.consoleLog(machine.path, suffix: "-patch"))+ }+ .disabled(!FileManager.default.fileExists(atPath: VPhoneLaunchpadMachineLibrary.consoleLog(machine.path, suffix: "-patch").path))Divider()Button("Delete…", role: .destructive) { deletion = machine.path }.disabled(!isStopped)diff --git a/VPhoneLaunchpad/VPhoneLaunchpadShared/VPhoneLaunchpadControl.swift b/VPhoneLaunchpad/VPhoneLaunchpadShared/VPhoneLaunchpadControl.swiftindex dbd1ad80..157756fe 100644--- a/VPhoneLaunchpad/VPhoneLaunchpadShared/VPhoneLaunchpadControl.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpadShared/VPhoneLaunchpadControl.swift@@ -163,7 +163,7 @@ nonisolated struct VPhoneLaunchpadControlCommand: Sendable {Self(name: "vm.wait", arguments: ["name"], options: ["root", "timeout"], flags: [],summary: "Wait until vphoned answers on the machine's vphone.sock."),Self(name: "vm.log", arguments: ["name"], options: ["root", "lines", "kind"], flags: [],- summary: "The last lines of the console log (--kind create or dfu for those logs)."),+ summary: "The last lines of the console log (--kind create, dfu or patch for those logs)."),Self(name: "vm.create", arguments: ["name"], options: ["root", "iphone-source", "cloudos-source", "cpu", "memory", "disk-size", "network", "preset", "from",], flags: ["force-dsc-maxslide", "keep-artifacts", "no-wait"],