Last active
March 26, 2024 10:39
-
-
Save finestructure/f4ce789d35bcde4c792f27f6e3776228 to your computer and use it in GitHub Desktop.
List Swift toolchain IDs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env swift | |
import Foundation | |
let toolchainsDir = URL(fileURLWithPath: "/Library/Developer/Toolchains") | |
struct ToolchainInfoPlist: Codable { | |
var bundleIdentifier: String | |
var createdDate: Date | |
var displayName: String | |
enum CodingKeys: String, CodingKey { | |
case bundleIdentifier = "CFBundleIdentifier" | |
case createdDate = "CreatedDate" | |
case displayName = "DisplayName" | |
} | |
} | |
func readPlist(url: URL) throws -> ToolchainInfoPlist { | |
try PropertyListDecoder().decode(ToolchainInfoPlist.self, from: Data(contentsOf: url)) | |
} | |
func getToolchainInfo(toolchainsDir: URL) throws -> [ToolchainInfoPlist] { | |
try FileManager.default.contentsOfDirectory(atPath: toolchainsDir.path) | |
.map { toolchainsDir.appendingPathComponent($0) } | |
.filter(\.hasDirectoryPath) | |
.map { $0.appendingPathComponent("Info.plist") } | |
.map(readPlist(url:)) | |
} | |
try getToolchainInfo(toolchainsDir: toolchainsDir) | |
.sorted(by: { $0.bundleIdentifier < $1.bundleIdentifier }) | |
.forEach { | |
print("Name:", $0.displayName) | |
print("xcrun --toolchain \($0.bundleIdentifier) swift --version") | |
print() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment