@@ -4,7 +4,10 @@ import dev.adamko.kotlin.binary_compatibility_validator.internal.*
4
4
import dev.adamko.kotlin.binary_compatibility_validator.targets.BCVJvmTarget
5
5
import dev.adamko.kotlin.binary_compatibility_validator.targets.BCVKLibTarget
6
6
import dev.adamko.kotlin.binary_compatibility_validator.targets.BCVTarget
7
- import dev.adamko.kotlin.binary_compatibility_validator.workers.*
7
+ import dev.adamko.kotlin.binary_compatibility_validator.workers.JvmSignaturesWorker
8
+ import dev.adamko.kotlin.binary_compatibility_validator.workers.KLibInferSignaturesWorker
9
+ import dev.adamko.kotlin.binary_compatibility_validator.workers.KLibMergeWorker
10
+ import dev.adamko.kotlin.binary_compatibility_validator.workers.KLibSignaturesWorker
8
11
import java.io.File
9
12
import javax.inject.Inject
10
13
import org.gradle.api.NamedDomainObjectContainer
@@ -71,17 +74,18 @@ constructor(
71
74
72
75
@TaskAction
73
76
fun generate () {
74
- val workQueue = prepareWorkQueue()
75
-
76
77
prepareDirectories()
77
78
78
- logger.lifecycle( " [ $path ] got ${targets.size} targets : ${targets.joinToString { it.name }} " )
79
+ val workQueue = prepareWorkQueue( )
79
80
80
81
val enabledTargets = targets.matching { it.enabled.getOrElse(true ) }
81
82
83
+ logger.lifecycle(" [$path ] got ${targets.size} targets (${enabledTargets.size} enabled) : ${targets.joinToString { it.name }} " )
84
+
85
+ val jvmTargets = enabledTargets.withType<BCVJvmTarget >().sorted()
82
86
generateJvmTargets(
83
87
workQueue = workQueue,
84
- jvmTargets = enabledTargets.withType< BCVJvmTarget >().sorted() ,
88
+ jvmTargets = jvmTargets ,
85
89
outputApiBuildDir = outputApiBuildDir.get().asFile,
86
90
)
87
91
@@ -90,7 +94,6 @@ constructor(
90
94
val klibTargets = enabledTargets.withType<BCVKLibTarget >()
91
95
.filter { it.klibFile.singleOrNull()?.exists() == true }
92
96
.sorted()
93
-
94
97
generateKLibTargets(
95
98
workQueue = workQueue,
96
99
klibTargets = klibTargets,
@@ -103,26 +106,19 @@ constructor(
103
106
104
107
105
108
private fun prepareWorkQueue (): WorkQueue {
106
- fs.delete { delete(temporaryDir) }
107
- temporaryDir.mkdirs()
108
-
109
109
return workers.classLoaderIsolation {
110
110
classpath.from(runtimeClasspath)
111
111
}
112
112
}
113
113
114
114
private fun prepareDirectories () {
115
- val outputApiBuildDir = outputApiBuildDir.get()
116
115
fs.delete { delete(outputApiBuildDir) }
117
- outputApiBuildDir.asFile.mkdirs()
116
+ outputApiBuildDir.get(). asFile.mkdirs()
118
117
119
- fs.delete { delete(klibTargetsDir.supported) }
118
+ fs.delete { delete(workDir) }
119
+ workDir.mkdirs()
120
120
klibTargetsDir.supported.mkdirs()
121
-
122
- fs.delete { delete(klibTargetsDir.unsupported) }
123
121
klibTargetsDir.unsupported.mkdirs()
124
-
125
- fs.delete { delete(klibTargetsDir.extracted) }
126
122
klibTargetsDir.extracted.mkdirs()
127
123
}
128
124
@@ -187,7 +183,7 @@ constructor(
187
183
private fun generateKLibTargets (
188
184
workQueue : WorkQueue ,
189
185
outputApiBuildDir : File ,
190
- klibTargets : Collection <BCVKLibTarget >,
186
+ klibTargets : List <BCVKLibTarget >,
191
187
) {
192
188
if (klibTargets.isEmpty()) {
193
189
logger.info(" [$path ] No enabled KLib targets" )
@@ -201,19 +197,30 @@ constructor(
201
197
generateSupportedKLibTargets(workQueue, supportedKLibTargets)
202
198
generateUnsupportedKLibTargets(workQueue, unsupportedKLibTargets)
203
199
204
- workQueue.await()
200
+ val allTargetDumpFiles = buildSet {
201
+ addAll(klibTargetsDir.supported.walk().filter { it.isFile })
202
+ addAll(klibTargetsDir.unsupported.walk().filter { it.isFile })
203
+ }
205
204
206
- val allTargetDumpFiles =
207
- klibTargetsDir.supported.walk().filter { it.isFile }.toSet() union
208
- klibTargetsDir.unsupported.walk().filter { it.isFile }.toSet()
205
+ mergeDumpFiles(
206
+ workQueue = workQueue,
207
+ allTargetDumpFiles = allTargetDumpFiles,
208
+ outputApiBuildDir = outputApiBuildDir,
209
+ targets = klibTargets,
210
+ strictValidation = strictKLibTargetValidation.get(),
211
+ )
209
212
210
- mergeDumpFiles( workQueue, allTargetDumpFiles, outputApiBuildDir )
213
+ // workQueue.extract( )
211
214
}
212
215
213
216
private fun generateSupportedKLibTargets (
214
217
workQueue : WorkQueue ,
215
218
supportedKLibTargets : List <BCVKLibTarget >
216
219
) {
220
+ if (supportedKLibTargets.isEmpty()) {
221
+ logger.info(" [$path ] No supported enabled KLib targets" )
222
+ return
223
+ }
217
224
logger.lifecycle(" [$path ] generating ${supportedKLibTargets.size} supported KLib targets : ${supportedKLibTargets.joinToString { it.name }} " )
218
225
219
226
val duration = measureTime {
@@ -233,6 +240,10 @@ constructor(
233
240
workQueue : WorkQueue ,
234
241
unsupportedKLibTargets : List <BCVKLibTarget >
235
242
) {
243
+ if (unsupportedKLibTargets.isEmpty()) {
244
+ logger.info(" [$path ] No unsupported enabled KLib targets" )
245
+ return
246
+ }
236
247
logger.lifecycle(" [$path ] generating ${unsupportedKLibTargets.size} unsupported KLib targets : ${unsupportedKLibTargets.joinToString { it.name }} " )
237
248
238
249
val duration = measureTime {
@@ -245,6 +256,7 @@ constructor(
245
256
outputDir = klibTargetsDir.unsupported,
246
257
)
247
258
}
259
+ workQueue.await()
248
260
}
249
261
250
262
logger.lifecycle(" [$path ] finished generating unsupported KLib targets in $duration " )
@@ -254,20 +266,26 @@ constructor(
254
266
private fun mergeDumpFiles (
255
267
workQueue : WorkQueue ,
256
268
allTargetDumpFiles : Set <File >,
257
- outputApiBuildDir : File
269
+ outputApiBuildDir : File ,
270
+ targets : List <BCVKLibTarget >,
271
+ strictValidation : Boolean ,
258
272
) {
259
273
logger.lifecycle(" [$path ] merging ${allTargetDumpFiles.size} dump files : ${allTargetDumpFiles.joinToString { it.name }} " )
260
274
261
- workQueue.merge(
262
- projectName.get(),
263
- targetDumpFiles = allTargetDumpFiles,
264
- outputDir = outputApiBuildDir,
265
- )
266
- workQueue.await()
275
+ val duration = measureTime {
276
+ workQueue.merge(
277
+ projectName.get(),
278
+ targetDumpFiles = allTargetDumpFiles,
279
+ outputDir = outputApiBuildDir,
280
+ supportedTargets = targets.filter { it.supportedByCurrentHost.get() }.map { it.targetName },
281
+ strictValidation = strictValidation,
282
+ )
283
+ workQueue.await()
284
+ }
267
285
268
286
if (logger.isLifecycleEnabled) {
269
287
val fileNames = outputApiBuildDir.walk().filter { it.isFile }.toList()
270
- logger.lifecycle(" [$path ] merged ${allTargetDumpFiles.size} dump files : $fileNames " )
288
+ logger.lifecycle(" [$path ] merged ${allTargetDumpFiles.size} dump files in $duration : $fileNames " )
271
289
}
272
290
}
273
291
@@ -288,8 +306,7 @@ constructor(
288
306
289
307
this @worker.klib.set(target.klibFile.singleFile)
290
308
this @worker.signatureVersion.set(target.signatureVersion)
291
- this @worker.strictValidation.set(target.strictValidation)
292
- // [email protected] (target.supportedByCurrentHost)
309
+ // [email protected] (target.strictValidation)
293
310
294
311
295
312
@@ -325,37 +342,45 @@ constructor(
325
342
projectName : String ,
326
343
targetDumpFiles : Set <File >,
327
344
outputDir : File ,
345
+ supportedTargets : List <String >,
346
+ strictValidation : Boolean ,
328
347
) {
329
348
val task = this @BCVApiGenerateTask
330
349
331
350
@OptIn(BCVInternalApi ::class )
332
351
submit(KLibMergeWorker ::class ) worker@{
333
- this @worker.projectName.set(projectName)
352
+
334
353
this @worker.taskPath.set(task.path)
335
354
336
- this @worker.outputApiDir.set(outputDir)
355
+
356
+ this @worker.outputApiFile.set(
357
+ outputDir.resolve(" $projectName .klib.api" )
358
+ )
359
+
360
+ this @worker.strictValidation.set(strictValidation)
361
+ this @worker.supportedTargets.set(supportedTargets)
337
362
338
363
this @worker.targetDumpFiles.from(targetDumpFiles)
339
364
}
340
365
}
341
366
342
- @OptIn(BCVExperimentalApi ::class )
343
- private fun WorkQueue.extract (
344
- target : BCVKLibTarget ,
345
- targetDumpFiles : Set <File >,
346
- outputDir : File ,
347
- ) {
348
- val task = this @BCVApiGenerateTask
349
-
350
- @OptIn(BCVInternalApi ::class )
351
- submit(KLibExtractWorker ::class ) worker@{
352
- this @worker.taskPath.set(task.path)
353
- this @worker.strictValidation.set(target.strictValidation)
354
-
355
-
356
-
357
-
358
- }
359
- }
367
+ // @OptIn(BCVExperimentalApi::class)
368
+ // private fun WorkQueue.extract(
369
+ // target: BCVKLibTarget,
370
+ // targetDumpFiles: Set<File>,
371
+ // outputDir: File,
372
+ // ) {
373
+ // val task = this@BCVApiGenerateTask
374
+ //
375
+ // @OptIn(BCVInternalApi::class)
376
+ // submit(KLibExtractWorker::class) worker@{
377
+
378
+ // [email protected] (target.strictValidation)
379
+ //
380
+
381
+
382
+
383
+ // }
384
+ // }
360
385
// endregion
361
386
}
0 commit comments