-
Notifications
You must be signed in to change notification settings - Fork 15
/
Package.swift
196 lines (183 loc) · 5.68 KB
/
Package.swift
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// swift-tools-version:5.2
import PackageDescription
import Foundation
enum Builder {
case theos
case xcode
case spm
}
let swiftSyntaxVersion: Package.Dependency.Requirement = {
#if swift(>=5.6)
#error("""
Internal error: Swift Package Manager should be reading from
[email protected], not Package.swift.
""")
#elseif swift(>=5.5)
return .exact("0.50500.0")
#elseif swift(>=5.4)
return .exact("0.50400.0")
#elseif swift(>=5.3)
return .exact("0.50300.0")
#elseif swift(>=5.2)
return .exact("0.50200.0")
#else
#error("Orion does not support versions of Swift lower than 5.2.")
#endif
}()
let builder: Builder
let env = ProcessInfo.processInfo.environment
if env["SPM_THEOS_BUILD"] == "1" {
builder = .theos
} else if env["XPC_SERVICE_NAME"]?.contains("com.apple.dt.Xcode.") == true {
builder = .xcode
} else {
builder = .spm
}
func system(_ path: String, _ args: String...) -> String {
let pipe = Pipe()
let process = Process()
process.launchPath = path
process.arguments = args
process.standardOutput = pipe
process.standardError = nil
process.launch()
process.waitUntilExit()
return String(data: pipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8)!
.trimmingCharacters(in: .whitespacesAndNewlines)
}
// based on
// https://github.com/muter-mutation-testing/muter/blob/dc53a9cd1792b2ffd3c9a1a0795aae99e8c7334d/Package.swift#L40
let rpathLinkerSettings: [LinkerSetting]? = {
#if os(macOS)
guard builder == .xcode else { return nil }
let xcrunSwiftPath = system("/usr/bin/xcrun", "-f", "swift")
let overriddenPrefix = URL(fileURLWithPath: xcrunSwiftPath)
.deletingLastPathComponent().deletingLastPathComponent()
let defaultPlatformPath = system("/usr/bin/xcodebuild", "-version", "-sdk", "macosx", "PlatformPath")
let defaultPrefix = URL(fileURLWithPath: defaultPlatformPath)
.deletingLastPathComponent().deletingLastPathComponent()
.appendingPathComponent("Toolchains/XcodeDefault.xctoolchain/usr")
let computedPrefix: URL
if overriddenPrefix == defaultPrefix {
// there's no explicit toolchain override. A more specific override may exist
// inside the PATH
let xcodebuildPath = system("/usr/bin/type", "-p", "xcodebuild")
let platformPath = system(xcodebuildPath, "-version", "-sdk", "macosx", "PlatformPath")
computedPrefix = URL(fileURLWithPath: platformPath)
.deletingLastPathComponent().deletingLastPathComponent()
.appendingPathComponent("Toolchains/XcodeDefault.xctoolchain/usr")
} else {
computedPrefix = overriddenPrefix
}
let rpath = computedPrefix.appendingPathComponent("lib/swift/macosx")
return [
.unsafeFlags(["-Xlinker", "-rpath", "-Xlinker", rpath.path])
]
#else
return nil
#endif
}()
var package = Package(
name: "Orion",
platforms: [.macOS("10.12")],
products: [
.library(
name: "OrionProcessor",
targets: ["OrionProcessor"]
),
.executable(
name: "OrionCLI",
targets: ["OrionCLI"]
),
.executable(
name: "generate-test-fixtures",
targets: ["GenerateTestFixtures"]
),
],
dependencies: [
.package(name: "SwiftSyntax", url: "https://github.com/apple/swift-syntax.git", swiftSyntaxVersion),
.package(name: "swift-argument-parser", url: "https://github.com/apple/swift-argument-parser", .upToNextMinor(from: "0.4.0")),
],
targets: [
.target(
name: "OrionProcessor",
dependencies: ["SwiftSyntax"]
),
.target(
name: "OrionCLI",
dependencies: [
"OrionProcessor",
.product(name: "ArgumentParser", package: "swift-argument-parser")
],
linkerSettings: rpathLinkerSettings
),
.target(
name: "GenerateTestFixtures",
dependencies: ["OrionProcessor"],
linkerSettings: rpathLinkerSettings
),
.testTarget(
name: "OrionProcessorTests",
dependencies: ["OrionProcessor"],
linkerSettings: rpathLinkerSettings
),
]
)
#if canImport(ObjectiveC)
if builder != .theos {
package.products += [
.library(
name: "Orion",
targets: ["Orion"]
),
.library(
name: "CydiaSubstrate",
targets: ["CydiaSubstrate"]
),
.library(
name: "OrionBackend_Substrate",
targets: ["OrionBackend_Substrate"]
),
.executable(
name: "OrionPlayground",
targets: ["OrionPlayground"]
),
]
package.targets += [
.target(
name: "OrionC",
dependencies: []
),
.target(
name: "Orion",
dependencies: ["OrionC"]
),
.systemLibrary(
name: "CydiaSubstrate"
),
.target(
name: "OrionBackend_Substrate",
dependencies: ["CydiaSubstrate", "Orion"]
),
.target(
name: "Fishhook"
),
.target(
name: "OrionBackend_Fishhook",
dependencies: ["Fishhook", "Orion"]
),
.target(
name: "OrionPlayground",
dependencies: ["Orion", "OrionTestSupport"]
),
.target(
name: "OrionTestSupport",
dependencies: ["Orion"]
),
.testTarget(
name: "OrionTests",
dependencies: ["Orion", "OrionBackend_Fishhook", "OrionTestSupport"]
),
]
}
#endif