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,81 @@ 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 ( rootCachePath: $0) }
499
+ }
500
+ }
501
+
502
+ func getResolutionConfiguration( fileSystem: FileSystem ) throws -> Configuration . Resolution {
503
+ return . init(
504
+ repositories: try getRepositoriesResolutionConfiguration ( fileSystem: fileSystem) ,
505
+ prefetchingEnabled: options. shouldEnableResolverPrefetching,
506
+ tracingEnabled: options. enableResolverTrace,
507
+ skipUpdate: options. skipDependencyUpdate
508
+ )
509
+ }
510
+
511
+ func getRepositoriesResolutionConfiguration( fileSystem: FileSystem ) throws -> Configuration . Resolution . Repositories {
512
+ return . init(
513
+ cachePath: try self . resolveRepositoriesResolutionCachePath ( fileSystem: fileSystem)
514
+ )
515
+ }
516
+
517
+ // FIXME: move out of here
518
+ func resolveRepositoriesResolutionCachePath( fileSystem: FileSystem ) throws -> AbsolutePath ? {
519
+ guard self . options. useRepositoriesCache else {
520
+ return . none
521
+ }
522
+ // FIXME
523
+ return try self . resolveCachePath ( fileSystem: fileSystem) . map { Configuration . Resolution. Repositories. cachePath ( rootCachePath: $0) }
524
+ }
525
+
526
+ func getMirrorsConfiguration( fileSystem: FileSystem ) throws -> Configuration . Mirrors {
527
+ return . init(
528
+ fileSystem: fileSystem,
529
+ path: try self . resolveMirrorsConfigFilePath ( fileSystem: fileSystem)
530
+ )
531
+ }
532
+
533
+ // FIXME: move out of here
534
+ // FIXME: global vs local, default locations
535
+ func resolveMirrorsConfigFilePath( fileSystem: FileSystem ) throws -> AbsolutePath {
470
536
// Look for the override in the environment.
471
537
if let envPath = ProcessEnv . vars [ " SWIFTPM_MIRROR_CONFIG " ] {
472
538
return try AbsolutePath ( validating: envPath)
@@ -479,21 +545,21 @@ public class SwiftTool {
479
545
return try getPackageRoot ( ) . appending ( components: " .swiftpm " , " config " )
480
546
}
481
547
482
- func getSwiftPMConfig( ) throws -> Workspace . Configuration {
483
- return try _swiftpmConfig. get ( )
548
+ func getNetrcConfiguration( fileSystem: FileSystem ) throws -> Configuration . Netrc {
549
+ return . init(
550
+ fileSystem: fileSystem,
551
+ path: try self . resolveNetrcConfigFilePath ( fileSystem: fileSystem)
552
+ )
484
553
}
485
554
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 ? {
555
+ // FIXME: move out of here
556
+ func resolveNetrcConfigFilePath( fileSystem: FileSystem ) throws -> AbsolutePath ? {
491
557
guard options. netrc ||
492
558
options. netrcFilePath != nil ||
493
559
options. netrcOptional else { return nil }
494
560
495
561
let resolvedPath : AbsolutePath = options. netrcFilePath ?? AbsolutePath ( " \( NSHomeDirectory ( ) ) /.netrc " )
496
- guard localFileSystem . exists ( resolvedPath) else {
562
+ guard fileSystem . exists ( resolvedPath) else {
497
563
if !options. netrcOptional {
498
564
diagnostics. emit ( error: " Cannot find mandatory .netrc file at \( resolvedPath. pathString) . To make .netrc file optional, use --netrc-optional flag. " )
499
565
throw ExitCode . failure
@@ -505,7 +571,20 @@ public class SwiftTool {
505
571
return resolvedPath
506
572
}
507
573
508
- private func getCachePath( fileSystem: FileSystem = localFileSystem) throws -> AbsolutePath ? {
574
+ func getCollectionsConfiguration( fileSystem: FileSystem ) throws -> Configuration . Collections {
575
+ return . init(
576
+ fileSystem: fileSystem,
577
+ path: try self . resolveCollectionsFilePath ( fileSystem: fileSystem)
578
+ )
579
+ }
580
+
581
+ // FIXME: move out of here
582
+ func resolveCollectionsFilePath( fileSystem: FileSystem ) throws -> AbsolutePath ? {
583
+ return try self . resolveConfigPath ( fileSystem: fileSystem) . flatMap { $0. appending ( component: " collections.json " ) }
584
+ }
585
+
586
+ // FIXME: move out of here
587
+ private func resolveCachePath( fileSystem: FileSystem ) throws -> AbsolutePath ? {
509
588
if let explicitCachePath = options. cachePath {
510
589
// Create the explicit cache path if necessary
511
590
if !fileSystem. exists ( explicitCachePath) {
@@ -522,7 +601,8 @@ public class SwiftTool {
522
601
}
523
602
}
524
603
525
- private func getConfigPath( fileSystem: FileSystem = localFileSystem) throws -> AbsolutePath ? {
604
+ // FIXME: move out of here
605
+ private func resolveConfigPath( fileSystem: FileSystem ) throws -> AbsolutePath ? {
526
606
if let explicitConfigPath = options. configPath {
527
607
// Create the explicit config path if necessary
528
608
if !fileSystem. exists ( explicitConfigPath) {
@@ -548,24 +628,17 @@ public class SwiftTool {
548
628
let isVerbose = options. verbosity != 0
549
629
let delegate = ToolWorkspaceDelegate ( self . stdoutStream, isVerbose: isVerbose, diagnostics: diagnostics)
550
630
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
631
let isXcodeBuildSystemEnabled = self . options. buildSystem == . xcode
554
632
let workspace = Workspace (
633
+ configuration: try getSwiftPMConfiguration ( ) ,
555
634
dataPath: buildPath,
556
635
editablesPath: try editablesPath ( ) ,
557
636
pinsFile: try resolvedFilePath ( ) ,
558
637
manifestLoader: try getManifestLoader ( ) ,
559
638
toolsVersionLoader: ToolsVersionLoader ( ) ,
560
639
delegate: delegate,
561
- config: try getSwiftPMConfig ( ) ,
562
640
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
641
+ additionalFileRules: isXcodeBuildSystemEnabled ? FileRuleDescription . xcbuildFileTypes : FileRuleDescription . swiftpmFileTypes
569
642
)
570
643
_workspace = workspace
571
644
_workspaceDelegate = delegate
@@ -852,30 +925,17 @@ public class SwiftTool {
852
925
853
926
private lazy var _manifestLoader : Result < ManifestLoader , Swift . Error > = {
854
927
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
928
var extraManifestFlags = self . options. manifestFlags
869
929
// 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
930
if SwiftTargetBuildDescription . checkSupportedFrontendFlags ( flags: [ " disable-implicit-concurrency-module-import " ] , fs: localFileSystem) {
871
931
extraManifestFlags += [ " -Xfrontend " , " -disable-implicit-concurrency-module-import " ]
872
932
}
873
933
934
+ let configuration = try self . getSwiftPMConfiguration ( )
874
935
return try ManifestLoader (
875
- // Always use the host toolchain's resources for parsing manifest.
936
+ configuration: configuration. manifestsLoading,
937
+ // Always use the host toolchain's for parsing manifest.
876
938
toolchain: self . _hostToolchain. get ( ) . configuration,
877
- isManifestSandboxEnabled: !self . options. shouldDisableSandbox,
878
- cacheDir: cachePath,
879
939
extraManifestFlags: extraManifestFlags
880
940
)
881
941
} )
0 commit comments