Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fzhinkin committed Feb 1, 2024
1 parent 50ebf8b commit f733b96
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 62 deletions.
2 changes: 1 addition & 1 deletion docs/design/KLibSupport.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The document described assumptions that led to the current KLib ABI validation implementation.
The document describes assumptions that led to the current KLib ABI validation implementation.

### Motivation and assumptions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import org.junit.Rule
import org.junit.rules.TemporaryFolder
import java.io.File

internal const val KLIB_PHONY_TARGET_NAME = "klib"
internal const val KLIB_ALL_PHONY_TARGET_NAME = "klib-all"

public open class BaseKotlinGradleTest {
@Rule
@JvmField
Expand All @@ -21,14 +18,7 @@ public open class BaseKotlinGradleTest {

internal val rootProjectApiDump: File get() = rootProjectDir.resolve("$API_DIR/${rootProjectDir.name}.api")

internal fun rootProjectAbiDump(target: String, project: String = rootProjectDir.name): File {
// TODO: rewrite
val suffix = if (target != KLIB_PHONY_TARGET_NAME) "api" else "klib.api"
return rootProjectDir.resolve("$API_DIR/$target/$project.$suffix")
}

internal fun rootProjectAbiDump(project: String = rootProjectDir.name): File {
// TODO: rewrite
return rootProjectDir.resolve("$API_DIR/$project.klib.api")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ import kotlin.test.assertTrue

internal const val BANNED_TARGETS_PROPERTY_NAME = "binary.compatibility.validator.klib.targets.blacklist.for.testing"

private fun KLibVerificationTests.checkKlibDump(buildResult: BuildResult, expectedDumpFileName: String,
projectName: String = "testproject",
dumpTask: String = ":apiDump",
projectWithMultipleDumps: Boolean = false) {
private fun KLibVerificationTests.checkKlibDump(
buildResult: BuildResult,
expectedDumpFileName: String,
projectName: String = "testproject",
dumpTask: String = ":apiDump"
) {
buildResult.assertTaskSuccess(dumpTask)

val generatedDump = if (projectWithMultipleDumps) {
rootProjectAbiDump(target = KLIB_PHONY_TARGET_NAME, project = projectName)
} else {
rootProjectAbiDump(projectName)
}
val generatedDump = rootProjectAbiDump(projectName)
assertTrue(generatedDump.exists(), "There are no dumps generated for KLibs")

val expected = readFileList(expectedDumpFileName)
Expand Down Expand Up @@ -140,14 +138,10 @@ internal class KLibVerificationTests : BaseKotlinGradleTest() {
}

runner.build().apply {
assertTaskSuccess(":apiDump")

// not common, but built from the common source set
val dump = rootProjectAbiDump("testproject")
assertTrue(dump.exists(), "Dump does not exist")

val expectedDump = readFileList("/examples/classes/AnotherBuildConfigLinuxArm64Extra.klib.dump")
Assertions.assertThat(dump.readText()).isEqualToIgnoringNewLines(expectedDump)
checkKlibDump(
this,
"/examples/classes/AnotherBuildConfigLinuxArm64Extra.klib.dump"
)
}
}

Expand All @@ -170,8 +164,7 @@ internal class KLibVerificationTests : BaseKotlinGradleTest() {
}

runner.build().apply {
checkKlibDump(this, "/examples/classes/AnotherBuildConfig.klib.dump",
projectWithMultipleDumps = false)
checkKlibDump(this, "/examples/classes/AnotherBuildConfig.klib.dump")

val jvmApiDump = rootProjectDir.resolve("$API_DIR/testproject.api")
assertTrue(jvmApiDump.exists(), "No API dump for JVM")
Expand Down Expand Up @@ -403,7 +396,7 @@ internal class KLibVerificationTests : BaseKotlinGradleTest() {
}

@Test
fun `apiCheck should fail if a target is not supported`() {
fun `apiCheck should not fail if a target is not supported`() {
val runner = test {
settingsGradleKts {
resolve("/examples/gradle/settings/settings-name-testproject.gradle.kts")
Expand All @@ -414,15 +407,18 @@ internal class KLibVerificationTests : BaseKotlinGradleTest() {
kotlin("TopLevelDeclarations.kt", "commonMain") {
resolve("/examples/classes/TopLevelDeclarations.kt")
}
abiFile(projectName = "testproject", target = KLIB_PHONY_TARGET_NAME) {
abiFile(projectName = "testproject") {
resolve("/examples/classes/TopLevelDeclarations.klib.dump")
}
runner {
arguments.add("-P$BANNED_TARGETS_PROPERTY_NAME=linuxArm64")
arguments.add(":apiCheck")
}
}

runner.buildAndFail()
runner.build().apply {
assertTaskSuccess(":apiCheck")
}
}

@Test
Expand Down Expand Up @@ -501,8 +497,10 @@ internal class KLibVerificationTests : BaseKotlinGradleTest() {
}
}

checkKlibDump(runner.build(), "/examples/classes/TopLevelDeclarations.klib.with.linux.dump",
dumpTask = ":klibApiDump")
checkKlibDump(
runner.build(), "/examples/classes/TopLevelDeclarations.klib.with.linux.dump",
dumpTask = ":klibApiDump"
)
}

@Test
Expand All @@ -528,8 +526,10 @@ internal class KLibVerificationTests : BaseKotlinGradleTest() {

runner.buildAndFail().apply {
assertTaskFailure(":linuxArm64ApiInferAbiDump")
Assertions.assertThat(output).contains("The target linuxArm64 is not supported by the host compiler " +
"and there are no targets similar to linuxArm64 to infer a dump from it.")
Assertions.assertThat(output).contains(
"The target linuxArm64 is not supported by the host compiler " +
"and there are no targets similar to linuxArm64 to infer a dump from it."
)
}
}

Expand All @@ -546,16 +546,18 @@ internal class KLibVerificationTests : BaseKotlinGradleTest() {
resolve("/examples/classes/TopLevelDeclarations.kt")
}
runner {
arguments.add("-P$BANNED_TARGETS_PROPERTY_NAME=linuxArm64,linuxX64,mingwX64," +
"androidNativeArm32,androidNativeArm64,androidNativeX64,androidNativeX86")
arguments.add(
"-P$BANNED_TARGETS_PROPERTY_NAME=linuxArm64,linuxX64,mingwX64," +
"androidNativeArm32,androidNativeArm64,androidNativeX64,androidNativeX86"
)
arguments.add(":klibApiDump")
}
}

runner.buildAndFail().apply {
Assertions.assertThat(output).contains(
"is not supported by the host compiler and there are no targets similar to"
)
Assertions.assertThat(output).contains(
"is not supported by the host compiler and there are no targets similar to"
)
}
}

Expand All @@ -576,8 +578,10 @@ internal class KLibVerificationTests : BaseKotlinGradleTest() {
resolve("/examples/classes/TopLevelDeclarations.klib.dump")
}
runner {
arguments.add("-P$BANNED_TARGETS_PROPERTY_NAME=linuxArm64,linuxX64,mingwX64," +
"androidNativeArm32,androidNativeArm64,androidNativeX64,androidNativeX86")
arguments.add(
"-P$BANNED_TARGETS_PROPERTY_NAME=linuxArm64,linuxX64,mingwX64," +
"androidNativeArm32,androidNativeArm64,androidNativeX64,androidNativeX86"
)
arguments.add(":klibApiCheck")
}
}
Expand Down Expand Up @@ -607,8 +611,10 @@ internal class KLibVerificationTests : BaseKotlinGradleTest() {
}
}

checkKlibDump(runner.build(), "/examples/classes/AnotherBuildConfig.klib.clash.dump",
dumpTask = ":klibApiDump")
checkKlibDump(
runner.build(), "/examples/classes/AnotherBuildConfig.klib.clash.dump",
dumpTask = ":klibApiDump"
)
}

@Test
Expand All @@ -629,8 +635,10 @@ internal class KLibVerificationTests : BaseKotlinGradleTest() {
}
}

checkKlibDump(runner.build(), "/examples/classes/AnotherBuildConfig.klib.custom.dump",
dumpTask = ":klibApiDump")
checkKlibDump(
runner.build(), "/examples/classes/AnotherBuildConfig.klib.custom.dump",
dumpTask = ":klibApiDump"
)
}

