Repository navigation
Expand file tree
/
Copy pathPackage.swift
More file actions
346 lines (309 loc) · 14.5 KB
/
Copy pathPackage.swift
File metadata and controls
346 lines (309 loc) · 14.5 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
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
// swift-tools-version: 6.2
// The swift-tools-version declares the minimum version of Swift required to build this package.
import CompilerPluginSupport
import Foundation
import PackageDescription
let packageDirURL: URL = URL(fileURLWithPath: #filePath).deletingLastPathComponent()
let swiftLanguageVersion: String =
(try? String(contentsOf: packageDirURL.appendingPathComponent(".swift-version"), encoding: .utf8))
.flatMap { Version($0.trimmingCharacters(in: .newlines))?.major }.map(String.init(describing:)) ?? "6"
/// swift-confidential package source.
enum SwiftConfidentialSource {
// Waiting for the https://github.com/securevale/swift-confidential/pull/10 to be merged 🤞.
case upstream
case fork
var packageDependency: PackageDescription.Package.Dependency {
switch self {
case .upstream: .package(url: "https://github.com/securevale/swift-confidential.git", from: "0.5.2")
case .fork: .package(url: "https://github.com/nekrich/swift-confidential.git", branch: "master")
}
}
var confidentialKitTargetDependency: PackageDescription.Target.Dependency {
.product(name: "ConfidentialKit", package: "swift-confidential", condition: .when(platforms: [.macOS]))
}
var targetDependency: PackageDescription.Target.Dependency {
switch self {
case .upstream: .target(name: "Dummy")
case .fork:
#if os(macOS)
.product(name: "ConfidentialObfuscator", package: "swift-confidential", condition: .when(platforms: [.macOS]))
#else
.target(name: "Dummy")
#endif
}
}
}
// Yams package source.
enum YamsSource {
// Waiting for the https://github.com/jpsim/Yams/pull/460 to be merged 🤞.
case upstream
case fork
var packageDependency: PackageDescription.Package.Dependency {
switch self {
case .upstream: .package(url: "https://github.com/jpsim/Yams.git", from: "6.2.1")
case .fork: .package(url: "https://github.com/nekrich/Yams.git", branch: "main")
}
}
}
let swiftConfidentialSource: SwiftConfidentialSource = .fork
let yamsSource: YamsSource = .upstream
enum Targets {
static func targetBundle(
name: String,
dependencies: [PackageDescription.Target.Dependency] = [],
plugins: [PackageDescription.Target.PluginUsage] = [],
tests: Bool = true,
testsDependencies: [PackageDescription.Target.Dependency] = [],
) -> [PackageDescription.Target] {
var dependencies = dependencies
if name != "SharedLogger" { dependencies.append(.target(name: "SharedLogger")) }
var targets: [PackageDescription.Target] = [.target(name: name, dependencies: dependencies, plugins: plugins)]
if tests {
targets.append(.testTarget(name: "\(name)Tests", dependencies: [.target(name: name)] + testsDependencies))
}
return targets
}
static func commandBundle(
name: String,
dependencies: [PackageDescription.Target.Dependency] = [],
plugins: [PackageDescription.Target.PluginUsage] = [],
tests: Bool = true,
testsDependencies: [PackageDescription.Target.Dependency] = [],
commandDependencies: [PackageDescription.Target.Dependency] = [],
commandTests: Bool = false,
commandTestsDependencies: [PackageDescription.Target.Dependency] = [],
) -> [PackageDescription.Target] {
targetBundle(name: name, dependencies: dependencies, tests: tests, testsDependencies: testsDependencies)
+ targetBundle(
name: "\(name)Command",
dependencies: [.target(name: name), .product(name: "ArgumentParser", package: "swift-argument-parser")]
+ commandDependencies,
tests: commandTests,
testsDependencies: commandTestsDependencies,
)
}
static var env: [PackageDescription.Target] { targetBundle(name: "ENV") }
static var ci: [PackageDescription.Target] { targetBundle(name: "CI", dependencies: [.target(name: "ENV")]) }
static var shell: [PackageDescription.Target] { targetBundle(name: "Shell", tests: false) }
static var envSubst: [PackageDescription.Target] {
commandBundle(name: "EnvSubst", testsDependencies: [.target(name: "Shell")])
}
static var importSecrets: [PackageDescription.Target] {
targetBundle(
name: "ImportSecrets",
dependencies: [
.target(name: "EnvSubst"), .target(name: "Shell"), .target(name: "HashiCorpVaultReader"),
.target(name: "SecretsInterface"), .product(name: "Yams", package: "Yams"),
],
testsDependencies: [.target(name: "SecretsInterfaceTesting")],
)
}
static var exportSecrets: [PackageDescription.Target] {
commandBundle(
name: "ExportSecrets",
dependencies: [.target(name: "Shell"), .target(name: "CI")],
commandDependencies: [
.target(name: "EnvSubstCommand"), .target(name: "HashiCorpVaultReader"), .target(name: "CI"),
.target(name: "ImportSecrets"),
],
)
}
static var obfuscateSecrets: [PackageDescription.Target] {
commandBundle(
name: "ObfuscateSecrets",
dependencies: [.target(name: "EnvSubst"), .target(name: "Shell"), swiftConfidentialSource.targetDependency],
testsDependencies: [swiftConfidentialSource.targetDependency],
commandDependencies: [.target(name: "EnvSubstCommand"), .target(name: "ExportSecretsCommand")],
)
}
static var semanticVersion: [PackageDescription.Target] {
targetBundle(name: "SemanticVersion")
+ targetBundle(
name: "SemanticVersionMacro",
dependencies: [.target(name: "SemanticVersion"), .target(name: "SemanticVersionMacroPlugin")],
tests: false,
) + [
.macro(
name: "SemanticVersionMacroPlugin",
dependencies: [
.target(name: "SemanticVersion"), .product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
],
),
.plugin(
name: "SemanticVersionBuildToolPlugin",
capability: .buildTool(),
dependencies: [.target(name: "SemanticVersionGenerator")],
),
.executableTarget(
name: "SemanticVersionGenerator",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"), .target(name: "SemanticVersion"),
],
),
]
}
static var sharedLogger: [PackageDescription.Target] {
targetBundle(name: "SharedLogger", dependencies: [.product(name: "Logging", package: "swift-log")], tests: false)
}
static var secretsInterface: [PackageDescription.Target] {
targetBundle(name: "SecretsInterface", tests: false)
+ targetBundle(name: "SecretsInterfaceTesting", dependencies: [.target(name: "SecretsInterface")], tests: false)
}
static var hashicorpVaultReader: [PackageDescription.Target] {
targetBundle(name: "HashiCorpVaultReader", dependencies: [.target(name: "SecretsInterface")], tests: true)
}
static var xcResultParsing: [PackageDescription.Target] {
targetBundle(name: "XCResultParsing", dependencies: [.target(name: "Shell")], tests: false)
+ [
.testTarget(
name: "XCResultParsingTests",
dependencies: [.target(name: "XCResultParsing"), .target(name: "SharedLogger")],
resources: [
.copy("fixtures/test-package.xcresult"),
.copy("fixtures/coverage-diff.json"),
],
)
]
}
static var xUnitReport: [PackageDescription.Target] {
targetBundle(name: "XUnitReport", tests: false)
+ [
.testTarget(
name: "XUnitReportTests",
dependencies: [.target(name: "XUnitReport"), .target(name: "SharedLogger")],
resources: [
.copy("fixtures/test-package-xUnit-swift-testing.xml")
],
)
]
}
static var llvmCoverageParser: [PackageDescription.Target] {
targetBundle(name: "LLVMCoverageParser", tests: false)
+ [
.testTarget(
name: "LLVMCoverageParserTests",
dependencies: [.target(name: "LLVMCoverageParser"), .target(name: "SharedLogger")],
resources: [
.copy("fixtures/lcov.json"),
.copy("fixtures/llvm-diff-before.json"),
.copy("fixtures/llvm-diff-after.json"),
],
)
]
}
static var testsCoverage: [PackageDescription.Target] {
targetBundle(
name: "TestsCoverageCommand",
dependencies: [
.target(name: "XCResultParsing", condition: .when(platforms: [.macOS])),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
],
tests: false,
)
}
static var testsResults: [PackageDescription.Target] {
targetBundle(
name: "TestsResultsCommand",
dependencies: [
.target(name: "XCResultParsing", condition: .when(platforms: [.macOS])),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
],
tests: false,
)
}
static var testsOTELReporter: [PackageDescription.Target] {
commandBundle(
name: "TestsOTELReporter",
dependencies: [.target(name: "CI")],
testsDependencies: [.target(name: "CI")],
commandDependencies: [
.target(name: "XCResultParsing", condition: .when(platforms: [.macOS])), .target(name: "XUnitReport"),
.target(name: "LLVMCoverageParser"),
],
commandTests: true,
commandTestsDependencies: [
.target(name: "XCResultParsing", condition: .when(platforms: [.macOS])), .target(name: "XUnitReport"),
.target(name: "LLVMCoverageParser"),
],
)
}
}
let package = Package(
name: "cocoa-tools",
platforms: [.macOS(.v15)],
products: [
.executable(name: "mpct", targets: ["mpct"]), .library(name: "EnvSubst", targets: ["EnvSubst"]),
.library(name: "Shell", targets: ["Shell"]), .library(name: "ImportSecrets", targets: ["ImportSecrets"]),
.library(name: "ExportSecrets", targets: ["ExportSecrets"]),
.library(name: "ObfuscateSecrets", targets: ["ObfuscateSecrets"]),
.library(name: "HashiCorpVaultReader", targets: ["HashiCorpVaultReader"]),
.plugin(name: "SemanticVersionBuildToolPlugin", targets: ["SemanticVersionBuildToolPlugin"]),
.library(name: "ENV", targets: ["ENV"]), .library(name: "CI", targets: ["CI"]),
.library(name: "SecretsInterfaceTesting", targets: ["SecretsInterfaceTesting"]),
.library(name: "SecretsInterface", targets: ["SecretsInterface"]),
.library(name: "XCResultParsing", targets: ["XCResultParsing"]),
.library(name: "XUnitReport", targets: ["XUnitReport"]),
.library(name: "LLVMCoverageParser", targets: ["LLVMCoverageParser"]),
.library(name: "TestsOTELReporter", targets: ["TestsOTELReporter"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMajor(from: "1.6.1")),
.package(url: "https://github.com/swiftlang/swift-format.git", .upToNextMajor(from: "602.0.0")),
.package(url: "https://github.com/swiftlang/swift-syntax.git", .upToNextMajor(from: "602.0.0")),
.package(url: "https://github.com/apple/swift-log.git", .upToNextMajor(from: "1.6.4")),
swiftConfidentialSource.packageDependency, yamsSource.packageDependency,
.package(url: "https://github.com/apple/swift-configuration.git", from: "1.2.0", traits: [.defaults, "YAML"]),
],
targets: [
.executableTarget(
name: "mpct",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"), .target(name: "EnvSubstCommand"),
.target(name: "ObfuscateSecretsCommand", condition: .when(platforms: [.macOS])),
.target(name: "ExportSecretsCommand"), .target(name: "SemanticVersion"), .target(name: "SemanticVersionMacro"),
.target(name: "TestsCoverageCommand"), .target(name: "TestsResultsCommand"),
.target(name: "TestsOTELReporterCommand"),
],
packageAccess: true,
plugins: [.plugin(name: "SemanticVersionBuildToolPlugin")],
),
// Dummy target to avoid optional compact map on dependencies for swift-confidential upstream w/o ConfidentialObfuscator
.target(name: "Dummy"),
] + Targets.shell + Targets.envSubst + Targets.exportSecrets + Targets.importSecrets + Targets.obfuscateSecrets
+ Targets.semanticVersion + Targets.env + Targets.ci + Targets.hashicorpVaultReader + Targets.sharedLogger
+ Targets.secretsInterface + Targets.xcResultParsing + Targets.xUnitReport + Targets.llvmCoverageParser
+ Targets.testsCoverage
+ Targets.testsResults + Targets.testsOTELReporter,
swiftLanguageModes: [.version(swiftLanguageVersion)],
)
for target in package.targets where target.type != .plugin && target.type != .test {
var settings: [SwiftSetting] = target.swiftSettings ?? []
// any existential type syntax.
settings.append(.enableUpcomingFeature("ExistentialAny"))
// Enables errors for uses of members that cannot be accessed because their defining module is not directly imported.
settings.append(.enableUpcomingFeature("MemberImportVisibility"))
// Runs nonisolated async functions on the caller’s actor by default.
settings.append(.enableUpcomingFeature("NonisolatedNonsendingByDefault"))
// Errors and warnings related to the compiler’s CAS compilation caching.
settings.append(.define("CompilationCaching"))
// Warnings related to deprecated APIs that may be removed in future versions and should be replaced with more current alternatives.
settings.append(.define("DeprecatedDeclaration"))
// Warnings that identify import declarations with the @_implementationOnly attribute.
settings.append(.define("ImplementationOnlyDeprecated"))
// Warnings that diagnose @preconcurrency import declarations that don’t need @preconcurrency, experimental and disabled by default.
settings.append(.define("PreconcurrencyImport"))
// Notes related to information about a missing module dependency.
settings.append(.define("MissingModuleOnKnownPaths"))
// Warnings that indicate the compiler cannot resolve an #if canImport(<ModuleName>, _version: <version>) directive because the module found was not built with a -user-module-version flag.
settings.append(.define("ModuleVersionMissing"))
// Warnings for unrecognized feature names in -enable-upcoming-feature or enable-experimental-feature.
settings.append(.define("StrictLanguageFeatures"))
// Warnings that identify the use of language constructs and library APIs that can undermine memory safety, disabled by default.
settings.append(.define("StrictMemorySafety"))
// Warnings that identify unrecognized platform names in @available attributes and if #available statements.
settings.append(.define("AvailabilityUnrecognizedName"))
// Warnings for unrecognized warning groups specified in -Wwarning or -Werror.
settings.append(.define("UnknownWarningGroup"))
target.swiftSettings = settings
}