Skip to content
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 @@ -700,14 +700,16 @@ internal class KlibVerificationTests : BaseKotlinGradleTest() {
runApiDump()
}

runner.withDebug(true).build().apply {
assertTaskSkipped(":klibApiDump")
runner.build().apply {
assertTaskSuccess(":klibApiDump")
}
assertFalse(runner.projectDir.resolve("api").exists())
val apiDumpFile = rootProjectAbiDump("testproject")
assertTrue(apiDumpFile.exists())
assertTrue(apiDumpFile.readText().isEmpty())
}

@Test
fun `apiDump should remove dump file if the project does not contain sources anymore`() {
fun `apiDump should dump empty file if the project does not contain sources anymore`() {
val runner = test {
baseProjectSetting()
addToSrcSet("/examples/classes/AnotherBuildConfig.kt", sourceSet = "commonTest")
Expand All @@ -720,7 +722,9 @@ internal class KlibVerificationTests : BaseKotlinGradleTest() {
runner.build().apply {
assertTaskSuccess(":klibApiDump")
}
assertFalse(runner.projectDir.resolve("api").resolve("testproject.klib.api").exists())
val dumpFile = rootProjectAbiDump("testproject")
assertTrue(dumpFile.exists())
assertTrue(dumpFile.readText().isEmpty())
}

@Test
Expand All @@ -735,7 +739,7 @@ internal class KlibVerificationTests : BaseKotlinGradleTest() {
}

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

@Test
fun `apiCheck should not fail for empty project with an empty dump file`() {
val runner = test {
baseProjectSetting()
addToSrcSet("/examples/classes/AnotherBuildConfig.kt", sourceSet = "commonTest")
abiFile("testproject") {
// empty dump file
}
runApiCheck()
}
runner.build().apply {
assertTaskSuccess(":klibApiCheck")
}
}

@Test
fun `apiDump for a project with generated sources only`() {
val runner = test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ internal class MultipleJvmTargetsTest : BaseKotlinGradleTest() {
assertTaskSuccess(":jvmApiDump")
assertTaskSuccess(":anotherJvmApiDump")

System.err.println(output)

val anotherExpectedApi = readFileList("/examples/classes/Subsub1Class.dump")
assertThat(anotherApiDump.readText()).isEqualToIgnoringNewLines(anotherExpectedApi)

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/-Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public class KlibDumpMetadata(
* happen for an empty project, a project having only test targets,
* or a project that has no sources for a particular target),
* [KlibDumpMetadata] will not force an error.
* Instead, a dependent task will be skipped.
* It's up to [KlibDumpMetadata] users to check if a [dumpFile] exists and
* perform a required action accordingly.
*/
@get:InputFiles
@get:SkipWhenEmpty
@get:PathSensitive(PathSensitivity.RELATIVE)
public val dumpFile: RegularFileProperty
) : Serializable
5 changes: 4 additions & 1 deletion src/main/kotlin/KotlinKlibExtractAbiTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
import org.gradle.api.provider.SetProperty
import org.gradle.api.tasks.*
import java.nio.file.Files
import java.nio.file.StandardCopyOption

/**
* Extracts dump for targets supported by the host compiler from a merged API dump stored in a project.
Expand Down Expand Up @@ -58,7 +60,8 @@ public abstract class KotlinKlibExtractAbiTask : DefaultTask() {
"Please ensure that ':apiDump' was executed in order to get API dump to compare the build against")
}
if (inputFile.length() == 0L) {
error("Project ABI file ${inputFile.relativeTo(rootDir)} is empty.")
Files.copy(inputFile.toPath(), outputAbiFile.asFile.get().toPath(), StandardCopyOption.REPLACE_EXISTING)
return
}
val dump = KlibDump.from(inputFile)
val unsupportedTargets = targetsToRemove.get().map(KlibTarget::targetName).toSet()
Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/KotlinKlibMergeAbiTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public abstract class KotlinKlibMergeAbiTask : DefaultTask() {
/**
* Dumps to merge.
*
* If a file referred by [KlibDumpMetadata.dumpFile] does not exist, it will be ignored and corresponding
* target will not be mentioned in the resulting merged dump.
* If there is no dump for a particular target, its [KlibDumpMetadata.dumpFile] won't exist.
*/
@get:Nested
public abstract val dumps: SetProperty<KlibDumpMetadata>
Expand Down