Skip to content

Commit 9666d74

Browse files
committed
Removed native targets should trigger validation failure
Fixes #234
1 parent 5826452 commit 9666d74

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

api/binary-compatibility-validator.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ public abstract class kotlinx/validation/KotlinKlibExtractAbiTask : org/gradle/a
9999
public fun <init> ()V
100100
public abstract fun getInputAbiFile ()Lorg/gradle/api/file/RegularFileProperty;
101101
public abstract fun getOutputAbiFile ()Lorg/gradle/api/file/RegularFileProperty;
102-
public abstract fun getRequiredTargets ()Lorg/gradle/api/provider/SetProperty;
103102
public final fun getStrictValidation ()Lorg/gradle/api/provider/Property;
103+
public abstract fun getTargetsToRemove ()Lorg/gradle/api/provider/SetProperty;
104104
}
105105

106106
public abstract class kotlinx/validation/KotlinKlibInferAbiTask : org/gradle/api/DefaultTask {

src/main/kotlin/BinaryCompatibilityValidatorPlugin.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ private class KlibValidationPipelineBuilder(
432432
"the golden file stored in the project"
433433
group = "other"
434434
strictValidation.set(extension.klib.strictValidation)
435-
requiredTargets.addAll(supportedTargets())
435+
targetsToRemove.addAll(unsupportedTargets())
436436
inputAbiFile.fileProvider(klibApiDir.map { it.resolve(klibDumpFileName) })
437437
outputAbiFile.set(klibOutputDir.resolve(klibDumpFileName))
438438
}
@@ -536,18 +536,18 @@ private class KlibValidationPipelineBuilder(
536536
}
537537
}
538538

539-
// Compilable targets supported by the host compiler
540-
private fun Project.supportedTargets(): Provider<Set<KlibTarget>> {
539+
// Compilable targets not supported by the host compiler
540+
private fun Project.unsupportedTargets(): Provider<Set<KlibTarget>> {
541541
val banned = bannedTargets() // for testing only
542542
return project.provider {
543543
val hm = HostManager()
544544
project.kotlinMultiplatform.targets.matching { it.emitsKlib }
545545
.asSequence()
546546
.filter {
547547
if (it is KotlinNativeTarget) {
548-
hm.isEnabled(it.konanTarget) && it.targetName !in banned
548+
!hm.isEnabled(it.konanTarget) || it.targetName in banned
549549
} else {
550-
true
550+
false
551551
}
552552
}
553553
.map { it.toKlibTarget() }

src/main/kotlin/KotlinKlibExtractAbiTask.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ public abstract class KotlinKlibExtractAbiTask : DefaultTask() {
3030
public abstract val inputAbiFile: RegularFileProperty
3131

3232
/**
33-
* List of the targets that the resulting dump should contain.
33+
* List of the targets that need to be filtered out from [inputAbiFile].
3434
*/
3535
@get:Input
36-
public abstract val requiredTargets: SetProperty<KlibTarget>
36+
public abstract val targetsToRemove: SetProperty<KlibTarget>
3737

3838
/**
3939
* Refer to [KlibValidationSettings.strictValidation] for details.
@@ -56,17 +56,16 @@ public abstract class KotlinKlibExtractAbiTask : DefaultTask() {
5656
error("Project ABI file $inputAbiFile is empty.")
5757
}
5858
val dump = KlibDump.from(inputFile)
59-
val enabledTargets = requiredTargets.get().map(KlibTarget::targetName).toSet()
59+
val unsupportedTargets = targetsToRemove.get().map(KlibTarget::targetName).toSet()
6060
// Filter out only unsupported files.
6161
// That ensures that target renaming will be caught and reported as a change.
62-
val targetsToRemove = dump.targets.filter { it.targetName !in enabledTargets }
63-
if (targetsToRemove.isNotEmpty() && strictValidation.get()) {
62+
if (unsupportedTargets.isNotEmpty() && strictValidation.get()) {
6463
throw IllegalStateException(
6564
"Validation could not be performed as some targets (namely, $targetsToRemove) are not available " +
6665
"and the strictValidation mode was enabled."
6766
)
6867
}
69-
dump.remove(targetsToRemove)
68+
dump.remove(unsupportedTargets.map(KlibTarget::parse))
7069
dump.saveTo(outputAbiFile.asFile.get())
7170
}
7271
}

0 commit comments

Comments
 (0)