@@ -294,6 +294,15 @@ public class SwiftTool {
294
294
/// Path to the build directory.
295
295
let buildPath : AbsolutePath
296
296
297
+ /// Path to the shared security directory
298
+ let sharedSecurityDirectory : AbsolutePath ?
299
+
300
+ /// Path to the shared cache directory
301
+ let sharedCacheDirectory : AbsolutePath ?
302
+
303
+ /// Path to the shared configuration directory
304
+ let sharedConfigurationDirectory : AbsolutePath ?
305
+
297
306
/// The process set to hold the launched processes. These will be terminated on any signal
298
307
/// received by the swift tools.
299
308
let processSet : ProcessSet
@@ -333,7 +342,7 @@ public class SwiftTool {
333
342
self . observabilityScope. emit ( error: " couldn't determine the current working directory " )
334
343
throw ExitCode . failure
335
344
}
336
- originalWorkingDirectory = cwd
345
+ self . originalWorkingDirectory = cwd
337
346
338
347
do {
339
348
try Self . postprocessArgParserResult ( options: options, observabilityScope: self . observabilityScope)
@@ -416,6 +425,11 @@ public class SwiftTool {
416
425
customBuildPath ??
417
426
( packageRoot ?? cwd) . appending ( component: " .build " )
418
427
428
+ // make sure common directories are created
429
+ self . sharedSecurityDirectory = try getSharedSecurityDirectory ( options: self . options, observabilityScope: self . observabilityScope)
430
+ self . sharedConfigurationDirectory = try getSharedConfigurationDirectory ( options: self . options, observabilityScope: self . observabilityScope)
431
+ self . sharedCacheDirectory = try getSharedCacheDirectory ( options: self . options, observabilityScope: self . observabilityScope)
432
+
419
433
// set verbosity globals.
420
434
// TODO: get rid of this global settings in TSC
421
435
switch self . logLevel {
@@ -492,7 +506,7 @@ public class SwiftTool {
492
506
}
493
507
494
508
func getMirrorsConfig( sharedConfigurationDirectory: AbsolutePath ? = nil ) throws -> Workspace . Configuration . Mirrors {
495
- let sharedConfigurationDirectory = try sharedConfigurationDirectory ?? self . getSharedConfigurationDirectory ( )
509
+ let sharedConfigurationDirectory = sharedConfigurationDirectory ?? self . sharedConfigurationDirectory
496
510
let sharedMirrorFile = sharedConfigurationDirectory. map { Workspace . DefaultLocations. mirrorsConfigurationFile ( at: $0) }
497
511
return try . init(
498
512
localMirrorFile: self . mirrorsConfigFile ( ) ,
@@ -537,7 +551,7 @@ public class SwiftTool {
537
551
func getRegistriesConfig( sharedConfigurationDirectory: AbsolutePath ? = nil ) throws -> Workspace . Configuration . Registries {
538
552
let localRegistriesFile = try Workspace . DefaultLocations. registriesConfigurationFile ( forRootPackage: self . getPackageRoot ( ) )
539
553
540
- let sharedConfigurationDirectory = try sharedConfigurationDirectory ?? self . getSharedConfigurationDirectory ( )
554
+ let sharedConfigurationDirectory = sharedConfigurationDirectory ?? self . sharedConfigurationDirectory
541
555
let sharedRegistriesFile = sharedConfigurationDirectory. map {
542
556
Workspace . DefaultLocations. registriesConfigurationFile ( at: $0)
543
557
}
@@ -607,56 +621,6 @@ public class SwiftTool {
607
621
return providers
608
622
}
609
623
610
- private func getSharedCacheDirectory( ) throws -> AbsolutePath ? {
611
- if let explicitCachePath = options. cachePath {
612
- // Create the explicit cache path if necessary
613
- if !localFileSystem. exists ( explicitCachePath) {
614
- try localFileSystem. createDirectory ( explicitCachePath, recursive: true )
615
- }
616
- return explicitCachePath
617
- }
618
-
619
- do {
620
- return try localFileSystem. getOrCreateSwiftPMCacheDirectory ( )
621
- } catch {
622
- self . observabilityScope. emit ( warning: " Failed creating default cache location, \( error) " )
623
- return . none
624
- }
625
- }
626
-
627
- private func getSharedConfigurationDirectory( ) throws -> AbsolutePath ? {
628
- if let explicitConfigPath = options. configPath {
629
- // Create the explicit config path if necessary
630
- if !localFileSystem. exists ( explicitConfigPath) {
631
- try localFileSystem. createDirectory ( explicitConfigPath, recursive: true )
632
- }
633
- return explicitConfigPath
634
- }
635
-
636
- do {
637
- return try localFileSystem. getOrCreateSwiftPMConfigDirectory ( )
638
- } catch {
639
- self . observabilityScope. emit ( warning: " Failed creating default configuration location, \( error) " )
640
- return . none
641
- }
642
- }
643
-
644
- private func getSharedSecurityDirectory( ) throws -> AbsolutePath ? {
645
- do {
646
- let fileSystem = localFileSystem
647
- let sharedSecurityDirectory = fileSystem. swiftPMSecurityDirectory
648
- if !fileSystem. exists ( sharedSecurityDirectory) {
649
- try fileSystem. createDirectory ( sharedSecurityDirectory, recursive: true )
650
- }
651
- // And make sure we can write files (locking the directory writes a lock file)
652
- try fileSystem. withLock ( on: sharedSecurityDirectory, type: . exclusive) { }
653
- return sharedSecurityDirectory
654
- } catch {
655
- self . observabilityScope. emit ( warning: " Failed creating shared security directory: \( error) " )
656
- return . none
657
- }
658
- }
659
-
660
624
/// Returns the currently active workspace.
661
625
func getActiveWorkspace( ) throws -> Workspace {
662
626
if let workspace = _workspace {
@@ -665,28 +629,25 @@ public class SwiftTool {
665
629
666
630
let delegate = ToolWorkspaceDelegate ( self . outputStream, logLevel: self . logLevel, observabilityScope: self . observabilityScope)
667
631
let provider = GitRepositoryProvider ( processSet: processSet)
668
- let sharedSecurityDirectory = try self . getSharedSecurityDirectory ( )
669
- let sharedCacheDirectory = try self . getSharedCacheDirectory ( )
670
- let sharedConfigurationDirectory = try self . getSharedConfigurationDirectory ( )
671
632
let isXcodeBuildSystemEnabled = self . options. buildSystem == . xcode
672
633
let workspace = try Workspace (
673
634
fileSystem: localFileSystem,
674
635
location: . init(
675
- workingDirectory: buildPath,
636
+ workingDirectory: self . buildPath,
676
637
editsDirectory: self . editsDirectory ( ) ,
677
638
resolvedVersionsFile: self . resolvedVersionsFile ( ) ,
678
- sharedSecurityDirectory: sharedSecurityDirectory,
679
- sharedCacheDirectory: sharedCacheDirectory,
680
- sharedConfigurationDirectory: sharedConfigurationDirectory
639
+ sharedSecurityDirectory: self . sharedSecurityDirectory,
640
+ sharedCacheDirectory: self . sharedCacheDirectory,
641
+ sharedConfigurationDirectory: self . sharedConfigurationDirectory
681
642
) ,
682
- mirrors: self . getMirrorsConfig ( sharedConfigurationDirectory: sharedConfigurationDirectory) . mirrors,
683
- registries: try self . getRegistriesConfig ( sharedConfigurationDirectory: sharedConfigurationDirectory) . configuration,
643
+ mirrors: self . getMirrorsConfig ( sharedConfigurationDirectory: self . sharedConfigurationDirectory) . mirrors,
644
+ registries: try self . getRegistriesConfig ( sharedConfigurationDirectory: self . sharedConfigurationDirectory) . configuration,
684
645
authorizationProvider: self . getAuthorizationProvider ( ) ,
685
646
customManifestLoader: self . getManifestLoader ( ) , // FIXME: doe we really need to customize it?
686
647
customRepositoryProvider: provider, // FIXME: doe we really need to customize it?
687
648
additionalFileRules: isXcodeBuildSystemEnabled ? FileRuleDescription . xcbuildFileTypes : FileRuleDescription . swiftpmFileTypes,
688
- resolverUpdateEnabled: !options. skipDependencyUpdate,
689
- resolverPrefetchingEnabled: options. shouldEnableResolverPrefetching,
649
+ resolverUpdateEnabled: !self . options. skipDependencyUpdate,
650
+ resolverPrefetchingEnabled: self . options. shouldEnableResolverPrefetching,
690
651
resolverFingerprintCheckingMode: self . options. resolverFingerprintCheckingMode,
691
652
sharedRepositoriesCacheEnabled: self . options. useRepositoriesCache,
692
653
delegate: delegate
@@ -1011,7 +972,7 @@ public class SwiftTool {
1011
972
case ( false , . local) :
1012
973
cachePath = self . buildPath
1013
974
case ( false , . shared) :
1014
- cachePath = try self . getSharedCacheDirectory ( ) . map { Workspace . DefaultLocations. manifestsDirectory ( at: $0) }
975
+ cachePath = self . sharedCacheDirectory . map { Workspace . DefaultLocations. manifestsDirectory ( at: $0) }
1015
976
}
1016
977
1017
978
var extraManifestFlags = self . options. manifestFlags
@@ -1062,6 +1023,61 @@ private func getEnvBuildPath(workingDir: AbsolutePath) -> AbsolutePath? {
1062
1023
return AbsolutePath ( env, relativeTo: workingDir)
1063
1024
}
1064
1025
1026
+
1027
+ private func getSharedSecurityDirectory( options: SwiftToolOptions , observabilityScope: ObservabilityScope ) throws -> AbsolutePath ? {
1028
+ if let explicitSecurityPath = options. securityPath {
1029
+ // Create the explicit security path if necessary
1030
+ if !localFileSystem. exists ( explicitSecurityPath) {
1031
+ try localFileSystem. createDirectory ( explicitSecurityPath, recursive: true )
1032
+ }
1033
+ return explicitSecurityPath
1034
+ }
1035
+
1036
+ do {
1037
+ let sharedSecurityDirectory = try localFileSystem. getOrCreateSwiftPMSecurityDirectory ( )
1038
+ // And make sure we can write files (locking the directory writes a lock file)
1039
+ try localFileSystem. withLock ( on: sharedSecurityDirectory, type: . exclusive) { }
1040
+ return sharedSecurityDirectory
1041
+ } catch {
1042
+ observabilityScope. emit ( warning: " Failed creating default security location, \( error) " )
1043
+ return . none
1044
+ }
1045
+ }
1046
+
1047
+ private func getSharedConfigurationDirectory( options: SwiftToolOptions , observabilityScope: ObservabilityScope ) throws -> AbsolutePath ? {
1048
+ if let explicitConfigPath = options. configPath {
1049
+ // Create the explicit config path if necessary
1050
+ if !localFileSystem. exists ( explicitConfigPath) {
1051
+ try localFileSystem. createDirectory ( explicitConfigPath, recursive: true )
1052
+ }
1053
+ return explicitConfigPath
1054
+ }
1055
+
1056
+ do {
1057
+ return try localFileSystem. getOrCreateSwiftPMConfigurationDirectory ( observabilityScope: observabilityScope)
1058
+ } catch {
1059
+ observabilityScope. emit ( warning: " Failed creating default configuration location, \( error) " )
1060
+ return . none
1061
+ }
1062
+ }
1063
+
1064
+ private func getSharedCacheDirectory( options: SwiftToolOptions , observabilityScope: ObservabilityScope ) throws -> AbsolutePath ? {
1065
+ if let explicitCachePath = options. cachePath {
1066
+ // Create the explicit cache path if necessary
1067
+ if !localFileSystem. exists ( explicitCachePath) {
1068
+ try localFileSystem. createDirectory ( explicitCachePath, recursive: true )
1069
+ }
1070
+ return explicitCachePath
1071
+ }
1072
+
1073
+ do {
1074
+ return try localFileSystem. getOrCreateSwiftPMCacheDirectory ( )
1075
+ } catch {
1076
+ observabilityScope. emit ( warning: " Failed creating default cache location, \( error) " )
1077
+ return . none
1078
+ }
1079
+ }
1080
+
1065
1081
/// A wrapper to hold the build system so we can use it inside
1066
1082
/// the int. handler without requiring to initialize it.
1067
1083
final class BuildSystemRef {
0 commit comments