From 3d74bb583066bbef67231a71d78aaecf82b0495e Mon Sep 17 00:00:00 2001 From: Filipp Zhinkin Date: Tue, 25 Jun 2024 17:33:38 +0200 Subject: [PATCH 1/2] 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 --- .../test/MultiPlatformSingleJvmTargetTest.kt | 27 ++++++++++++++++--- .../BinaryCompatibilityValidatorPlugin.kt | 6 +---- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/functionalTest/kotlin/kotlinx/validation/test/MultiPlatformSingleJvmTargetTest.kt b/src/functionalTest/kotlin/kotlinx/validation/test/MultiPlatformSingleJvmTargetTest.kt index 94a2cac4..6d050ee5 100644 --- a/src/functionalTest/kotlin/kotlinx/validation/test/MultiPlatformSingleJvmTargetTest.kt +++ b/src/functionalTest/kotlin/kotlinx/validation/test/MultiPlatformSingleJvmTargetTest.kt @@ -129,8 +129,8 @@ internal class MultiPlatformSingleJvmTargetTest : BaseKotlinGradleTest() { } runner.build().apply { - assertTaskSkipped(":jvmApiDump") - assertTaskUpToDate(":apiDump") + assertTaskSuccess(":jvmApiDump") + assertTaskSuccess(":apiDump") } } @@ -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" + ) } } diff --git a/src/main/kotlin/BinaryCompatibilityValidatorPlugin.kt b/src/main/kotlin/BinaryCompatibilityValidatorPlugin.kt index ccaf4d2c..87ec1e59 100644 --- a/src/main/kotlin/BinaryCompatibilityValidatorPlugin.kt +++ b/src/main/kotlin/BinaryCompatibilityValidatorPlugin.kt @@ -215,7 +215,7 @@ private fun Project.configureKotlinCompilation( val apiBuild = task(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" @@ -631,7 +631,3 @@ private val Project.jvmDumpFileName: String get() = "$name.api" private val Project.klibDumpFileName: String get() = "$name.klib.api" - -private fun KotlinCompilation.hasAnySources(): Boolean = allKotlinSourceSets.any { - it.kotlin.srcDirs.any(File::exists) -} From e3a2d198ab0ff09d97f69d45d0d65333c5811129 Mon Sep 17 00:00:00 2001 From: Filipp Zhinkin Date: Wed, 26 Jun 2024 09:39:29 +0200 Subject: [PATCH 2/2] Removed obsolete comments --- src/main/kotlin/BinaryCompatibilityValidatorPlugin.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/kotlin/BinaryCompatibilityValidatorPlugin.kt b/src/main/kotlin/BinaryCompatibilityValidatorPlugin.kt index 87ec1e59..3930a340 100644 --- a/src/main/kotlin/BinaryCompatibilityValidatorPlugin.kt +++ b/src/main/kotlin/BinaryCompatibilityValidatorPlugin.kt @@ -214,7 +214,6 @@ private fun Project.configureKotlinCompilation( val apiBuildDir = apiDirProvider.flatMap { f -> layout.buildDirectory.asFile.map { it.resolve(f) } } val apiBuild = task(targetConfig.apiTaskName("Build")) { - // Do not enable task for empty umbrella modules isEnabled = apiCheckEnabled(projectName, extension) // 'group' is not specified deliberately, so it will be hidden from ./gradlew tasks description = @@ -562,7 +561,6 @@ private class KlibValidationPipelineBuilder( ): TaskProvider { val projectName = project.name val buildTask = project.task(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. " +