Skip to content

Commit

Permalink
Removed native targets should trigger validation failure
Browse files Browse the repository at this point in the history
Fixes #234
  • Loading branch information
fzhinkin committed Jun 24, 2024
1 parent e44424f commit 4176bbb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion api/binary-compatibility-validator.api
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public abstract class kotlinx/validation/KotlinKlibExtractAbiTask : org/gradle/a
public fun <init> ()V
public abstract fun getInputAbiFile ()Lorg/gradle/api/file/RegularFileProperty;
public abstract fun getOutputAbiFile ()Lorg/gradle/api/file/RegularFileProperty;
public abstract fun getRequiredTargets ()Lorg/gradle/api/provider/SetProperty;
public final fun getStrictValidation ()Lorg/gradle/api/provider/Property;
public abstract fun getTargetsToRemove ()Lorg/gradle/api/provider/SetProperty;
}

public abstract class kotlinx/validation/KotlinKlibInferAbiTask : org/gradle/api/DefaultTask {
Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/BinaryCompatibilityValidatorPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ private class KlibValidationPipelineBuilder(
"the golden file stored in the project"
group = "other"
strictValidation.set(extension.klib.strictValidation)
requiredTargets.addAll(supportedTargets())
targetsToRemove.addAll(unsupportedTargets())
inputAbiFile.fileProvider(klibApiDir.map { it.resolve(klibDumpFileName) })
outputAbiFile.fileProvider(klibOutputDir.map { it.resolve(klibDumpFileName) })
}
Expand Down Expand Up @@ -534,18 +534,18 @@ private class KlibValidationPipelineBuilder(
}
}

// Compilable targets supported by the host compiler
private fun Project.supportedTargets(): Provider<Set<KlibTarget>> {
// Compilable targets not supported by the host compiler
private fun Project.unsupportedTargets(): Provider<Set<KlibTarget>> {
val banned = bannedTargets() // for testing only
return project.provider {
val hm = HostManager()
project.kotlinMultiplatform.targets.matching { it.emitsKlib }
.asSequence()
.filter {
if (it is KotlinNativeTarget) {
hm.isEnabled(it.konanTarget) && it.targetName !in banned
!hm.isEnabled(it.konanTarget) || it.targetName in banned
} else {
true
false
}
}
.map { it.toKlibTarget() }
Expand Down
11 changes: 5 additions & 6 deletions src/main/kotlin/KotlinKlibExtractAbiTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public abstract class KotlinKlibExtractAbiTask : DefaultTask() {
public abstract val inputAbiFile: RegularFileProperty

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

/**
* Refer to [KlibValidationSettings.strictValidation] for details.
Expand Down Expand Up @@ -61,17 +61,16 @@ public abstract class KotlinKlibExtractAbiTask : DefaultTask() {
error("Project ABI file ${inputFile.relativeTo(rootDir)} is empty.")
}
val dump = KlibDump.from(inputFile)
val enabledTargets = requiredTargets.get().map(KlibTarget::targetName).toSet()
val unsupportedTargets = targetsToRemove.get().map(KlibTarget::targetName).toSet()
// Filter out only unsupported files.
// That ensures that target renaming will be caught and reported as a change.
val targetsToRemove = dump.targets.filter { it.targetName !in enabledTargets }
if (targetsToRemove.isNotEmpty() && strictValidation.get()) {
if (unsupportedTargets.isNotEmpty() && strictValidation.get()) {
throw IllegalStateException(
"Validation could not be performed as some targets (namely, $targetsToRemove) are not available " +
"and the strictValidation mode was enabled."
)
}
dump.remove(targetsToRemove)
dump.remove(unsupportedTargets.map(KlibTarget::parse))
dump.saveTo(outputAbiFile.asFile.get())
}
}

0 comments on commit 4176bbb

Please sign in to comment.