@@ -54,16 +54,22 @@ public struct ToolWorkspaceConfiguration {
54
54
let wantsMultipleTestProducts : Bool
55
55
let wantsREPLProduct : Bool
56
56
57
- public init ( wantsMultipleTestProducts: Bool = false ,
58
- wantsREPLProduct: Bool = false )
59
- {
57
+ public init (
58
+ wantsMultipleTestProducts: Bool = false ,
59
+ wantsREPLProduct: Bool = false
60
+ ) {
60
61
self . wantsMultipleTestProducts = wantsMultipleTestProducts
61
62
self . wantsREPLProduct = wantsREPLProduct
62
63
}
63
64
}
64
65
65
- public typealias WorkspaceDelegateProvider = ( _ observabilityScope: ObservabilityScope , _ outputHandler: @escaping ( String , Bool ) -> Void , _ progressHandler: @escaping ( Int64 , Int64 , String ? ) -> Void ) -> WorkspaceDelegate
66
- public typealias WorkspaceLoaderProvider = ( _ fileSystem: FileSystem , _ observabilityScope: ObservabilityScope ) -> WorkspaceLoader
66
+ public typealias WorkspaceDelegateProvider = (
67
+ _ observabilityScope: ObservabilityScope ,
68
+ _ outputHandler: @escaping ( String , Bool ) -> Void ,
69
+ _ progressHandler: @escaping ( Int64 , Int64 , String ? ) -> Void
70
+ ) -> WorkspaceDelegate
71
+ public typealias WorkspaceLoaderProvider = ( _ fileSystem: FileSystem , _ observabilityScope: ObservabilityScope )
72
+ -> WorkspaceLoader
67
73
68
74
public protocol SwiftCommand : ParsableCommand {
69
75
var globalOptions : GlobalOptions { get }
@@ -105,7 +111,7 @@ extension SwiftCommand {
105
111
public static var _errorLabel : String { " error " }
106
112
107
113
public var toolWorkspaceConfiguration : ToolWorkspaceConfiguration {
108
- return . init( )
114
+ . init( )
109
115
}
110
116
}
111
117
@@ -137,7 +143,8 @@ public final class SwiftTool {
137
143
let packages : [ AbsolutePath ]
138
144
139
145
if let workspace = options. locations. multirootPackageDataFile {
140
- packages = try self . workspaceLoaderProvider ( self . fileSystem, self . observabilityScope) . load ( workspace: workspace)
146
+ packages = try self . workspaceLoaderProvider ( self . fileSystem, self . observabilityScope)
147
+ . load ( workspace: workspace)
141
148
} else {
142
149
packages = [ try getPackageRoot ( ) ]
143
150
}
@@ -201,17 +208,34 @@ public final class SwiftTool {
201
208
/// Create an instance of this tool.
202
209
///
203
210
/// - parameter options: The command line options to be passed to this tool.
204
- public convenience init ( options: GlobalOptions , toolWorkspaceConfiguration: ToolWorkspaceConfiguration = . init( ) , workspaceDelegateProvider: @escaping WorkspaceDelegateProvider , workspaceLoaderProvider: @escaping WorkspaceLoaderProvider ) throws {
211
+ public convenience init (
212
+ options: GlobalOptions ,
213
+ toolWorkspaceConfiguration: ToolWorkspaceConfiguration = . init( ) ,
214
+ workspaceDelegateProvider: @escaping WorkspaceDelegateProvider ,
215
+ workspaceLoaderProvider: @escaping WorkspaceLoaderProvider
216
+ ) throws {
205
217
// output from background activities goes to stderr, this includes diagnostics and output from build operations,
206
218
// package resolution that take place as part of another action
207
219
// CLI commands that have user facing output, use stdout directly to emit the final result
208
220
// this means that the build output from "swift build" goes to stdout
209
221
// but the build output from "swift test" goes to stderr, while the tests output go to stdout
210
- try self . init ( outputStream: TSCBasic . stderrStream, options: options, toolWorkspaceConfiguration: toolWorkspaceConfiguration, workspaceDelegateProvider: workspaceDelegateProvider, workspaceLoaderProvider: workspaceLoaderProvider)
222
+ try self . init (
223
+ outputStream: TSCBasic . stderrStream,
224
+ options: options,
225
+ toolWorkspaceConfiguration: toolWorkspaceConfiguration,
226
+ workspaceDelegateProvider: workspaceDelegateProvider,
227
+ workspaceLoaderProvider: workspaceLoaderProvider
228
+ )
211
229
}
212
230
213
231
// marked internal for testing
214
- internal init ( outputStream: OutputByteStream , options: GlobalOptions , toolWorkspaceConfiguration: ToolWorkspaceConfiguration , workspaceDelegateProvider: @escaping WorkspaceDelegateProvider , workspaceLoaderProvider: @escaping WorkspaceLoaderProvider ) throws {
232
+ internal init (
233
+ outputStream: OutputByteStream ,
234
+ options: GlobalOptions ,
235
+ toolWorkspaceConfiguration: ToolWorkspaceConfiguration ,
236
+ workspaceDelegateProvider: @escaping WorkspaceDelegateProvider ,
237
+ workspaceLoaderProvider: @escaping WorkspaceLoaderProvider
238
+ ) throws {
215
239
self . fileSystem = localFileSystem
216
240
// first, bootstrap the observability system
217
241
self . logLevel = options. logging. logLevel
@@ -283,7 +307,8 @@ public final class SwiftTool {
283
307
var action = sigaction ( )
284
308
action. __sigaction_handler = unsafeBitCast (
285
309
SIG_DFL,
286
- to: sigaction. __Unnamed_union___sigaction_handler. self)
310
+ to: sigaction. __Unnamed_union___sigaction_handler. self
311
+ )
287
312
sigaction ( SIGINT, & action, nil )
288
313
kill ( getpid ( ) , SIGINT)
289
314
#endif
@@ -308,11 +333,15 @@ public final class SwiftTool {
308
333
309
334
// make sure common directories are created
310
335
self . sharedSecurityDirectory = try getSharedSecurityDirectory ( options: options, fileSystem: fileSystem)
311
- self . sharedConfigurationDirectory = try getSharedConfigurationDirectory ( options: options, fileSystem: fileSystem)
312
- self . sharedCacheDirectory = try getSharedCacheDirectory ( options: options, fileSystem: fileSystem)
313
- self . sharedCrossCompilationDestinationsDirectory = try fileSystem. getSharedCrossCompilationDestinationsDirectory (
314
- explicitDirectory: options. locations. crossCompilationDestinationsDirectory
336
+ self . sharedConfigurationDirectory = try getSharedConfigurationDirectory (
337
+ options: options,
338
+ fileSystem: fileSystem
315
339
)
340
+ self . sharedCacheDirectory = try getSharedCacheDirectory ( options: options, fileSystem: fileSystem)
341
+ self . sharedCrossCompilationDestinationsDirectory = try fileSystem
342
+ . getSharedCrossCompilationDestinationsDirectory (
343
+ explicitDirectory: options. locations. crossCompilationDestinationsDirectory
344
+ )
316
345
317
346
// set global process logging handler
318
347
Process . loggingHandler = { self . observabilityScope. emit ( debug: $0) }
@@ -334,12 +363,18 @@ public final class SwiftTool {
334
363
// --enable-test-discovery should never be called on darwin based platforms
335
364
#if canImport(Darwin)
336
365
if options. build. enableTestDiscovery {
337
- observabilityScope. emit ( warning: " '--enable-test-discovery' option is deprecated; tests are automatically discovered on all platforms " )
366
+ observabilityScope
367
+ . emit (
368
+ warning: " '--enable-test-discovery' option is deprecated; tests are automatically discovered on all platforms "
369
+ )
338
370
}
339
371
#endif
340
372
341
373
if options. caching. shouldDisableManifestCaching {
342
- observabilityScope. emit ( warning: " '--disable-package-manifest-caching' option is deprecated; use '--manifest-caching' instead " )
374
+ observabilityScope
375
+ . emit (
376
+ warning: " '--disable-package-manifest-caching' option is deprecated; use '--manifest-caching' instead "
377
+ )
343
378
}
344
379
345
380
if let _ = options. security. netrcFilePath, options. security. netrc == false {
@@ -357,7 +392,11 @@ public final class SwiftTool {
357
392
return workspace
358
393
}
359
394
360
- let delegate = self . workspaceDelegateProvider ( self . observabilityScope, self . observabilityHandler. print, self . observabilityHandler. progress)
395
+ let delegate = self . workspaceDelegateProvider (
396
+ self . observabilityScope,
397
+ self . observabilityHandler. print,
398
+ self . observabilityHandler. progress
399
+ )
361
400
let isXcodeBuildSystemEnabled = self . options. build. buildSystem == . xcode
362
401
let workspace = try Workspace (
363
402
fileSystem: self . fileSystem,
@@ -417,13 +456,25 @@ public final class SwiftTool {
417
456
if let multiRootPackageDataFile = options. locations. multirootPackageDataFile {
418
457
// migrate from legacy location
419
458
let legacyPath = multiRootPackageDataFile. appending ( components: " xcshareddata " , " swiftpm " , " config " )
420
- let newPath = Workspace . DefaultLocations. mirrorsConfigurationFile ( at: multiRootPackageDataFile. appending ( components: " xcshareddata " , " swiftpm " , " configuration " ) )
421
- return try Workspace . migrateMirrorsConfiguration ( from: legacyPath, to: newPath, observabilityScope: observabilityScope)
459
+ let newPath = Workspace . DefaultLocations
460
+ . mirrorsConfigurationFile (
461
+ at: multiRootPackageDataFile
462
+ . appending ( components: " xcshareddata " , " swiftpm " , " configuration " )
463
+ )
464
+ return try Workspace . migrateMirrorsConfiguration (
465
+ from: legacyPath,
466
+ to: newPath,
467
+ observabilityScope: observabilityScope
468
+ )
422
469
} else {
423
470
// migrate from legacy location
424
471
let legacyPath = try self . getPackageRoot ( ) . appending ( components: " .swiftpm " , " config " )
425
472
let newPath = try Workspace . DefaultLocations. mirrorsConfigurationFile ( forRootPackage: self . getPackageRoot ( ) )
426
- return try Workspace . migrateMirrorsConfiguration ( from: legacyPath, to: newPath, observabilityScope: observabilityScope)
473
+ return try Workspace . migrateMirrorsConfiguration (
474
+ from: legacyPath,
475
+ to: newPath,
476
+ observabilityScope: observabilityScope
477
+ )
427
478
}
428
479
}
429
480
@@ -441,7 +492,10 @@ public final class SwiftTool {
441
492
authorization. keychain = self . options. security. keychain ? . enabled : . disabled
442
493
#endif
443
494
444
- return try authorization. makeAuthorizationProvider ( fileSystem: self . fileSystem, observabilityScope: self . observabilityScope)
495
+ return try authorization. makeAuthorizationProvider (
496
+ fileSystem: self . fileSystem,
497
+ observabilityScope: self . observabilityScope
498
+ )
445
499
}
446
500
447
501
public func getRegistryAuthorizationProvider( ) throws -> AuthorizationProvider ? {
@@ -457,7 +511,10 @@ public final class SwiftTool {
457
511
authorization. keychain = self . options. security. forceNetrc ? . disabled : . enabled
458
512
#endif
459
513
460
- return try authorization. makeRegistryAuthorizationProvider ( fileSystem: self . fileSystem, observabilityScope: self . observabilityScope)
514
+ return try authorization. makeRegistryAuthorizationProvider (
515
+ fileSystem: self . fileSystem,
516
+ observabilityScope: self . observabilityScope
517
+ )
461
518
}
462
519
463
520
/// Resolve the dependencies.
@@ -481,7 +538,8 @@ public final class SwiftTool {
481
538
/// Fetch and load the complete package graph.
482
539
///
483
540
/// - Parameters:
484
- /// - explicitProduct: The product specified on the command line to a “swift run” or “swift build” command. This allows executables from dependencies to be run directly without having to hook them up to any particular target.
541
+ /// - explicitProduct: The product specified on the command line to a “swift run” or “swift build” command. This
542
+ /// allows executables from dependencies to be run directly without having to hook them up to any particular target.
485
543
@discardableResult
486
544
public func loadPackageGraph(
487
545
explicitProduct: String ? = nil ,
@@ -527,15 +585,15 @@ public final class SwiftTool {
527
585
528
586
/// Returns the user toolchain to compile the actual product.
529
587
public func getDestinationToolchain( ) throws -> UserToolchain {
530
- return try _destinationToolchain. get ( )
588
+ try _destinationToolchain. get ( )
531
589
}
532
590
533
591
public func getHostToolchain( ) throws -> UserToolchain {
534
- return try _hostToolchain. get ( )
592
+ try _hostToolchain. get ( )
535
593
}
536
594
537
595
func getManifestLoader( ) throws -> ManifestLoader {
538
- return try _manifestLoader. get ( )
596
+ try _manifestLoader. get ( )
539
597
}
540
598
541
599
public func canUseCachedBuildManifest( ) throws -> Bool {
@@ -555,7 +613,7 @@ public final class SwiftTool {
555
613
// Perform steps for build manifest caching if we can enabled it.
556
614
//
557
615
// FIXME: We don't add edited packages in the package structure command yet (SR-11254).
558
- let hasEditedPackages = try self . getActiveWorkspace ( ) . state. dependencies. contains ( where: { $0 . isEdited } )
616
+ let hasEditedPackages = try self . getActiveWorkspace ( ) . state. dependencies. contains ( where: \ . isEdited)
559
617
if hasEditedPackages {
560
618
return false
561
619
}
@@ -654,9 +712,24 @@ public final class SwiftTool {
654
712
655
713
// Create custom toolchain if present.
656
714
if let customDestination = options. locations. customCompileDestination {
657
- destination = try Destination ( fromFile: customDestination, fileSystem: fileSystem)
658
- } else if let target = options. build. customCompileTriple,
659
- let targetDestination = Destination . defaultDestination ( for: target, host: hostDestination) {
715
+ let destinations = try Destination . decode (
716
+ fromFile: customDestination,
717
+ fileSystem: fileSystem,
718
+ observabilityScope: observabilityScope
719
+ )
720
+ if destinations. count == 1 {
721
+ destination = destinations [ 0 ]
722
+ } else if destinations. count > 1 ,
723
+ let triple = options. build. customCompileTriple,
724
+ let matchingDestination = destinations. first ( where: { $0. targetTriple == triple } )
725
+ {
726
+ destination = matchingDestination
727
+ } else {
728
+ return . failure( DestinationError . noDestinationsDecoded ( customDestination) )
729
+ }
730
+ } else if let triple = options. build. customCompileTriple,
731
+ let targetDestination = Destination . defaultDestination ( for: triple, host: hostDestination)
732
+ {
660
733
destination = targetDestination
661
734
} else if let destinationSelector = options. build. crossCompilationDestinationSelector {
662
735
destination = try DestinationsBundle . selectDestination (
@@ -678,7 +751,7 @@ public final class SwiftTool {
678
751
destination. targetTriple = triple
679
752
}
680
753
if let binDir = options. build. customCompileToolchain {
681
- destination. toolchainBinDir = binDir. appending ( components: " usr " , " bin " )
754
+ destination. add ( toolsetRootPath : binDir. appending ( components: " usr " , " bin " ) )
682
755
}
683
756
if let sdk = options. build. customCompileSDK {
684
757
destination. sdkRootDir = sdk
@@ -886,8 +959,8 @@ extension BuildOptions.TargetDependencyImportCheckingMode {
886
959
}
887
960
}
888
961
889
- public extension Basics . Diagnostic {
890
- static func mutuallyExclusiveArgumentsError( arguments: [ String ] ) -> Self {
962
+ extension Basics . Diagnostic {
963
+ public static func mutuallyExclusiveArgumentsError( arguments: [ String ] ) -> Self {
891
964
. error( arguments. map { " ' \( $0) ' " } . spm_localizedJoin ( type: . conjunction) + " are mutually exclusive " )
892
965
}
893
966
}
0 commit comments