@Test
Expand All @@ -656,7 +664,9 @@ internal class KLibVerificationTests : BaseKotlinGradleTest() {
}
}

checkKlibDump(runner.build(), "/examples/classes/AnotherBuildConfigLinux.klib.grouping.dump",
dumpTask = ":klibApiDump")
checkKlibDump(
runner.build(), "/examples/classes/AnotherBuildConfigLinux.klib.grouping.dump",
dumpTask = ":klibApiDump"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ class NonPublicMarkersTest : BaseKotlinGradleTest() {
fun testIgnoredMarkersOnPropertiesForNativeTargets() {
val runner = test {
settingsGradleKts {
resolve("examples/gradle/settings/settings-name-testproject.gradle.kts")
resolve("/examples/gradle/settings/settings-name-testproject.gradle.kts")
}

buildGradleKts {
resolve("examples/gradle/base/withNativePlugin.gradle.kts")
resolve("examples/gradle/configuration/nonPublicMarkers/markers.gradle.kts")
resolve("/examples/gradle/base/withNativePlugin.gradle.kts")
resolve("/examples/gradle/configuration/nonPublicMarkers/markers.gradle.kts")
}

kotlin("Properties.kt", sourceSet = "commonMain") {
resolve("examples/classes/Properties.kt")
resolve("/examples/classes/Properties.kt")
}

commonNativeTargets.forEach {
abiFile(projectName = "testproject", target = it) {
resolve("examples/classes/Properties.klib.dump")
resolve("/examples/classes/Properties.klib.dump")
}
}

Expand Down
13 changes: 6 additions & 7 deletions src/main/kotlin/BinaryCompatibilityValidatorPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ import org.jetbrains.kotlin.library.abi.LibraryAbiReader
import java.io.*
import kotlin.text.split

internal const val KLIB_PHONY_TARGET_NAME = "klib"
internal const val KLIB_ALL_PHONY_TARGET_NAME = "klib-all"

public class BinaryCompatibilityValidatorPlugin : Plugin<Project> {

@ExperimentalLibraryAbiReader
Expand Down Expand Up @@ -336,7 +333,9 @@ private inline fun <reified T : Task> Project.task(
noinline configuration: T.() -> Unit,
): TaskProvider<T> = tasks.register(name, T::class.java, Action(configuration))

internal const val BANNED_TARGETS_PROPERTY_NAME = "binary.compatibility.validator.klib.targets.blacklist.for.testing"
private const val BANNED_TARGETS_PROPERTY_NAME = "binary.compatibility.validator.klib.targets.blacklist.for.testing"
private const val KLIB_DUMPS_DIRECTORY = "klib"
private const val KLIB_INFERRED_DUMPS_DIRECTORY = "klib-all"

@ExperimentalBCVApi
private class KlibValidationPipelineBuilder(
Expand All @@ -349,9 +348,9 @@ private class KlibValidationPipelineBuilder(
// In the intermediate phase of Klib dump generation there are always multiple targets, thus we need
// target-based directory tree.
intermediateFilesConfig = project.provider { DirConfig.TARGET_DIR }
val klibApiDirConfig = dirConfig?.map { TargetConfig(project, extension, KLIB_PHONY_TARGET_NAME, dirConfig) }
val klibDumpConfig = TargetConfig(project, extension, KLIB_PHONY_TARGET_NAME, intermediateFilesConfig)
val klibDumpAllConfig = TargetConfig(project, extension, KLIB_ALL_PHONY_TARGET_NAME, intermediateFilesConfig)
val klibApiDirConfig = dirConfig?.map { TargetConfig(project, extension, KLIB_DUMPS_DIRECTORY, dirConfig) }
val klibDumpConfig = TargetConfig(project, extension, KLIB_DUMPS_DIRECTORY, intermediateFilesConfig)
val klibDumpAllConfig = TargetConfig(project, extension, KLIB_INFERRED_DUMPS_DIRECTORY, intermediateFilesConfig)

val projectDir = project.projectDir
val klibApiDir = klibApiDirConfig?.map {
Expand Down

0 comments on commit f733b96

Please sign in to comment.