@@ -41,7 +41,7 @@ public final class SwiftCachingMaterializeKeyTaskAction: TaskAction {
41
41
/// The action is in its initial state, and has not yet performed any work.
42
42
case initial
43
43
/// Waiting for the caching key query to finish.
44
- case waitingForKeyQuery( jobTaskIDBase: UInt , cas: SwiftCASDatabases , key : String )
44
+ case waitingForKeyQuery( jobTaskIDBase: UInt , cas: SwiftCASDatabases , keys : [ String ] )
45
45
/// Waiting for the outputs to finish downloading.
46
46
case waitingForOutputDownloads
47
47
/// Not waiting for any other dependency
@@ -69,22 +69,22 @@ public final class SwiftCachingMaterializeKeyTaskAction: TaskAction {
69
69
guard let cas = try swiftModuleDependencyGraph. getCASDatabases ( casOptions: taskKey. casOptions, compilerLocation: taskKey. compilerLocation) else {
70
70
throw StubError . error ( " unable to use CAS databases " )
71
71
}
72
- let jobTaskIDBase : UInt = 0
73
- if let cachedComp = try cas. queryLocalCacheKey ( taskKey. cacheKey) {
74
- if try requestCompilationOutputs ( cachedComp,
75
- dynamicExecutionDelegate: dynamicExecutionDelegate,
76
- cacheKey: taskKey. cacheKey,
77
- jobTaskIDBase: jobTaskIDBase) != 0 {
78
- state = . waitingForOutputDownloads
72
+ var missingKeys : [ String ] = [ ]
73
+ var compOutputs : [ SwiftCachedCompilation ] = [ ]
74
+ try taskKey. cacheKeys. forEach { key in
75
+ if let output = try cas. queryLocalCacheKey ( key) {
76
+ compOutputs. append ( output)
79
77
} else {
80
- state = . done
78
+ missingKeys . append ( key )
81
79
}
82
- } else {
83
- let key = SwiftCachingKeyQueryTaskKey ( casOptions: taskKey. casOptions, cacheKey: taskKey. cacheKey, compilerLocation: taskKey. compilerLocation)
80
+ }
81
+
82
+ if !missingKeys. isEmpty {
83
+ let key = SwiftCachingKeyQueryTaskKey ( casOptions: taskKey. casOptions, cacheKeys: missingKeys, compilerLocation: taskKey. compilerLocation)
84
84
dynamicExecutionDelegate. requestDynamicTask (
85
85
toolIdentifier: SwiftCachingKeyQueryTaskAction . toolIdentifier,
86
86
taskKey: . swiftCachingKeyQuery( key) ,
87
- taskID: jobTaskIDBase ,
87
+ taskID: 0 ,
88
88
singleUse: true ,
89
89
workingDirectory: Path ( " " ) ,
90
90
environment: . init( ) ,
@@ -93,7 +93,15 @@ public final class SwiftCachingMaterializeKeyTaskAction: TaskAction {
93
93
showEnvironment: false ,
94
94
reason: . wasCompilationCachingQuery
95
95
)
96
- state = . waitingForKeyQuery( jobTaskIDBase: jobTaskIDBase + 1 , cas: cas, key: taskKey. cacheKey)
96
+ state = . waitingForKeyQuery( jobTaskIDBase: 1 , cas: cas, keys: taskKey. cacheKeys)
97
+ } else {
98
+ if try requestCompilationOutputs ( compOutputs,
99
+ dynamicExecutionDelegate: dynamicExecutionDelegate,
100
+ jobTaskIDBase: 1 ) != 0 {
101
+ state = . waitingForOutputDownloads
102
+ } else {
103
+ state = . done
104
+ }
97
105
}
98
106
} catch {
99
107
state = . executionError( error)
@@ -111,15 +119,17 @@ public final class SwiftCachingMaterializeKeyTaskAction: TaskAction {
111
119
switch state {
112
120
case . initial:
113
121
state = . executionError( StubError . error ( " taskDependencyReady unexpectedly called in initial state " ) )
114
- case . waitingForKeyQuery( jobTaskIDBase: let jobTaskIDBase, cas: let cas, key : let key ) :
122
+ case . waitingForKeyQuery( jobTaskIDBase: let jobTaskIDBase, cas: let cas, keys : let keys ) :
115
123
do {
116
- guard let cachedComp = try cas. queryLocalCacheKey ( key) else {
124
+ let cachedComps = try keys. compactMap {
125
+ try cas. queryLocalCacheKey ( $0)
126
+ }
127
+ guard cachedComps. count == keys. count else {
117
128
state = . done
118
129
return // compilation key not found.
119
130
}
120
- if try requestCompilationOutputs ( cachedComp ,
131
+ if try requestCompilationOutputs ( cachedComps ,
121
132
dynamicExecutionDelegate: dynamicExecutionDelegate,
122
- cacheKey: key,
123
133
jobTaskIDBase: jobTaskIDBase) != 0 {
124
134
state = . waitingForOutputDownloads
125
135
} else {
@@ -139,32 +149,33 @@ public final class SwiftCachingMaterializeKeyTaskAction: TaskAction {
139
149
}
140
150
141
151
private func requestCompilationOutputs(
142
- _ cachedComp : SwiftCachedCompilation ,
152
+ _ cachedComps : [ SwiftCachedCompilation ] ,
143
153
dynamicExecutionDelegate: any DynamicTaskExecutionDelegate ,
144
- cacheKey: String ,
145
154
jobTaskIDBase: UInt
146
155
) throws -> UInt {
147
- let requested = try cachedComp. getOutputs ( ) . reduce ( into: UInt ( 0 ) ) { ( numRequested, output) in
148
- if output. isMaterialized { return }
149
- let outputMaterializeKey = SwiftCachingOutputMaterializerTaskKey ( casOptions: taskKey. casOptions,
150
- casID: output. casID,
151
- outputKind: output. kindName,
152
- compilerLocation: taskKey. compilerLocation)
153
- dynamicExecutionDelegate. requestDynamicTask (
154
- toolIdentifier: SwiftCachingOutputMaterializerTaskAction . toolIdentifier,
155
- taskKey: . swiftCachingOutputMaterializer( outputMaterializeKey) ,
156
- taskID: jobTaskIDBase + numRequested,
157
- singleUse: true ,
158
- workingDirectory: Path ( " " ) ,
159
- environment: . init( ) ,
160
- forTarget: nil ,
161
- priority: . network,
162
- showEnvironment: false ,
163
- reason: . wasCompilationCachingQuery
164
- )
165
- numRequested += 1
156
+ let numRequested = try cachedComps. reduce ( into: UInt ( 0 ) ) { ( numRequested, cachedComp) in
157
+ try cachedComp. getOutputs ( ) . forEach { output in
158
+ if output. isMaterialized { return }
159
+ let outputMaterializeKey = SwiftCachingOutputMaterializerTaskKey ( casOptions: taskKey. casOptions,
160
+ casID: output. casID,
161
+ outputKind: output. kindName,
162
+ compilerLocation: taskKey. compilerLocation)
163
+ dynamicExecutionDelegate. requestDynamicTask (
164
+ toolIdentifier: SwiftCachingOutputMaterializerTaskAction . toolIdentifier,
165
+ taskKey: . swiftCachingOutputMaterializer( outputMaterializeKey) ,
166
+ taskID: jobTaskIDBase + numRequested,
167
+ singleUse: true ,
168
+ workingDirectory: Path ( " " ) ,
169
+ environment: . init( ) ,
170
+ forTarget: nil ,
171
+ priority: . network,
172
+ showEnvironment: false ,
173
+ reason: . wasCompilationCachingQuery
174
+ )
175
+ numRequested += 1
176
+ }
166
177
}
167
- return requested
178
+ return numRequested
168
179
}
169
180
170
181
public override func performTaskAction(
0 commit comments