1
1
package teksturepako.pakku.api.actions.export
2
2
3
+ import com.github.michaelbull.result.Result
3
4
import com.github.michaelbull.result.get
4
5
import com.github.michaelbull.result.onFailure
5
6
import com.github.michaelbull.result.runCatching
@@ -46,12 +47,24 @@ suspend fun export(
46
47
configFile : ConfigFile ,
47
48
platforms : List <Platform >
48
49
): List <Job > = coroutineScope {
50
+ val overrides: Deferred <List <Result <String , ActionError >>> = async {
51
+ configFile.getAllOverrides()
52
+ }
53
+
54
+ val serverOverrides: Deferred <List <Result <String , ActionError >>> = async {
55
+ configFile.getAllServerOverrides()
56
+ }
57
+
58
+ val clientOverrides: Deferred <List <Result <String , ActionError >>> = async {
59
+ configFile.getAllClientOverrides()
60
+ }
61
+
49
62
profiles.map { profile ->
50
63
launch {
51
64
profile.export(
52
65
onError = { profile, error -> onError(profile, error) },
53
66
onSuccess = { profile, path, duration -> onSuccess(profile, path, duration) },
54
- lockFile, configFile, platforms
67
+ lockFile, configFile, platforms, overrides, serverOverrides, clientOverrides
55
68
)
56
69
}
57
70
}
@@ -62,7 +75,10 @@ suspend fun ExportProfile.export(
62
75
onSuccess : suspend (profile: ExportProfile , path: Path , duration: Duration ) -> Unit ,
63
76
lockFile : LockFile ,
64
77
configFile : ConfigFile ,
65
- platforms : List <Platform >
78
+ platforms : List <Platform >,
79
+ overrides : Deferred <List <Result <String , ActionError >>>,
80
+ serverOverrides : Deferred <List <Result <String , ActionError >>>,
81
+ clientOverrides : Deferred <List <Result <String , ActionError >>>,
66
82
)
67
83
{
68
84
if (this .dependsOn != null && this .dependsOn !in platforms) return
@@ -88,8 +104,10 @@ suspend fun ExportProfile.export(
88
104
89
105
val inputDirectory = Path (cacheDir.pathString, this .name)
90
106
91
- val results: List <RuleResult > = this .rules.filterNotNull()
92
- .produceRuleResults({ onError(this , it) }, lockFile, configFile, this .name)
107
+ val results: List <RuleResult > = this .rules.filterNotNull().produceRuleResults(
108
+ onError = { onError(this , it) },
109
+ lockFile, configFile, this .name, overrides, serverOverrides, clientOverrides
110
+ )
93
111
94
112
// Run export rules
95
113
val cachedPaths: List <Path > = results.resolveResults { onError(this , it) }.awaitAll().filterNotNull() +
@@ -281,44 +299,71 @@ suspend fun List<RuleResult>.finishResults(
281
299
*/
282
300
suspend fun List<ExportRule>.produceRuleResults (
283
301
onError : suspend (error: ActionError ) -> Unit ,
284
- lockFile : LockFile , configFile : ConfigFile , workingSubDir : String
285
- ): List <RuleResult >
286
- {
287
- val results = this .fold(listOf<Pair <ExportRule , RuleContext >>()) { acc, rule ->
288
- acc + lockFile.getAllProjects().map {
289
- rule to RuleContext .ExportingProject (it, lockFile, configFile, workingSubDir)
290
- } + configFile.getAllOverrides().mapNotNull { result ->
302
+ lockFile : LockFile , configFile : ConfigFile , workingSubDir : String ,
303
+ overrides : Deferred <List <Result <String , ActionError >>>,
304
+ serverOverrides : Deferred <List <Result <String , ActionError >>>,
305
+ clientOverrides : Deferred <List <Result <String , ActionError >>>,
306
+ ): List <RuleResult > = coroutineScope {
307
+ val projects: Deferred <List <RuleContext .ExportingProject >> = async {
308
+ lockFile.getAllProjects().map {
309
+ RuleContext .ExportingProject (it, lockFile, configFile, workingSubDir)
310
+ }
311
+ }
312
+
313
+ val overridesR: Deferred <List <RuleContext .ExportingOverride >> = async {
314
+ overrides.await().mapNotNull { result ->
291
315
result.resultFold(
292
316
success = {
293
- rule to RuleContext .ExportingOverride (it, OverrideType .OVERRIDE , lockFile, configFile, workingSubDir)
317
+ RuleContext .ExportingOverride (it, OverrideType .OVERRIDE , lockFile, configFile, workingSubDir)
294
318
},
295
319
failure = {
296
320
onError(it)
297
321
null
298
322
}
299
323
)
300
- } + configFile.getAllServerOverrides().mapNotNull { result ->
324
+ }
325
+ }
326
+
327
+ val serverOverridesR: Deferred <List <RuleContext .ExportingOverride >> = async {
328
+ serverOverrides.await().mapNotNull { result ->
301
329
result.resultFold(
302
330
success = {
303
- rule to RuleContext .ExportingOverride (it, OverrideType .SERVER_OVERRIDE , lockFile, configFile, workingSubDir)
331
+ RuleContext .ExportingOverride (it, OverrideType .SERVER_OVERRIDE , lockFile, configFile, workingSubDir)
304
332
},
305
333
failure = {
306
334
onError(it)
307
335
null
308
336
}
309
337
)
310
- } + configFile.getAllClientOverrides().mapNotNull { result ->
338
+ }
339
+ }
340
+
341
+ val clientOverridesR: Deferred <List <RuleContext .ExportingOverride >> = async {
342
+ clientOverrides.await().mapNotNull { result ->
311
343
result.resultFold(
312
344
success = {
313
- rule to RuleContext .ExportingOverride (it, OverrideType .CLIENT_OVERRIDE , lockFile, configFile, workingSubDir)
345
+ RuleContext .ExportingOverride (it, OverrideType .CLIENT_OVERRIDE , lockFile, configFile, workingSubDir)
314
346
},
315
347
failure = {
316
348
onError(it)
317
349
null
318
350
}
319
351
)
320
- } + readProjectOverrides(configFile).map {
321
- rule to RuleContext .ExportingProjectOverride (it, lockFile, configFile, workingSubDir)
352
+ }
353
+ }
354
+
355
+ val projectOverrides: Deferred <List <RuleContext .ExportingProjectOverride >> = async {
356
+ readProjectOverrides(configFile).map {
357
+ RuleContext .ExportingProjectOverride (it, lockFile, configFile, workingSubDir)
358
+ }
359
+ }
360
+
361
+ val deferredContexts = listOf (projects, overridesR, serverOverridesR, clientOverridesR, projectOverrides)
362
+ val contexts = deferredContexts.awaitAll().flatten()
363
+
364
+ val results = this @produceRuleResults.fold(listOf<Pair <ExportRule , RuleContext >>()) { acc, rule ->
365
+ acc + contexts.map { context ->
366
+ rule to context
322
367
}
323
368
}.map { (exportRule, ruleContext) ->
324
369
exportRule.getResult(ruleContext)
@@ -327,15 +372,15 @@ suspend fun List<ExportRule>.produceRuleResults(
327
372
val missing = results.filter {
328
373
it.ruleContext is RuleContext .MissingProject
329
374
}.flatMap { ruleResult ->
330
- this .map { rule ->
375
+ this @produceRuleResults .map { rule ->
331
376
val project = (ruleResult.ruleContext as RuleContext .MissingProject ).project
332
377
rule.getResult(RuleContext .MissingProject (project, lockFile, configFile, workingSubDir))
333
378
}
334
379
}
335
380
336
- val finished = this .map { rule ->
381
+ val finished = this @produceRuleResults .map { rule ->
337
382
rule.getResult(Finished (lockFile, configFile, workingSubDir))
338
383
}
339
384
340
- return results + missing + finished
385
+ return @coroutineScope results + missing + finished
341
386
}
0 commit comments