8
8
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9
9
*/
10
10
11
+ import ArgumentParser
12
+ import Basics
13
+ import Build
14
+ import Configurations
15
+ import Dispatch
11
16
import func Foundation. NSUserName
12
17
import class Foundation. ProcessInfo
13
18
import func Foundation. NSHomeDirectory
14
- import Dispatch
15
-
16
- import ArgumentParser
17
- import TSCLibc
18
- import TSCBasic
19
- import TSCUtility
20
-
21
- import PackageModel
22
19
import PackageGraph
20
+ import PackageModel
23
21
import SourceControl
24
22
import SPMBuildCore
25
- import Build
26
- import XCBuildSupport
23
+ import TSCBasic
24
+ import TSCLibc
25
+ import TSCUtility
27
26
import Workspace
28
- import Basics
27
+ import XCBuildSupport
29
28
30
29
typealias Diagnostic = TSCBasic . Diagnostic
31
30
@@ -459,14 +458,75 @@ public class SwiftTool {
459
458
return try getPackageRoot ( ) . appending ( component: " Packages " )
460
459
}
461
460
461
+ // FIXME: move out of here
462
462
func resolvedFilePath( ) throws -> AbsolutePath {
463
463
if let multiRootPackageDataFile = options. multirootPackageDataFile {
464
464
return multiRootPackageDataFile. appending ( components: " xcshareddata " , " swiftpm " , " Package.resolved " )
465
465
}
466
466
return try getPackageRoot ( ) . appending ( component: " Package.resolved " )
467
467
}
468
468
469
- func configFilePath( ) throws -> AbsolutePath {
469
+ // FIXME: global vs local, default locations
470
+ func getSwiftPMConfiguration( ) throws -> Configuration {
471
+ let fileSystem = localFileSystem
472
+ return . init( resolution: try self . getResolutionConfiguration ( fileSystem: fileSystem) ,
473
+ manifestsLoading: try self . getManifestLoadingConfiguration ( fileSystem: fileSystem) ,
474
+ mirrors: try self . getMirrorsConfiguration ( fileSystem: fileSystem) ,
475
+ netrc: try self . getNetrcConfiguration ( fileSystem: fileSystem) ,
476
+ collections: try self . getCollectionsConfiguration ( fileSystem: fileSystem)
477
+ )
478
+ }
479
+
480
+ func getManifestLoadingConfiguration( fileSystem: FileSystem ) throws -> Configuration . ManifestsLoading {
481
+ return . init(
482
+ cachePath: try self . resolveManifestCachePath ( fileSystem: fileSystem) ,
483
+ isManifestSandboxEnabled: !self . options. shouldDisableSandbox
484
+ )
485
+ }
486
+
487
+ // FIXME: move out of here
488
+ func resolveManifestCachePath( fileSystem: FileSystem ) throws -> AbsolutePath ? {
489
+ switch ( self . options. shouldDisableManifestCaching, self . options. manifestCachingMode) {
490
+ case ( true , _) :
491
+ // backwards compatibility
492
+ return . none
493
+ case ( false , . none) :
494
+ return . none
495
+ case ( false , . local) :
496
+ return self . buildPath
497
+ case ( false , . shared) :
498
+ return try self . resolveCachePath ( fileSystem: fileSystem) . map { Configuration . ManifestsLoading. cachePath ( cacheRoot: $0) }
499
+ }
500
+ }
501
+
502
+ func getResolutionConfiguration( fileSystem: FileSystem ) throws -> Configuration . Resolution {
503
+ return . init(
504
+ cachePath: try self . resolveRepositoriesCachePath ( fileSystem: fileSystem) ,
505
+ prefetchingEnabled: options. shouldEnableResolverPrefetching,
506
+ tracingEnabled: options. enableResolverTrace,
507
+ skipUpdate: options. skipDependencyUpdate
508
+ )
509
+ }
510
+
511
+ // FIXME: move out of here
512
+ func resolveRepositoriesCachePath( fileSystem: FileSystem ) throws -> AbsolutePath ? {
513
+ guard self . options. useRepositoriesCache else {
514
+ return . none
515
+ }
516
+ // FIXME
517
+ return try self . resolveCachePath ( fileSystem: fileSystem) //.map { Configuration.Resolution.cachePath(cacheRoot: $0) }
518
+ }
519
+
520
+ func getMirrorsConfiguration( fileSystem: FileSystem ) throws -> Configuration . Mirrors {
521
+ return . init(
522
+ fileSystem: fileSystem,
523
+ path: try self . resolveMirrorsConfigFilePath ( fileSystem: fileSystem)
524
+ )
525
+ }
526
+
527
+ // FIXME: move out of here
528
+ // FIXME: global vs local, default locations
529
+ func resolveMirrorsConfigFilePath( fileSystem: FileSystem ) throws -> AbsolutePath {
470
530
// Look for the override in the environment.
471
531
if let envPath = ProcessEnv . vars [ " SWIFTPM_MIRROR_CONFIG " ] {
472
532
return try AbsolutePath ( validating: envPath)
@@ -479,21 +539,21 @@ public class SwiftTool {
479
539
return try getPackageRoot ( ) . appending ( components: " .swiftpm " , " config " )
480
540
}
481
541
482
- func getSwiftPMConfig( ) throws -> Workspace . Configuration {
483
- return try _swiftpmConfig. get ( )
542
+ func getNetrcConfiguration( fileSystem: FileSystem ) throws -> Configuration . Netrc {
543
+ return . init(
544
+ fileSystem: fileSystem,
545
+ path: try self . resolveNetrcConfigFilePath ( fileSystem: fileSystem)
546
+ )
484
547
}
485
548
486
- private lazy var _swiftpmConfig : Result < Workspace . Configuration , Swift . Error > = {
487
- return Result ( catching: { try Workspace . Configuration ( path: try configFilePath ( ) ) } )
488
- } ( )
489
-
490
- func resolvedNetrcFilePath( ) throws -> AbsolutePath ? {
549
+ // FIXME: move out of here
550
+ func resolveNetrcConfigFilePath( fileSystem: FileSystem ) throws -> AbsolutePath ? {
491
551
guard options. netrc ||
492
552
options. netrcFilePath != nil ||
493
553
options. netrcOptional else { return nil }
494
554
495
555
let resolvedPath : AbsolutePath = options. netrcFilePath ?? AbsolutePath ( " \( NSHomeDirectory ( ) ) /.netrc " )
496
- guard localFileSystem . exists ( resolvedPath) else {
556
+ guard fileSystem . exists ( resolvedPath) else {
497
557
if !options. netrcOptional {
498
558
diagnostics. emit ( error: " Cannot find mandatory .netrc file at \( resolvedPath. pathString) . To make .netrc file optional, use --netrc-optional flag. " )
499
559
throw ExitCode . failure
@@ -505,7 +565,20 @@ public class SwiftTool {
505
565
return resolvedPath
506
566
}
507
567
508
- private func getCachePath( fileSystem: FileSystem = localFileSystem) throws -> AbsolutePath ? {
568
+ func getCollectionsConfiguration( fileSystem: FileSystem ) throws -> Configuration . Collections {
569
+ return . init(
570
+ fileSystem: fileSystem,
571
+ path: try self . resolveCollectionsFilePath ( fileSystem: fileSystem)
572
+ )
573
+ }
574
+
575
+ // FIXME: move out of here
576
+ func resolveCollectionsFilePath( fileSystem: FileSystem ) throws -> AbsolutePath ? {
577
+ return try self . resolveConfigPath ( fileSystem: fileSystem) . flatMap { $0. appending ( component: " collections.json " ) }
578
+ }
579
+
580
+ // FIXME: move out of here
581
+ private func resolveCachePath( fileSystem: FileSystem ) throws -> AbsolutePath ? {
509
582
if let explicitCachePath = options. cachePath {
510
583
// Create the explicit cache path if necessary
511
584
if !fileSystem. exists ( explicitCachePath) {
@@ -522,7 +595,8 @@ public class SwiftTool {
522
595
}
523
596
}
524
597
525
- private func getConfigPath( fileSystem: FileSystem = localFileSystem) throws -> AbsolutePath ? {
598
+ // FIXME: move out of here
599
+ private func resolveConfigPath( fileSystem: FileSystem ) throws -> AbsolutePath ? {
526
600
if let explicitConfigPath = options. configPath {
527
601
// Create the explicit config path if necessary
528
602
if !fileSystem. exists ( explicitConfigPath) {
@@ -548,24 +622,17 @@ public class SwiftTool {
548
622
let isVerbose = options. verbosity != 0
549
623
let delegate = ToolWorkspaceDelegate ( self . stdoutStream, isVerbose: isVerbose, diagnostics: diagnostics)
550
624
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
553
625
let isXcodeBuildSystemEnabled = self . options. buildSystem == . xcode
554
626
let workspace = Workspace (
627
+ configuration: try getSwiftPMConfiguration ( ) ,
555
628
dataPath: buildPath,
556
629
editablesPath: try editablesPath ( ) ,
557
630
pinsFile: try resolvedFilePath ( ) ,
558
631
manifestLoader: try getManifestLoader ( ) ,
559
632
toolsVersionLoader: ToolsVersionLoader ( ) ,
560
633
delegate: delegate,
561
- config: try getSwiftPMConfig ( ) ,
562
634
repositoryProvider: provider,
563
- netrcFilePath: try resolvedNetrcFilePath ( ) ,
564
- additionalFileRules: isXcodeBuildSystemEnabled ? FileRuleDescription . xcbuildFileTypes : FileRuleDescription . swiftpmFileTypes,
565
- isResolverPrefetchingEnabled: options. shouldEnableResolverPrefetching,
566
- skipUpdate: options. skipDependencyUpdate,
567
- enableResolverTrace: options. enableResolverTrace,
568
- cachePath: cachePath
635
+ additionalFileRules: isXcodeBuildSystemEnabled ? FileRuleDescription . xcbuildFileTypes : FileRuleDescription . swiftpmFileTypes
569
636
)
570
637
_workspace = workspace
571
638
_workspaceDelegate = delegate
@@ -852,30 +919,17 @@ public class SwiftTool {
852
919
853
920
private lazy var _manifestLoader : Result < ManifestLoader , Swift . Error > = {
854
921
return Result ( catching: {
855
- let cachePath : AbsolutePath ?
856
- switch ( self . options. shouldDisableManifestCaching, self . options. manifestCachingMode) {
857
- case ( true , _) :
858
- // backwards compatibility
859
- cachePath = nil
860
- case ( false , . none) :
861
- cachePath = nil
862
- case ( false , . local) :
863
- cachePath = self . buildPath
864
- case ( false , . shared) :
865
- cachePath = try self . getCachePath ( ) . map { $0. appending ( component: " manifests " ) }
866
- }
867
-
868
922
var extraManifestFlags = self . options. manifestFlags
869
923
// 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.
870
924
if SwiftTargetBuildDescription . checkSupportedFrontendFlags ( flags: [ " disable-implicit-concurrency-module-import " ] , fs: localFileSystem) {
871
925
extraManifestFlags += [ " -Xfrontend " , " -disable-implicit-concurrency-module-import " ]
872
926
}
873
927
928
+ let configuration = try self . getSwiftPMConfiguration ( )
874
929
return try ManifestLoader (
875
- // Always use the host toolchain's resources for parsing manifest.
930
+ configuration: configuration. manifestsLoading,
931
+ // Always use the host toolchain's for parsing manifest.
876
932
toolchain: self . _hostToolchain. get ( ) . configuration,
877
- isManifestSandboxEnabled: !self . options. shouldDisableSandbox,
878
- cacheDir: cachePath,
879
933
extraManifestFlags: extraManifestFlags
880
934
)
881
935
} )
0 commit comments