Skip to content

Commit e2c1ae3

Browse files
authored
Align klib validation behavior for empty projects with other targets (#247)
Closes #246
1 parent 0dd6e41 commit e2c1ae3

File tree

5 files changed

+32
-13
lines changed

5 files changed

+32
-13
lines changed

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -700,14 +700,16 @@ internal class KlibVerificationTests : BaseKotlinGradleTest() {
700700
runApiDump()
701701
}
702702

703-
runner.withDebug(true).build().apply {
704-
assertTaskSkipped(":klibApiDump")
703+
runner.build().apply {
704+
assertTaskSuccess(":klibApiDump")
705705
}
706-
assertFalse(runner.projectDir.resolve("api").exists())
706+
val apiDumpFile = rootProjectAbiDump("testproject")
707+
assertTrue(apiDumpFile.exists())
708+
assertTrue(apiDumpFile.readText().isEmpty())
707709
}
708710

709711
@Test
710-
fun `apiDump should remove dump file if the project does not contain sources anymore`() {
712+
fun `apiDump should dump empty file if the project does not contain sources anymore`() {
711713
val runner = test {
712714
baseProjectSetting()
713715
addToSrcSet("/examples/classes/AnotherBuildConfig.kt", sourceSet = "commonTest")
@@ -720,7 +722,9 @@ internal class KlibVerificationTests : BaseKotlinGradleTest() {
720722
runner.build().apply {
721723
assertTaskSuccess(":klibApiDump")
722724
}
723-
assertFalse(runner.projectDir.resolve("api").resolve("testproject.klib.api").exists())
725+
val dumpFile = rootProjectAbiDump("testproject")
726+
assertTrue(dumpFile.exists())
727+
assertTrue(dumpFile.readText().isEmpty())
724728
}
725729

726730
@Test
@@ -735,7 +739,7 @@ internal class KlibVerificationTests : BaseKotlinGradleTest() {
735739
}
736740

737741
@Test
738-
fun `apiCheck should fail for empty project`() {
742+
fun `apiCheck should fail for empty project without a dump file`() {
739743
val runner = test {
740744
baseProjectSetting()
741745
addToSrcSet("/examples/classes/AnotherBuildConfig.kt", sourceSet = "commonTest")
@@ -749,6 +753,21 @@ internal class KlibVerificationTests : BaseKotlinGradleTest() {
749753
}
750754
}
751755

756+
@Test
757+
fun `apiCheck should not fail for empty project with an empty dump file`() {
758+
val runner = test {
759+
baseProjectSetting()
760+
addToSrcSet("/examples/classes/AnotherBuildConfig.kt", sourceSet = "commonTest")
761+
abiFile("testproject") {
762+
// empty dump file
763+
}
764+
runApiCheck()
765+
}
766+
runner.build().apply {
767+
assertTaskSuccess(":klibApiCheck")
768+
}
769+
}
770+
752771
@Test
753772
fun `apiDump for a project with generated sources only`() {
754773
val runner = test {

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ internal class MultipleJvmTargetsTest : BaseKotlinGradleTest() {
124124
assertTaskSuccess(":jvmApiDump")
125125
assertTaskSuccess(":anotherJvmApiDump")
126126

127-
System.err.println(output)
128-
129127
val anotherExpectedApi = readFileList("/examples/classes/Subsub1Class.dump")
130128
assertThat(anotherApiDump.readText()).isEqualToIgnoringNewLines(anotherExpectedApi)
131129

src/main/kotlin/-Utils.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ public class KlibDumpMetadata(
5353
* happen for an empty project, a project having only test targets,
5454
* or a project that has no sources for a particular target),
5555
* [KlibDumpMetadata] will not force an error.
56-
* Instead, a dependent task will be skipped.
56+
* It's up to [KlibDumpMetadata] users to check if a [dumpFile] exists and
57+
* perform a required action accordingly.
5758
*/
5859
@get:InputFiles
59-
@get:SkipWhenEmpty
6060
@get:PathSensitive(PathSensitivity.RELATIVE)
6161
public val dumpFile: RegularFileProperty
6262
) : Serializable

src/main/kotlin/KotlinKlibExtractAbiTask.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import org.gradle.api.file.RegularFileProperty
1313
import org.gradle.api.provider.Property
1414
import org.gradle.api.provider.SetProperty
1515
import org.gradle.api.tasks.*
16+
import java.nio.file.Files
17+
import java.nio.file.StandardCopyOption
1618

1719
/**
1820
* Extracts dump for targets supported by the host compiler from a merged API dump stored in a project.
@@ -58,7 +60,8 @@ public abstract class KotlinKlibExtractAbiTask : DefaultTask() {
5860
"Please ensure that ':apiDump' was executed in order to get API dump to compare the build against")
5961
}
6062
if (inputFile.length() == 0L) {
61-
error("Project ABI file ${inputFile.relativeTo(rootDir)} is empty.")
63+
Files.copy(inputFile.toPath(), outputAbiFile.asFile.get().toPath(), StandardCopyOption.REPLACE_EXISTING)
64+
return
6265
}
6366
val dump = KlibDump.from(inputFile)
6467
val unsupportedTargets = targetsToRemove.get().map(KlibTarget::targetName).toSet()

src/main/kotlin/KotlinKlibMergeAbiTask.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ public abstract class KotlinKlibMergeAbiTask : DefaultTask() {
2020
/**
2121
* Dumps to merge.
2222
*
23-
* If a file referred by [KlibDumpMetadata.dumpFile] does not exist, it will be ignored and corresponding
24-
* target will not be mentioned in the resulting merged dump.
23+
* If there is no dump for a particular target, its [KlibDumpMetadata.dumpFile] won't exist.
2524
*/
2625
@get:Nested
2726
public abstract val dumps: SetProperty<KlibDumpMetadata>

0 commit comments

Comments
 (0)