@@ -4,7 +4,10 @@ import dev.adamko.kotlin.binary_compatibility_validator.internal.*
44import dev.adamko.kotlin.binary_compatibility_validator.targets.BCVJvmTarget
55import dev.adamko.kotlin.binary_compatibility_validator.targets.BCVKLibTarget
66import 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
811import java.io.File
912import javax.inject.Inject
1013import org.gradle.api.NamedDomainObjectContainer
@@ -71,17 +74,18 @@ constructor(
7174
7275 @TaskAction
7376 fun generate () {
74- val workQueue = prepareWorkQueue()
75-
7677 prepareDirectories()
7778
78- logger.lifecycle( " [ $path ] got ${targets.size} targets : ${targets.joinToString { it.name }} " )
79+ val workQueue = prepareWorkQueue( )
7980
8081 val enabledTargets = targets.matching { it.enabled.getOrElse(true ) }
8182
83+ logger.lifecycle(" [$path ] got ${targets.size} targets (${enabledTargets.size} enabled) : ${targets.joinToString { it.name }} " )
84+
85+ val jvmTargets = enabledTargets.withType<BCVJvmTarget >().sorted()
8286 generateJvmTargets(
8387 workQueue = workQueue,
84- jvmTargets = enabledTargets.withType< BCVJvmTarget >().sorted() ,
88+ jvmTargets = jvmTargets ,
8589 outputApiBuildDir = outputApiBuildDir.get().asFile,
8690 )
8791
@@ -90,7 +94,6 @@ constructor(
9094 val klibTargets = enabledTargets.withType<BCVKLibTarget >()
9195 .filter { it.klibFile.singleOrNull()?.exists() == true }
9296 .sorted()
93-
9497 generateKLibTargets(
9598 workQueue = workQueue,
9699 klibTargets = klibTargets,
@@ -103,26 +106,19 @@ constructor(
103106
104107
105108 private fun prepareWorkQueue (): WorkQueue {
106- fs.delete { delete(temporaryDir) }
107- temporaryDir.mkdirs()
108-
109109 return workers.classLoaderIsolation {
110110 classpath.from(runtimeClasspath)
111111 }
112112 }
113113
114114 private fun prepareDirectories () {
115- val outputApiBuildDir = outputApiBuildDir.get()
116115 fs.delete { delete(outputApiBuildDir) }
117- outputApiBuildDir.asFile.mkdirs()
116+ outputApiBuildDir.get(). asFile.mkdirs()
118117
119- fs.delete { delete(klibTargetsDir.supported) }
118+ fs.delete { delete(workDir) }
119+ workDir.mkdirs()
120120 klibTargetsDir.supported.mkdirs()
121-
122- fs.delete { delete(klibTargetsDir.unsupported) }
123121 klibTargetsDir.unsupported.mkdirs()
124-
125- fs.delete { delete(klibTargetsDir.extracted) }
126122 klibTargetsDir.extracted.mkdirs()
127123 }
128124
@@ -187,7 +183,7 @@ constructor(
187183 private fun generateKLibTargets (
188184 workQueue : WorkQueue ,
189185 outputApiBuildDir : File ,
190- klibTargets : Collection <BCVKLibTarget >,
186+ klibTargets : List <BCVKLibTarget >,
191187 ) {
192188 if (klibTargets.isEmpty()) {
193189 logger.info(" [$path ] No enabled KLib targets" )
@@ -201,19 +197,30 @@ constructor(
201197 generateSupportedKLibTargets(workQueue, supportedKLibTargets)
202198 generateUnsupportedKLibTargets(workQueue, unsupportedKLibTargets)
203199
204- workQueue.await()
200+ val allTargetDumpFiles = buildSet {
201+ addAll(klibTargetsDir.supported.walk().filter { it.isFile })
202+ addAll(klibTargetsDir.unsupported.walk().filter { it.isFile })
203+ }
205204
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+ )
209212
210- mergeDumpFiles( workQueue, allTargetDumpFiles, outputApiBuildDir )
213+ // workQueue.extract( )
211214 }
212215
213216 private fun generateSupportedKLibTargets (
214217 workQueue : WorkQueue ,
215218 supportedKLibTargets : List <BCVKLibTarget >
216219 ) {
220+ if (supportedKLibTargets.isEmpty()) {
221+ logger.info(" [$path ] No supported enabled KLib targets" )
222+ return
223+ }
217224 logger.lifecycle(" [$path ] generating ${supportedKLibTargets.size} supported KLib targets : ${supportedKLibTargets.joinToString { it.name }} " )
218225
219226 val duration = measureTime {
@@ -233,6 +240,10 @@ constructor(
233240 workQueue : WorkQueue ,
234241 unsupportedKLibTargets : List <BCVKLibTarget >
235242 ) {
243+ if (unsupportedKLibTargets.isEmpty()) {
244+ logger.info(" [$path ] No unsupported enabled KLib targets" )
245+ return
246+ }
236247 logger.lifecycle(" [$path ] generating ${unsupportedKLibTargets.size} unsupported KLib targets : ${unsupportedKLibTargets.joinToString { it.name }} " )
237248
238249 val duration = measureTime {
@@ -245,6 +256,7 @@ constructor(
245256 outputDir = klibTargetsDir.unsupported,
246257 )
247258 }
259+ workQueue.await()
248260 }
249261
250262 logger.lifecycle(" [$path ] finished generating unsupported KLib targets in $duration " )
@@ -254,20 +266,26 @@ constructor(
254266 private fun mergeDumpFiles (
255267 workQueue : WorkQueue ,
256268 allTargetDumpFiles : Set <File >,
257- outputApiBuildDir : File
269+ outputApiBuildDir : File ,
270+ targets : List <BCVKLibTarget >,
271+ strictValidation : Boolean ,
258272 ) {
259273 logger.lifecycle(" [$path ] merging ${allTargetDumpFiles.size} dump files : ${allTargetDumpFiles.joinToString { it.name }} " )
260274
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+ }
267285
268286 if (logger.isLifecycleEnabled) {
269287 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 " )
271289 }
272290 }
273291
@@ -288,8 +306,7 @@ constructor(
288306
289307 this @worker.klib.set(target.klibFile.singleFile)
290308 this @worker.signatureVersion.set(target.signatureVersion)
291- this @worker.strictValidation.set(target.strictValidation)
292- // [email protected] (target.supportedByCurrentHost)309+ // [email protected] (target.strictValidation)293310
294311295312
@@ -325,37 +342,45 @@ constructor(
325342 projectName : String ,
326343 targetDumpFiles : Set <File >,
327344 outputDir : File ,
345+ supportedTargets : List <String >,
346+ strictValidation : Boolean ,
328347 ) {
329348 val task = this @BCVApiGenerateTask
330349
331350 @OptIn(BCVInternalApi ::class )
332351 submit(KLibMergeWorker ::class ) worker@{
333- this @worker.projectName.set(projectName)
352+ 334353 this @worker.taskPath.set(task.path)
335354
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)
337362
338363 this @worker.targetDumpFiles.from(targetDumpFiles)
339364 }
340365 }
341366
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+ // }
360385 // endregion
361386}
0 commit comments