Skip to content

Require JVM ABI dump presence in empty KMP projects #244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ internal class MultiPlatformSingleJvmTargetTest : BaseKotlinGradleTest() {
}

runner.build().apply {
assertTaskSkipped(":jvmApiDump")
assertTaskUpToDate(":apiDump")
assertTaskSuccess(":jvmApiDump")
assertTaskSuccess(":apiDump")
}
}

Expand All @@ -149,9 +149,28 @@ internal class MultiPlatformSingleJvmTargetTest : BaseKotlinGradleTest() {
}

runner.build().apply {
assertTaskSkipped(":jvmApiCheck")
assertTaskUpToDate(":apiCheck")
assertTaskSuccess(":jvmApiCheck")
assertTaskSuccess(":apiCheck")
}
}

@Test
fun testApiCheckFailsForEmptyProjectWithoutDumpFile() {
val runner = test {
buildGradleKts {
resolve("/examples/gradle/base/multiplatformWithSingleJvmTarget.gradle.kts")
}

runner {
arguments.add(":apiCheck")
}
}

runner.buildAndFail().apply {
assertTaskFailure(":jvmApiCheck")
assertThat(output).contains(
"Expected file with API declarations 'api${File.separator}${rootProjectDir.name}.api' does not exist"
)
}
}

Expand Down
8 changes: 1 addition & 7 deletions src/main/kotlin/BinaryCompatibilityValidatorPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ private fun Project.configureKotlinCompilation(
val apiBuildDir = apiDirProvider.flatMap { f -> layout.buildDirectory.asFile.map { it.resolve(f) } }

val apiBuild = task<KotlinApiBuildTask>(targetConfig.apiTaskName("Build")) {
// Do not enable task for empty umbrella modules
isEnabled = apiCheckEnabled(projectName, extension) && compilation.hasAnySources()
isEnabled = apiCheckEnabled(projectName, extension)
// 'group' is not specified deliberately, so it will be hidden from ./gradlew tasks
description =
"Builds Kotlin API for 'main' compilations of $projectName. Complementary task and shouldn't be called manually"
Expand Down Expand Up @@ -562,7 +561,6 @@ private class KlibValidationPipelineBuilder(
): TaskProvider<KotlinKlibAbiBuildTask> {
val projectName = project.name
val buildTask = project.task<KotlinKlibAbiBuildTask>(targetConfig.apiTaskName("Build")) {
// Do not enable task for empty umbrella modules
isEnabled = klibAbiCheckEnabled(projectName, extension)
// 'group' is not specified deliberately, so it will be hidden from ./gradlew tasks
description = "Builds Kotlin KLib ABI dump for 'main' compilations of $projectName. " +
Expand Down Expand Up @@ -631,7 +629,3 @@ private val Project.jvmDumpFileName: String
get() = "$name.api"
private val Project.klibDumpFileName: String
get() = "$name.klib.api"

private fun KotlinCompilation<KotlinCommonOptions>.hasAnySources(): Boolean = allKotlinSourceSets.any {
it.kotlin.srcDirs.any(File::exists)
}