Skip to content

Commit 3590611

Browse files
authored
Require JVM ABI dump presence in empty KMP projects (#244)
* Require JVM ABI dump presence in empty KMP project Currently, only JVM ABI validation in KMP projects allows having no dump file. In other cases (JVM ABI validation in K/JVM project or KLib validation) require the presence of an ABI dump file. Lack of such a file is treated as a validation error. The main motivation for having a dump files instead of simply ignoring such projects is that otherwise BCV won't be able to catch the case when all sources were removed from a project. Fixes #243
1 parent 33a495b commit 3590611

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

src/functionalTest/kotlin/kotlinx/validation/test/MultiPlatformSingleJvmTargetTest.kt

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ internal class MultiPlatformSingleJvmTargetTest : BaseKotlinGradleTest() {
129129
}
130130

131131
runner.build().apply {
132-
assertTaskSkipped(":jvmApiDump")
133-
assertTaskUpToDate(":apiDump")
132+
assertTaskSuccess(":jvmApiDump")
133+
assertTaskSuccess(":apiDump")
134134
}
135135
}
136136

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

151151
runner.build().apply {
152-
assertTaskSkipped(":jvmApiCheck")
153-
assertTaskUpToDate(":apiCheck")
152+
assertTaskSuccess(":jvmApiCheck")
153+
assertTaskSuccess(":apiCheck")
154+
}
155+
}
154156

157+
@Test
158+
fun testApiCheckFailsForEmptyProjectWithoutDumpFile() {
159+
val runner = test {
160+
buildGradleKts {
161+
resolve("/examples/gradle/base/multiplatformWithSingleJvmTarget.gradle.kts")
162+
}
163+
164+
runner {
165+
arguments.add(":apiCheck")
166+
}
167+
}
168+
169+
runner.buildAndFail().apply {
170+
assertTaskFailure(":jvmApiCheck")
171+
assertThat(output).contains(
172+
"Expected file with API declarations 'api${File.separator}${rootProjectDir.name}.api' does not exist"
173+
)
155174
}
156175
}
157176

src/main/kotlin/BinaryCompatibilityValidatorPlugin.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,7 @@ private fun Project.configureKotlinCompilation(
214214
val apiBuildDir = apiDirProvider.flatMap { f -> layout.buildDirectory.asFile.map { it.resolve(f) } }
215215

216216
val apiBuild = task<KotlinApiBuildTask>(targetConfig.apiTaskName("Build")) {
217-
// Do not enable task for empty umbrella modules
218-
isEnabled = apiCheckEnabled(projectName, extension) && compilation.hasAnySources()
217+
isEnabled = apiCheckEnabled(projectName, extension)
219218
// 'group' is not specified deliberately, so it will be hidden from ./gradlew tasks
220219
description =
221220
"Builds Kotlin API for 'main' compilations of $projectName. Complementary task and shouldn't be called manually"
@@ -562,7 +561,6 @@ private class KlibValidationPipelineBuilder(
562561
): TaskProvider<KotlinKlibAbiBuildTask> {
563562
val projectName = project.name
564563
val buildTask = project.task<KotlinKlibAbiBuildTask>(targetConfig.apiTaskName("Build")) {
565-
// Do not enable task for empty umbrella modules
566564
isEnabled = klibAbiCheckEnabled(projectName, extension)
567565
// 'group' is not specified deliberately, so it will be hidden from ./gradlew tasks
568566
description = "Builds Kotlin KLib ABI dump for 'main' compilations of $projectName. " +
@@ -631,7 +629,3 @@ private val Project.jvmDumpFileName: String
631629
get() = "$name.api"
632630
private val Project.klibDumpFileName: String
633631
get() = "$name.klib.api"
634-
635-
private fun KotlinCompilation<KotlinCommonOptions>.hasAnySources(): Boolean = allKotlinSourceSets.any {
636-
it.kotlin.srcDirs.any(File::exists)
637-
}

0 commit comments

Comments
 (0)