1
1
/*
2
2
This source file is part of the Swift.org open source project
3
3
4
- Copyright (c) 2021 Apple Inc. and the Swift project authors
4
+ Copyright (c) 2021-2022 Apple Inc. and the Swift project authors
5
5
Licensed under Apache License v2.0 with Runtime Library Exception
6
6
7
7
See http://swift.org/LICENSE.txt for license information
@@ -29,14 +29,14 @@ public struct PackageManager {
29
29
) throws -> BuildResult {
30
30
// Ask the plugin host to build the specified products and targets, and wait for a response.
31
31
// FIXME: We'll want to make this asynchronous when there is back deployment support for it.
32
- return try sendMessageAndWaitForReply ( . buildOperationRequest( subset: subset, parameters: parameters) ) {
32
+ return try sendMessageAndWaitForReply ( . buildOperationRequest( subset: . init ( subset) , parameters: . init ( parameters) ) ) {
33
33
guard case . buildOperationResponse( let result) = $0 else { return nil }
34
- return result
34
+ return . init ( result)
35
35
}
36
36
}
37
37
38
38
/// Specifies a subset of products and targets of a package to build.
39
- public enum BuildSubset : Encodable {
39
+ public enum BuildSubset {
40
40
/// Represents the subset consisting of all products and of either all
41
41
/// targets or (if `includingTests` is false) just non-test targets.
42
42
case all( includingTests: Bool )
@@ -49,7 +49,7 @@ public struct PackageManager {
49
49
}
50
50
51
51
/// Parameters and options to apply during a build.
52
- public struct BuildParameters : Encodable {
52
+ public struct BuildParameters {
53
53
/// Whether to build for debug or release.
54
54
public var configuration : BuildConfiguration
55
55
@@ -76,17 +76,17 @@ public struct PackageManager {
76
76
77
77
/// Represents an overall purpose of the build, which affects such things
78
78
/// asoptimization and generation of debug symbols.
79
- public enum BuildConfiguration : String , Encodable {
79
+ public enum BuildConfiguration : String {
80
80
case debug, release
81
81
}
82
82
83
83
/// Represents the amount of detail in a build log.
84
- public enum BuildLogVerbosity : String , Encodable {
84
+ public enum BuildLogVerbosity : String {
85
85
case concise, verbose, debug
86
86
}
87
87
88
88
/// Represents the results of running a build.
89
- public struct BuildResult : Decodable {
89
+ public struct BuildResult {
90
90
/// Whether the build succeeded or failed.
91
91
public var succeeded : Bool
92
92
@@ -98,7 +98,7 @@ public struct PackageManager {
98
98
public var builtArtifacts : [ BuiltArtifact ]
99
99
100
100
/// Represents a single artifact produced during a build.
101
- public struct BuiltArtifact : Decodable {
101
+ public struct BuiltArtifact {
102
102
/// Full path of the built artifact in the local file system.
103
103
public var path : Path
104
104
@@ -108,7 +108,7 @@ public struct PackageManager {
108
108
/// Represents the kind of artifact that was built. The specific file
109
109
/// formats may vary from platform to platform — for example, on macOS
110
110
/// a dynamic library may in fact be built as a framework.
111
- public enum Kind : String , Decodable {
111
+ public enum Kind : String {
112
112
case executable, dynamicLibrary, staticLibrary
113
113
}
114
114
}
@@ -129,14 +129,14 @@ public struct PackageManager {
129
129
) throws -> TestResult {
130
130
// Ask the plugin host to run the specified tests, and wait for a response.
131
131
// FIXME: We'll want to make this asynchronous when there is back deployment support for it.
132
- return try sendMessageAndWaitForReply ( . testOperationRequest( subset: subset, parameters: parameters) ) {
132
+ return try sendMessageAndWaitForReply ( . testOperationRequest( subset: . init ( subset) , parameters: . init ( parameters) ) ) {
133
133
guard case . testOperationResponse( let result) = $0 else { return nil }
134
- return result
134
+ return . init ( result)
135
135
}
136
136
}
137
137
138
138
/// Specifies what tests in a package to run.
139
- public enum TestSubset : Encodable {
139
+ public enum TestSubset {
140
140
/// Represents all tests in the package.
141
141
case all
142
142
@@ -147,7 +147,7 @@ public struct PackageManager {
147
147
}
148
148
149
149
/// Parameters that control how the tests are run.
150
- public struct TestParameters : Encodable {
150
+ public struct TestParameters {
151
151
/// Whether to collect code coverage information while running the tests.
152
152
public var enableCodeCoverage : Bool
153
153
@@ -157,7 +157,7 @@ public struct PackageManager {
157
157
}
158
158
159
159
/// Represents the result of running unit tests.
160
- public struct TestResult : Decodable {
160
+ public struct TestResult {
161
161
/// Whether the test run succeeded or failed.
162
162
public var succeeded : Bool
163
163
@@ -171,24 +171,24 @@ public struct PackageManager {
171
171
172
172
/// Represents the results of running some or all of the tests in a
173
173
/// single test target.
174
- public struct TestTarget : Decodable {
174
+ public struct TestTarget {
175
175
public var name : String
176
176
public var testCases : [ TestCase ]
177
177
178
178
/// Represents the results of running some or all of the tests in
179
179
/// a single test case.
180
- public struct TestCase : Decodable {
180
+ public struct TestCase {
181
181
public var name : String
182
182
public var tests : [ Test ]
183
183
184
184
/// Represents the results of running a single test.
185
- public struct Test : Decodable {
185
+ public struct Test {
186
186
public var name : String
187
187
public var result : Result
188
188
public var duration : Double
189
189
190
190
/// Represents the result of running a single test.
191
- public enum Result : String , Decodable {
191
+ public enum Result : String {
192
192
case succeeded, skipped, failed
193
193
}
194
194
}
@@ -206,19 +206,19 @@ public struct PackageManager {
206
206
) throws -> SymbolGraphResult {
207
207
// Ask the plugin host for symbol graph information for the target, and wait for a response.
208
208
// FIXME: We'll want to make this asynchronous when there is back deployment support for it.
209
- return try sendMessageAndWaitForReply ( . symbolGraphRequest( targetName: target. name, options: options) ) {
209
+ return try sendMessageAndWaitForReply ( . symbolGraphRequest( targetName: target. name, options: . init ( options) ) ) {
210
210
guard case . symbolGraphResponse( let result) = $0 else { return nil }
211
- return result
211
+ return . init ( result)
212
212
}
213
213
}
214
214
215
215
/// Represents options for symbol graph generation.
216
- public struct SymbolGraphOptions : Encodable {
216
+ public struct SymbolGraphOptions {
217
217
/// The symbol graph will include symbols at this access level and higher.
218
218
public var minimumAccessLevel : AccessLevel
219
219
220
220
/// Represents a Swift access level.
221
- public enum AccessLevel : String , CaseIterable , Encodable {
221
+ public enum AccessLevel : String , CaseIterable {
222
222
case `private`, `fileprivate`, `internal`, `public`, `open`
223
223
}
224
224
@@ -236,13 +236,15 @@ public struct PackageManager {
236
236
}
237
237
238
238
/// Represents the result of symbol graph generation.
239
- public struct SymbolGraphResult : Decodable {
239
+ public struct SymbolGraphResult {
240
240
/// The directory that contains the symbol graph files for the target.
241
241
public var directoryPath : Path
242
242
}
243
-
243
+ }
244
+
245
+ fileprivate extension PackageManager {
244
246
/// Private helper function that sends a message to the host and waits for a reply. The reply handler should return nil for any reply message it doesn't recognize.
245
- fileprivate func sendMessageAndWaitForReply< T> ( _ message: PluginToHostMessage , replyHandler: ( HostToPluginMessage ) -> T ? ) throws -> T {
247
+ func sendMessageAndWaitForReply< T> ( _ message: PluginToHostMessage , replyHandler: ( HostToPluginMessage ) -> T ? ) throws -> T {
246
248
try pluginHostConnection. sendMessage ( message)
247
249
guard let reply = try pluginHostConnection. waitForNextMessage ( ) else {
248
250
throw PackageManagerProxyError . unspecified ( " internal error: unexpected lack of response message " )
@@ -264,3 +266,170 @@ public enum PackageManagerProxyError: Error {
264
266
/// An unspecified other kind of error from the Package Manager proxy.
265
267
case unspecified( _ message: String )
266
268
}
269
+
270
+ fileprivate extension PluginToHostMessage . BuildSubset {
271
+ init ( _ subset: PackageManager . BuildSubset ) {
272
+ switch subset {
273
+ case . all( let includingTests) :
274
+ self = . all( includingTests: includingTests)
275
+ case . product( let name) :
276
+ self = . product( name)
277
+ case . target( let name) :
278
+ self = . target( name)
279
+ }
280
+ }
281
+ }
282
+
283
+ fileprivate extension PluginToHostMessage . BuildParameters {
284
+ init ( _ parameters: PackageManager . BuildParameters ) {
285
+ self . configuration = . init( parameters. configuration)
286
+ self . logging = . init( parameters. logging)
287
+ self . otherCFlags = parameters. otherCFlags
288
+ self . otherCxxFlags = parameters. otherCxxFlags
289
+ self . otherSwiftcFlags = parameters. otherSwiftcFlags
290
+ self . otherLinkerFlags = parameters. otherLinkerFlags
291
+ }
292
+ }
293
+
294
+ fileprivate extension PluginToHostMessage . BuildParameters . Configuration {
295
+ init ( _ configuration: PackageManager . BuildConfiguration ) {
296
+ switch configuration {
297
+ case . debug:
298
+ self = . debug
299
+ case . release:
300
+ self = . release
301
+ }
302
+ }
303
+ }
304
+
305
+ fileprivate extension PluginToHostMessage . BuildParameters . LogVerbosity {
306
+ init ( _ verbosity: PackageManager . BuildLogVerbosity ) {
307
+ switch verbosity {
308
+ case . concise:
309
+ self = . concise
310
+ case . verbose:
311
+ self = . verbose
312
+ case . debug:
313
+ self = . debug
314
+ }
315
+ }
316
+ }
317
+
318
+ fileprivate extension PackageManager . BuildResult {
319
+ init ( _ result: HostToPluginMessage . BuildResult ) {
320
+ self . succeeded = result. succeeded
321
+ self . logText = result. logText
322
+ self . builtArtifacts = result. builtArtifacts. map { . init( $0) }
323
+ }
324
+ }
325
+
326
+ fileprivate extension PackageManager . BuildResult . BuiltArtifact {
327
+ init ( _ artifact: HostToPluginMessage . BuildResult . BuiltArtifact ) {
328
+ self . path = . init( artifact. path)
329
+ self . kind = . init( artifact. kind)
330
+ }
331
+ }
332
+
333
+ fileprivate extension PackageManager . BuildResult . BuiltArtifact . Kind {
334
+ init ( _ kind: HostToPluginMessage . BuildResult . BuiltArtifact . Kind ) {
335
+ switch kind {
336
+ case . executable:
337
+ self = . executable
338
+ case . dynamicLibrary:
339
+ self = . dynamicLibrary
340
+ case . staticLibrary:
341
+ self = . staticLibrary
342
+ }
343
+ }
344
+ }
345
+
346
+ fileprivate extension PluginToHostMessage . TestSubset {
347
+ init ( _ subset: PackageManager . TestSubset ) {
348
+ switch subset {
349
+ case . all:
350
+ self = . all
351
+ case . filtered( let regexes) :
352
+ self = . filtered( regexes)
353
+ }
354
+ }
355
+ }
356
+
357
+ fileprivate extension PluginToHostMessage . TestParameters {
358
+ init ( _ parameters: PackageManager . TestParameters ) {
359
+ self . enableCodeCoverage = parameters. enableCodeCoverage
360
+ }
361
+ }
362
+
363
+ fileprivate extension PackageManager . TestResult {
364
+ init ( _ result: HostToPluginMessage . TestResult ) {
365
+ self . succeeded = result. succeeded
366
+ self . testTargets = result. testTargets. map { . init( $0) }
367
+ self . codeCoverageDataFile = result. codeCoverageDataFile. map { . init( $0) }
368
+ }
369
+ }
370
+
371
+ fileprivate extension PackageManager . TestResult . TestTarget {
372
+ init ( _ testTarget: HostToPluginMessage . TestResult . TestTarget ) {
373
+ self . name = testTarget. name
374
+ self . testCases = testTarget. testCases. map { . init( $0) }
375
+ }
376
+ }
377
+
378
+ fileprivate extension PackageManager . TestResult . TestTarget . TestCase {
379
+ init ( _ testCase: HostToPluginMessage . TestResult . TestTarget . TestCase ) {
380
+ self . name = testCase. name
381
+ self . tests = testCase. tests. map { . init( $0) }
382
+ }
383
+ }
384
+
385
+ fileprivate extension PackageManager . TestResult . TestTarget . TestCase . Test {
386
+ init ( _ test: HostToPluginMessage . TestResult . TestTarget . TestCase . Test ) {
387
+ self . name = test. name
388
+ self . result = . init( test. result)
389
+ self . duration = test. duration
390
+ }
391
+ }
392
+
393
+ fileprivate extension PackageManager . TestResult . TestTarget . TestCase . Test . Result {
394
+ init ( _ result: HostToPluginMessage . TestResult . TestTarget . TestCase . Test . Result ) {
395
+ switch result {
396
+ case . succeeded:
397
+ self = . succeeded
398
+ case . skipped:
399
+ self = . skipped
400
+ case . failed:
401
+ self = . failed
402
+ }
403
+ }
404
+ }
405
+
406
+ fileprivate extension PluginToHostMessage . SymbolGraphOptions {
407
+ init ( _ options: PackageManager . SymbolGraphOptions ) {
408
+ self . minimumAccessLevel = . init( options. minimumAccessLevel)
409
+ self . includeSynthesized = options. includeSynthesized
410
+ self . includeSPI = options. includeSPI
411
+ }
412
+ }
413
+
414
+ fileprivate extension PluginToHostMessage . SymbolGraphOptions . AccessLevel {
415
+ init ( _ accessLevel: PackageManager . SymbolGraphOptions . AccessLevel ) {
416
+ switch accessLevel {
417
+ case . private:
418
+ self = . private
419
+ case . fileprivate:
420
+ self = . fileprivate
421
+ case . internal:
422
+ self = . internal
423
+ case . public:
424
+ self = . public
425
+ case . open:
426
+ self = . open
427
+ }
428
+ }
429
+ }
430
+
431
+ fileprivate extension PackageManager . SymbolGraphResult {
432
+ init ( _ result: HostToPluginMessage . SymbolGraphResult ) {
433
+ self . directoryPath = . init( result. directoryPath)
434
+ }
435
+ }
0 commit comments