@@ -8,7 +8,8 @@ enum DependencyInstallerError: Error {
8
8
protocol DependencyInstaller {
9
9
func loadManifest( ) throws -> Manifest
10
10
func revertCheckoutChanges( workingDirectory: String ) throws
11
- func buildFrameworksAndIntegrateWithXcode( manifest: Manifest , dependencyGraph: DependencyGraph , sharedCachePath: String ? ) throws
11
+ func buildFrameworksAndIntegrateWithXcode( workingDirectory: String , manifest: Manifest , dependencyGraph: DependencyGraph , sharedCachePath: String ? ) throws
12
+ func loadRequiredFrameworksFromCache( workingDirectory: String , sharedCachePath: String ? ) throws -> Bool
12
13
}
13
14
14
15
extension DependencyInstaller {
@@ -47,7 +48,12 @@ extension DependencyInstaller {
47
48
}
48
49
}
49
50
50
- func buildFrameworksAndIntegrateWithXcode( manifest: Manifest , dependencyGraph: DependencyGraph , sharedCachePath: String ? ) throws {
51
+ func buildFrameworksAndIntegrateWithXcode(
52
+ workingDirectory: String = GlobalOptions . workingDirectory. value ?? FileManager . default. currentDirectoryPath,
53
+ manifest: Manifest ,
54
+ dependencyGraph: DependencyGraph ,
55
+ sharedCachePath: String ?
56
+ ) throws {
51
57
if FileManager . default. fileExists ( atPath: Constants . temporaryFrameworksUrl. path) {
52
58
try bash ( " rm -rf ' \( Constants . temporaryFrameworksUrl. path) ' " )
53
59
}
@@ -59,6 +65,8 @@ extension DependencyInstaller {
59
65
try bash ( " mkdir -p ' \( Constants . temporaryFrameworksUrl. path) ' " )
60
66
try bash ( " mkdir -p ' \( Constants . temporaryUncachingUrl. path) ' " )
61
67
68
+ let swiftVersion = try SwiftVersionDetectorService . shared. getCurrentSwiftVersion ( )
69
+
62
70
typealias ParsingResult = ( target: AppTarget , platform: Platform , frameworkProducts: [ FrameworkProduct ] )
63
71
64
72
let appTargets : [ AppTarget ] = try manifest. appTargets ( )
@@ -71,7 +79,13 @@ extension DependencyInstaller {
71
79
let platform = try PlatformDetectorService . shared. detectPlatform ( of: appTarget)
72
80
print ( " Resolving dependencies for target ' \( appTarget. targetName) ' on platform ' \( platform. rawValue) ' ... " , level: . info)
73
81
74
- let frameworkProducts = try CachedBuilderService ( sharedCachePath: sharedCachePath) . frameworkProducts ( manifest: manifest, appTarget: appTarget, dependencyGraph: dependencyGraph, platform: platform)
82
+ let frameworkProducts = try CachedBuilderService ( sharedCachePath: sharedCachePath) . frameworkProducts (
83
+ manifest: manifest,
84
+ appTarget: appTarget,
85
+ dependencyGraph: dependencyGraph,
86
+ platform: platform,
87
+ swiftVersion: swiftVersion
88
+ )
75
89
return ParsingResult ( target: appTarget, platform: platform, frameworkProducts: frameworkProducts)
76
90
}
77
91
@@ -83,5 +97,66 @@ extension DependencyInstaller {
83
97
84
98
try XcodeProjectIntegrationService . shared. handleRemovedTargets ( keepingTargets: appTargets)
85
99
try bash ( " rm -rf ' \( Constants . temporaryFrameworksUrl. path) ' " )
100
+
101
+ try ResolvedManifestCachingService ( sharedCachePath: sharedCachePath) . cacheResolvedManifest (
102
+ at: URL ( fileURLWithPath: workingDirectory) . appendingPathComponent ( " Package.resolved " ) ,
103
+ with: parsingResults. flatMap {
104
+ $0. frameworkProducts. map {
105
+ CachedFrameworkProduct (
106
+ libraryName: $0. libraryName,
107
+ commitHash: $0. commitHash,
108
+ platform: $0. platformName
109
+ )
110
+ }
111
+ }
112
+ )
113
+ }
114
+
115
+ func loadRequiredFrameworksFromCache(
116
+ workingDirectory: String = GlobalOptions . workingDirectory. value ?? FileManager . default. currentDirectoryPath,
117
+ sharedCachePath: String ?
118
+ ) throws -> Bool {
119
+ let cachingService = ResolvedManifestCachingService ( sharedCachePath: sharedCachePath)
120
+
121
+ guard let cachedFrameworkProducts = try cachingService. cachedFrameworkProducts (
122
+ forResolvedManifestAt: URL ( fileURLWithPath: workingDirectory) . appendingPathComponent ( " Package.resolved " )
123
+ ) else {
124
+ return false
125
+ }
126
+
127
+ let cachedFrameworkProductUrls : [ URL ] = cachedFrameworkProducts. compactMap { cachedFrameworkProduct in
128
+ guard let cacheFileSubPath = try ? cachedFrameworkProduct. getCacheFileSubPath ( ) else { return nil }
129
+
130
+ let localCacheFileUrl = URL ( fileURLWithPath: Constants . localCachePath) . appendingPathComponent ( cacheFileSubPath)
131
+ if FileManager . default. fileExists ( atPath: localCacheFileUrl. path) {
132
+ return localCacheFileUrl
133
+ }
134
+
135
+ if let sharedCachePath = sharedCachePath {
136
+ let sharedCacheFileUrl = URL ( fileURLWithPath: sharedCachePath) . appendingPathComponent ( cacheFileSubPath)
137
+
138
+ if FileManager . default. fileExists ( atPath: sharedCacheFileUrl. path) {
139
+ return sharedCacheFileUrl
140
+ }
141
+ }
142
+
143
+ return nil
144
+ }
145
+
146
+ guard cachedFrameworkProductUrls. count == cachedFrameworkProducts. count else {
147
+ print ( " Not all required build products specified in resolved manifest are cached – unable to skip checkout / integration process ... " , level: . info)
148
+ return false
149
+ }
150
+
151
+ print ( " Found all required build products specified in resolved manifest in cache – skipping checkout & integration process ... " , level: . info)
152
+
153
+ let frameworkProducts : [ FrameworkProduct ] = try cachedFrameworkProductUrls. map {
154
+ return try FrameworkCachingService ( sharedCachePath: sharedCachePath) . frameworkProduct ( forCachedFileAt: $0)
155
+ }
156
+
157
+ try XcodeProjectIntegrationService . shared. clearDependenciesFolder ( )
158
+ try XcodeProjectIntegrationService . shared. copy ( cachedFrameworkProducts: frameworkProducts)
159
+
160
+ return true
86
161
}
87
162
}
0 commit comments