@@ -452,42 +452,63 @@ public class SwiftTool {
452
452
}
453
453
}
454
454
455
- func editablesPath( ) throws -> AbsolutePath {
455
+ private func editsDirectory( ) throws -> AbsolutePath {
456
+ // TODO: replace multiroot-data-file with explicit overrides
456
457
if let multiRootPackageDataFile = options. multirootPackageDataFile {
457
458
return multiRootPackageDataFile. appending ( component: " Packages " )
458
459
}
459
- return try getPackageRoot ( ) . appending ( component : " Packages " )
460
+ return try Workspace . DefaultLocations . editsDirectory ( forRootPackage : self . getPackageRoot ( ) )
460
461
}
461
462
462
- func resolvedVersionsFilePath( ) throws -> AbsolutePath {
463
+ private func resolvedVersionsFile( ) throws -> AbsolutePath {
464
+ // TODO: replace multiroot-data-file with explicit overrides
463
465
if let multiRootPackageDataFile = options. multirootPackageDataFile {
464
466
return multiRootPackageDataFile. appending ( components: " xcshareddata " , " swiftpm " , " Package.resolved " )
465
467
}
466
- return try getPackageRoot ( ) . appending ( component : " Package.resolved " )
468
+ return try Workspace . DefaultLocations . resolvedVersionsFile ( forRootPackage : self . getPackageRoot ( ) )
467
469
}
468
470
469
- func mirrorsConfigFilePath( ) throws -> AbsolutePath {
471
+ func getMirrorsConfig( sharedConfigurationDirectory: AbsolutePath ? = nil ) throws -> Workspace . Configuration . Mirrors {
472
+ let sharedConfigurationDirectory = try sharedConfigurationDirectory ?? self . getSharedConfigurationDirectory ( )
473
+ let sharedMirrorFile = sharedConfigurationDirectory. map { Workspace . DefaultLocations. mirrorsConfigurationFile ( at: $0) }
474
+ return try . init(
475
+ localMirrorFile: self . mirrorsConfigFile ( ) ,
476
+ sharedMirrorFile: sharedMirrorFile,
477
+ fileSystem: localFileSystem
478
+ )
479
+ }
480
+
481
+ private func mirrorsConfigFile( ) throws -> AbsolutePath {
482
+ // TODO: does this make sense now that we a global configuration as well? or should we at least rename it?
470
483
// Look for the override in the environment.
471
484
if let envPath = ProcessEnv . vars [ " SWIFTPM_MIRROR_CONFIG " ] {
472
485
return try AbsolutePath ( validating: envPath)
473
486
}
474
487
475
488
// Otherwise, use the default path.
489
+ // TODO: replace multiroot-data-file with explicit overrides
476
490
if let multiRootPackageDataFile = options. multirootPackageDataFile {
477
- return multiRootPackageDataFile. appending ( components: " xcshareddata " , " swiftpm " , " config " )
491
+ // migrate from legacy location
492
+ let legacyPath = multiRootPackageDataFile. appending ( components: " xcshareddata " , " swiftpm " , " config " )
493
+ let newPath = multiRootPackageDataFile. appending ( components: " xcshareddata " , " swiftpm " , " configuration " , " mirrors.json " )
494
+ if localFileSystem. exists ( legacyPath) {
495
+ try localFileSystem. createDirectory ( newPath. parentDirectory, recursive: true )
496
+ try localFileSystem. move ( from: legacyPath, to: newPath)
497
+ }
498
+ return newPath
478
499
}
479
- return try getPackageRoot ( ) . appending ( components: " .swiftpm " , " config " )
480
- }
481
500
482
- func getMirrorsConfig( ) throws -> Workspace . Configuration {
483
- return try _mirrorsConfig. get ( )
501
+ // migrate from legacy location
502
+ let legacyPath = try self . getPackageRoot ( ) . appending ( components: " .swiftpm " , " config " )
503
+ let newPath = try Workspace . DefaultLocations. mirrorsConfigurationFile ( forRootPackage: self . getPackageRoot ( ) )
504
+ if localFileSystem. exists ( legacyPath) {
505
+ try localFileSystem. createDirectory ( newPath. parentDirectory, recursive: true )
506
+ try localFileSystem. move ( from: legacyPath, to: newPath)
507
+ }
508
+ return newPath
484
509
}
485
510
486
- private lazy var _mirrorsConfig : Result < Workspace . Configuration , Swift . Error > = {
487
- return Result ( catching: { try Workspace . Configuration ( path: try mirrorsConfigFilePath ( ) , fileSystem: localFileSystem) } )
488
- } ( )
489
-
490
- func netrcFilePath( ) throws -> AbsolutePath ? {
511
+ private func netrcFilePath( ) throws -> AbsolutePath ? {
491
512
guard options. netrc ||
492
513
options. netrcFilePath != nil ||
493
514
options. netrcOptional else { return nil }
@@ -499,43 +520,43 @@ public class SwiftTool {
499
520
throw ExitCode . failure
500
521
} else {
501
522
diagnostics. emit ( warning: " Did not find optional .netrc file at \( resolvedPath. pathString) . " )
502
- return nil
523
+ return . none
503
524
}
504
525
}
505
526
return resolvedPath
506
527
}
507
528
508
- private func getCachePath ( fileSystem : FileSystem = localFileSystem ) throws -> AbsolutePath ? {
529
+ private func getSharedCacheDirectory ( ) throws -> AbsolutePath ? {
509
530
if let explicitCachePath = options. cachePath {
510
531
// Create the explicit cache path if necessary
511
- if !fileSystem . exists ( explicitCachePath) {
512
- try fileSystem . createDirectory ( explicitCachePath, recursive: true )
532
+ if !localFileSystem . exists ( explicitCachePath) {
533
+ try localFileSystem . createDirectory ( explicitCachePath, recursive: true )
513
534
}
514
535
return explicitCachePath
515
536
}
516
537
517
538
do {
518
- return try fileSystem . getOrCreateSwiftPMCacheDirectory ( )
539
+ return try localFileSystem . getOrCreateSwiftPMCacheDirectory ( )
519
540
} catch {
520
- self . diagnostics. emit ( warning: " Failed creating default cache locations , \( error) " )
521
- return nil
541
+ self . diagnostics. emit ( warning: " Failed creating default cache location , \( error) " )
542
+ return . none
522
543
}
523
544
}
524
545
525
- private func getConfigPath ( fileSystem : FileSystem = localFileSystem ) throws -> AbsolutePath ? {
546
+ private func getSharedConfigurationDirectory ( ) throws -> AbsolutePath ? {
526
547
if let explicitConfigPath = options. configPath {
527
548
// Create the explicit config path if necessary
528
- if !fileSystem . exists ( explicitConfigPath) {
529
- try fileSystem . createDirectory ( explicitConfigPath, recursive: true )
549
+ if !localFileSystem . exists ( explicitConfigPath) {
550
+ try localFileSystem . createDirectory ( explicitConfigPath, recursive: true )
530
551
}
531
552
return explicitConfigPath
532
553
}
533
554
534
555
do {
535
- return try fileSystem . getOrCreateSwiftPMConfigDirectory ( )
556
+ return try localFileSystem . getOrCreateSwiftPMConfigDirectory ( )
536
557
} catch {
537
- self . diagnostics. emit ( warning: " Failed creating default config locations , \( error) " )
538
- return nil
558
+ self . diagnostics. emit ( warning: " Failed creating default configuration location , \( error) " )
559
+ return . none
539
560
}
540
561
}
541
562
@@ -548,25 +569,27 @@ public class SwiftTool {
548
569
let isVerbose = options. verbosity != 0
549
570
let delegate = ToolWorkspaceDelegate ( self . stdoutStream, isVerbose: isVerbose, diagnostics: diagnostics)
550
571
let provider = GitRepositoryProvider ( processSet: processSet)
551
- let cachePath = self . options . useRepositoriesCache ? try self . getCachePath ( ) : . none
552
- _ = try self . getConfigPath ( ) // TODO: actually use this in the workspace
572
+ let sharedCacheDirectory = try self . getSharedCacheDirectory ( )
573
+ let sharedConfigurationDirectory = try self . getSharedConfigurationDirectory ( )
553
574
let isXcodeBuildSystemEnabled = self . options. buildSystem == . xcode
554
575
let workspace = try Workspace (
555
576
fileSystem: localFileSystem,
556
577
location: . init(
557
578
workingDirectory: buildPath,
558
- editsDirectory: try editablesPath ( ) ,
559
- resolvedVersionsFilePath: try resolvedVersionsFilePath ( ) ,
560
- sharedCacheDirectory: cachePath
579
+ editsDirectory: self . editsDirectory ( ) ,
580
+ resolvedVersionsFile: self . resolvedVersionsFile ( ) ,
581
+ sharedCacheDirectory: sharedCacheDirectory,
582
+ sharedConfigurationDirectory: sharedConfigurationDirectory
561
583
) ,
562
- netrcFilePath : try netrcFilePath ( ) ,
563
- mirrors : self . getMirrorsConfig ( ) . mirrors ,
564
- customManifestLoader: try getManifestLoader ( ) , // FIXME: doe we really need to customize it?
584
+ mirrors : self . getMirrorsConfig ( sharedConfigurationDirectory : sharedConfigurationDirectory ) . mirrors ,
585
+ netrcFilePath : self . netrcFilePath ( ) ,
586
+ customManifestLoader: self . getManifestLoader ( ) , // FIXME: doe we really need to customize it?
565
587
customRepositoryProvider: provider, // FIXME: doe we really need to customize it?
566
588
additionalFileRules: isXcodeBuildSystemEnabled ? FileRuleDescription . xcbuildFileTypes : FileRuleDescription . swiftpmFileTypes,
567
589
resolverUpdateEnabled: !options. skipDependencyUpdate,
568
590
resolverPrefetchingEnabled: options. shouldEnableResolverPrefetching,
569
591
resolverTracingEnabled: options. enableResolverTrace,
592
+ sharedRepositoriesCacheEnabled: self . options. useRepositoriesCache,
570
593
delegate: delegate
571
594
)
572
595
_workspace = workspace
@@ -858,16 +881,16 @@ public class SwiftTool {
858
881
switch ( self . options. shouldDisableManifestCaching, self . options. manifestCachingMode) {
859
882
case ( true , _) :
860
883
// backwards compatibility
861
- cachePath = nil
884
+ cachePath = . none
862
885
case ( false , . none) :
863
- cachePath = nil
886
+ cachePath = . none
864
887
case ( false , . local) :
865
888
cachePath = self . buildPath
866
889
case ( false , . shared) :
867
- cachePath = try self . getCachePath ( ) . map { $0 . appending ( component : " manifests " ) }
890
+ cachePath = try self . getSharedCacheDirectory ( ) . map { Workspace . DefaultLocations . manifestsDirectory ( at : $0 ) }
868
891
}
869
892
870
- var extraManifestFlags = self . options. manifestFlags
893
+ var extraManifestFlags = self . options. manifestFlags
871
894
// Disable the implicit concurrency import if the compiler in use supports it to avoid warnings if we are building against an older SDK that does not contain a Concurrency module.
872
895
if SwiftTargetBuildDescription . checkSupportedFrontendFlags ( flags: [ " disable-implicit-concurrency-module-import " ] , fs: localFileSystem) {
873
896
extraManifestFlags += [ " -Xfrontend " , " -disable-implicit-concurrency-module-import " ]
0 commit comments