-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathVersion+XCPTooling.swift
More file actions
59 lines (50 loc) · 2.22 KB
/
Version+XCPTooling.swift
File metadata and controls
59 lines (50 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// Version+XCPTooling.swift
// XCParseCore
//
// Created by Alex Botkin on 11/8/19.
//
import Foundation
import TSCUtility
public extension Version {
static func xcresulttoolCompatibleWithUnicodeExportPath() -> Version {
return Version(15500, 0, 0)
}
static func xcresulttoolWithDeprecatedAPIs() -> Version {
return Version(23028, 0, 0)
}
static func xcresulttool() -> Version? {
guard let xcresulttoolVersionResult = XCResultToolCommand.Version().run() else {
return nil
}
do {
let xcresultVersionString = try xcresulttoolVersionResult.utf8Output()
let components = xcresultVersionString.components(separatedBy: CharacterSet(charactersIn: ",\n"))
var xcresulttoolVersion: Version?
for string in components {
let trimmedString = string.trimmingCharacters(in: .whitespacesAndNewlines)
if trimmedString.hasPrefix("xcresulttool version ") {
let xcresulttoolVersionString = trimmedString.replacingOccurrences(of: "xcresulttool version ", with: "")
// Check to see if we can convert it to a number
if let xcresulttoolVersionInt = Int(xcresulttoolVersionString) {
xcresulttoolVersion = Version(xcresulttoolVersionInt, 0, 0)
} else {
xcresulttoolVersion = Version(string: xcresulttoolVersionString)
}
// on some Xcode versions (for example Xcode 26 beta 2),xcresulttoolVersion is coming in as 24038.1
let cleanedVersionString = xcresulttoolVersionString.before(first: ".")
if let cleanedVersionInt = Int(cleanedVersionString) {
xcresulttoolVersion = Version(cleanedVersionInt, 0, 0)
}
}
}
if xcresulttoolVersion == nil {
print("Failed to parse xcresulttool version: \(xcresultVersionString)")
}
return xcresulttoolVersion
} catch {
print("Failed to parse xcresulttool version with error: \(error)")
return nil
}
}
}