[MPP] Remove obsolete targets from KlibBasedMppIT
^KT-58822
This commit is contained in:
committed by
Space Team
parent
8ff67218f5
commit
5af8b9e819
+60
-48
@@ -7,10 +7,10 @@ package org.jetbrains.kotlin.gradle
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.gradle.util.modify
|
import org.jetbrains.kotlin.gradle.util.modify
|
||||||
import org.jetbrains.kotlin.konan.target.HostManager
|
import org.jetbrains.kotlin.konan.target.HostManager
|
||||||
|
import org.junit.Assume
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.zip.ZipFile
|
import java.util.zip.ZipFile
|
||||||
import kotlin.test.Ignore
|
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertFalse
|
import kotlin.test.assertFalse
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
@@ -22,17 +22,19 @@ open class KlibBasedMppIT : BaseGradleIT() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testBuildWithProjectDependency() = testBuildWithDependency {
|
fun testBuildWithProjectDependency() = testBuildWithDependency {
|
||||||
gradleBuildScript().appendText("\n" + """
|
gradleBuildScript().appendText(
|
||||||
|
"\n" + """
|
||||||
dependencies {
|
dependencies {
|
||||||
commonMainImplementation(project("$dependencyModuleName"))
|
commonMainImplementation(project("$dependencyModuleName"))
|
||||||
}
|
}
|
||||||
""".trimIndent())
|
""".trimIndent()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testPublishingAndConsumptionWithEmptySourceSet() = testBuildWithDependency {
|
fun testPublishingAndConsumptionWithEmptySourceSet() = testBuildWithDependency {
|
||||||
// KT-36674
|
// KT-36674
|
||||||
projectDir.resolve("$dependencyModuleName/src/$hostSpecificSourceSet").run {
|
projectDir.resolve("$dependencyModuleName/src/windowsMain").run {
|
||||||
assertTrue { isDirectory }
|
assertTrue { isDirectory }
|
||||||
deleteRecursively()
|
deleteRecursively()
|
||||||
}
|
}
|
||||||
@@ -40,9 +42,8 @@ open class KlibBasedMppIT : BaseGradleIT() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testHostSpecificSourceSetsInTransitiveDependencies() = with(Project("common-klib-lib-and-app")) {
|
fun testCommonSourceSetsInTransitiveDependencies() = with(Project("common-klib-lib-and-app")) {
|
||||||
// KT-41083
|
// On macOS KT-41083 is also validated by publishing a lib with host specific source sets depending on another lib with host-specific source sets
|
||||||
// Publish a lib with host specific source sets depending on another lib with host-specific source sets
|
|
||||||
setupWorkingDir()
|
setupWorkingDir()
|
||||||
val projectDepName = "dependency"
|
val projectDepName = "dependency"
|
||||||
val publishedGroup = "published"
|
val publishedGroup = "published"
|
||||||
@@ -87,22 +88,42 @@ open class KlibBasedMppIT : BaseGradleIT() {
|
|||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
|
|
||||||
// The consumer should correctly receive the klibs of the host-specific source sets
|
val commonModules = listOf(
|
||||||
|
"published-producer-1.0-commonMain-[\\w-]+.klib",
|
||||||
|
"published-dependency-1.0-commonMain-[\\w-]+.klib",
|
||||||
|
).map(::Regex)
|
||||||
|
|
||||||
|
val hostSpecificModules = listOf(
|
||||||
|
"published-producer-1.0-iosMain-[\\w-]+.klib",
|
||||||
|
"published-dependency-1.0-iosMain-[\\w-]+.klib",
|
||||||
|
).map(::Regex)
|
||||||
|
|
||||||
|
val windowsAndLinuxModules = listOf(
|
||||||
|
"published-producer-1.0-windowsAndLinuxMain-[\\w-]+.klib",
|
||||||
|
"published-dependency-1.0-windowsAndLinuxMain-[\\w-]+.klib",
|
||||||
|
).map(::Regex)
|
||||||
|
|
||||||
checkTaskCompileClasspath(
|
checkTaskCompileClasspath(
|
||||||
"compile${hostSpecificSourceSet.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}KotlinMetadata",
|
"compileWindowsAndLinuxMainKotlinMetadata",
|
||||||
listOf(
|
checkModulesInClasspath = commonModules + windowsAndLinuxModules,
|
||||||
"published-producer-1.0-$hostSpecificSourceSet-[\\w-]+.klib",
|
checkModulesNotInClasspath = hostSpecificModules
|
||||||
"published-producer-1.0-commonMain-[\\w-]+.klib",
|
|
||||||
"published-dependency-1.0-$hostSpecificSourceSet-[\\w-]+.klib",
|
|
||||||
"published-dependency-1.0-commonMain-[\\w-]+.klib"
|
|
||||||
).map(::Regex)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// The consumer should correctly receive the klibs of the host-specific source sets
|
||||||
|
|
||||||
|
if (HostManager.hostIsMac) {
|
||||||
|
checkTaskCompileClasspath(
|
||||||
|
"compileIosMainKotlinMetadata",
|
||||||
|
checkModulesInClasspath = commonModules + hostSpecificModules,
|
||||||
|
checkModulesNotInClasspath = windowsAndLinuxModules
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("disable until kotlin/native dependency is updated to include KT-52226")
|
fun testHostSpecificBuildWithPublishedDependency() = testBuildWithDependency {
|
||||||
fun testBuildWithPublishedDependency() = testBuildWithDependency {
|
// Host-specific dependencies are only possible on macOS
|
||||||
|
Assume.assumeTrue(HostManager.hostIsMac)
|
||||||
publishProjectDepAndAddDependency(validateHostSpecificPublication = true)
|
publishProjectDepAndAddDependency(validateHostSpecificPublication = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,14 +134,16 @@ open class KlibBasedMppIT : BaseGradleIT() {
|
|||||||
checkPublishedHostSpecificMetadata(this@build)
|
checkPublishedHostSpecificMetadata(this@build)
|
||||||
}
|
}
|
||||||
|
|
||||||
gradleBuildScript().appendText("\n" + """
|
gradleBuildScript().appendText(
|
||||||
|
"\n" + """
|
||||||
repositories {
|
repositories {
|
||||||
maven("${'$'}rootDir/repo")
|
maven("${'$'}rootDir/repo")
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
commonMainImplementation("$MODULE_GROUP:$dependencyModuleName:1.0")
|
commonMainImplementation("$MODULE_GROUP:$dependencyModuleName:1.0")
|
||||||
}
|
}
|
||||||
""".trimIndent())
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
// prevent Gradle from linking the above dependency to the project:
|
// prevent Gradle from linking the above dependency to the project:
|
||||||
gradleBuildScript(dependencyModuleName).appendText("\ngroup = \"some.other.group\"")
|
gradleBuildScript(dependencyModuleName).appendText("\ngroup = \"some.other.group\"")
|
||||||
@@ -143,7 +166,8 @@ open class KlibBasedMppIT : BaseGradleIT() {
|
|||||||
|
|
||||||
configureDependency()
|
configureDependency()
|
||||||
|
|
||||||
projectDir.resolve("src/commonMain/kotlin/LibUsage.kt").appendText("\n" + """
|
projectDir.resolve("src/commonMain/kotlin/LibUsage.kt").appendText(
|
||||||
|
"\n" + """
|
||||||
package com.h0tk3y.hmpp.klib.demo.test
|
package com.h0tk3y.hmpp.klib.demo.test
|
||||||
|
|
||||||
import com.projectdep.LibCommonMainExpect as ProjectDepExpect
|
import com.projectdep.LibCommonMainExpect as ProjectDepExpect
|
||||||
@@ -151,9 +175,11 @@ open class KlibBasedMppIT : BaseGradleIT() {
|
|||||||
private fun useProjectDep() {
|
private fun useProjectDep() {
|
||||||
ProjectDepExpect()
|
ProjectDepExpect()
|
||||||
}
|
}
|
||||||
""".trimIndent())
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
projectDir.resolve("src/linuxMain/kotlin/LibLinuxMainUsage.kt").appendText("\n" + """
|
projectDir.resolve("src/linuxMain/kotlin/LibLinuxMainUsage.kt").appendText(
|
||||||
|
"\n" + """
|
||||||
package com.h0tk3y.hmpp.klib.demo.test
|
package com.h0tk3y.hmpp.klib.demo.test
|
||||||
|
|
||||||
import com.projectdep.libLinuxMainFun as libFun
|
import com.projectdep.libLinuxMainFun as libFun
|
||||||
@@ -161,13 +187,13 @@ open class KlibBasedMppIT : BaseGradleIT() {
|
|||||||
private fun useProjectDep() {
|
private fun useProjectDep() {
|
||||||
libFun()
|
libFun()
|
||||||
}
|
}
|
||||||
""".trimIndent())
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
val tasksToExecute = listOf(
|
val tasksToExecute = listOf(
|
||||||
":compileJvmAndJsMainKotlinMetadata",
|
":compileJvmAndJsMainKotlinMetadata",
|
||||||
":compileLinuxMainKotlinMetadata",
|
":compileLinuxMainKotlinMetadata",
|
||||||
":compile${hostSpecificSourceSet.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}KotlinMetadata"
|
) + (if (HostManager.hostIsMac) listOf(":compileIosMainKotlinMetadata") else emptyList())
|
||||||
)
|
|
||||||
|
|
||||||
build("assemble") {
|
build("assemble") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
@@ -194,30 +220,17 @@ open class KlibBasedMppIT : BaseGradleIT() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val hostSpecificSourceSet = when {
|
|
||||||
HostManager.hostIsMac -> "iosMain"
|
|
||||||
HostManager.hostIsLinux -> "embeddedMain"
|
|
||||||
HostManager.hostIsMingw -> "windowsMain"
|
|
||||||
else -> error("unexpected host")
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun checkPublishedHostSpecificMetadata(compiledProject: CompiledProject) = with(compiledProject) {
|
private fun checkPublishedHostSpecificMetadata(compiledProject: CompiledProject) = with(compiledProject) {
|
||||||
val groupDir = project.projectDir.resolve("repo/com/example")
|
val groupDir = project.projectDir.resolve("repo/com/example")
|
||||||
|
|
||||||
assertTasksExecuted(
|
assertTasksExecuted(
|
||||||
":$dependencyModuleName:compile${
|
":$dependencyModuleName:compileIosMainKotlinMetadata")
|
||||||
hostSpecificSourceSet.replaceFirstChar {
|
|
||||||
if (it.isLowerCase()) it.titlecase(
|
|
||||||
Locale.getDefault()
|
|
||||||
) else it.toString()
|
|
||||||
}
|
|
||||||
}KotlinMetadata")
|
|
||||||
|
|
||||||
// Check that the metadata JAR doesn't contain the host-specific source set entries, but contains the shared-Native source set
|
// Check that the metadata JAR doesn't contain the host-specific source set entries, but contains the shared-Native source set
|
||||||
// that can be built on every host:
|
// that can be built on every host:
|
||||||
|
|
||||||
ZipFile(groupDir.resolve("$dependencyModuleName/1.0/$dependencyModuleName-1.0-all.jar")).use { metadataJar ->
|
ZipFile(groupDir.resolve("$dependencyModuleName/1.0/$dependencyModuleName-1.0-all.jar")).use { metadataJar ->
|
||||||
assertTrue { metadataJar.entries().asSequence().none { it.name.startsWith(hostSpecificSourceSet) } }
|
assertTrue { metadataJar.entries().asSequence().none { it.name.startsWith("iosMain") } }
|
||||||
assertTrue { metadataJar.entries().asSequence().any { it.name.startsWith("linuxMain") } }
|
assertTrue { metadataJar.entries().asSequence().any { it.name.startsWith("linuxMain") } }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,15 +239,13 @@ open class KlibBasedMppIT : BaseGradleIT() {
|
|||||||
|
|
||||||
val hostSpecificTargets = when {
|
val hostSpecificTargets = when {
|
||||||
HostManager.hostIsMac -> listOf("iosArm64", "iosX64")
|
HostManager.hostIsMac -> listOf("iosArm64", "iosX64")
|
||||||
HostManager.hostIsLinux -> listOf("linuxMips32", "linuxMipsel32")
|
else -> error("Host doesn't support host-specific metadata")
|
||||||
HostManager.hostIsMingw -> listOf("mingwX64", "mingwX86")
|
|
||||||
else -> error("unexpected host")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hostSpecificTargets.forEach { targetName ->
|
hostSpecificTargets.forEach { targetName ->
|
||||||
val moduleName = "$dependencyModuleName-${targetName.lowercase(Locale.getDefault())}"
|
val moduleName = "$dependencyModuleName-${targetName.lowercase(Locale.getDefault())}"
|
||||||
ZipFile(groupDir.resolve("$moduleName/1.0/$moduleName-1.0-metadata.jar")).use { metadataJar ->
|
ZipFile(groupDir.resolve("$moduleName/1.0/$moduleName-1.0-metadata.jar")).use { metadataJar ->
|
||||||
assertTrue { metadataJar.entries().asSequence().any { it.name.startsWith(hostSpecificSourceSet) } }
|
assertTrue { metadataJar.entries().asSequence().any { it.name.startsWith("iosMain") } }
|
||||||
assertTrue { metadataJar.entries().asSequence().none { it.name.startsWith("commonMain") } }
|
assertTrue { metadataJar.entries().asSequence().none { it.name.startsWith("commonMain") } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -255,7 +266,8 @@ open class KlibBasedMppIT : BaseGradleIT() {
|
|||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
}
|
}
|
||||||
|
|
||||||
gradleBuildScript().appendText("\n" + """
|
gradleBuildScript().appendText(
|
||||||
|
"\n" + """
|
||||||
repositories {
|
repositories {
|
||||||
maven("${'$'}rootDir/repo")
|
maven("${'$'}rootDir/repo")
|
||||||
}
|
}
|
||||||
@@ -278,7 +290,7 @@ open class KlibBasedMppIT : BaseGradleIT() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun testKotlinNativeImplementationDependencies(
|
private fun testKotlinNativeImplementationDependencies(
|
||||||
setupDependencies: Project.() -> Unit
|
setupDependencies: Project.() -> Unit,
|
||||||
) = with(Project("common-klib-lib-and-app")) {
|
) = with(Project("common-klib-lib-and-app")) {
|
||||||
embedProject(Project("common-klib-lib-and-app"), renameTo = transitiveDepModuleName)
|
embedProject(Project("common-klib-lib-and-app"), renameTo = transitiveDepModuleName)
|
||||||
embedProject(Project("common-klib-lib-and-app"), renameTo = dependencyModuleName).apply {
|
embedProject(Project("common-klib-lib-and-app"), renameTo = dependencyModuleName).apply {
|
||||||
@@ -327,7 +339,7 @@ open class KlibBasedMppIT : BaseGradleIT() {
|
|||||||
private fun BaseGradleIT.Project.checkTaskCompileClasspath(
|
private fun BaseGradleIT.Project.checkTaskCompileClasspath(
|
||||||
taskPath: String,
|
taskPath: String,
|
||||||
checkModulesInClasspath: List<Regex> = emptyList(),
|
checkModulesInClasspath: List<Regex> = emptyList(),
|
||||||
checkModulesNotInClasspath: List<Regex> = emptyList()
|
checkModulesNotInClasspath: List<Regex> = emptyList(),
|
||||||
) {
|
) {
|
||||||
val subproject = taskPath.substringBeforeLast(":").takeIf { it.isNotEmpty() && it != taskPath }
|
val subproject = taskPath.substringBeforeLast(":").takeIf { it.isNotEmpty() && it != taskPath }
|
||||||
val taskName = taskPath.removePrefix(subproject.orEmpty())
|
val taskName = taskPath.removePrefix(subproject.orEmpty())
|
||||||
@@ -340,7 +352,7 @@ open class KlibBasedMppIT : BaseGradleIT() {
|
|||||||
subproject: String?,
|
subproject: String?,
|
||||||
itemsExpression: String,
|
itemsExpression: String,
|
||||||
checkAnyItemsContains: List<Regex>,
|
checkAnyItemsContains: List<Regex>,
|
||||||
checkNoItemContains: List<Regex>
|
checkNoItemContains: List<Regex>,
|
||||||
) = with(testCase) {
|
) = with(testCase) {
|
||||||
setupWorkingDir()
|
setupWorkingDir()
|
||||||
|
|
||||||
|
|||||||
+15
-42
@@ -18,34 +18,31 @@ kotlin {
|
|||||||
linuxX64()
|
linuxX64()
|
||||||
linuxArm64()
|
linuxArm64()
|
||||||
|
|
||||||
// Linux-specific targets – embedded:
|
|
||||||
@Suppress("DEPRECATION_ERROR")
|
|
||||||
linuxMips32()
|
|
||||||
@Suppress("DEPRECATION_ERROR")
|
|
||||||
linuxMipsel32()
|
|
||||||
|
|
||||||
// macOS-specific targets - created by the ios() shortcut:
|
// macOS-specific targets - created by the ios() shortcut:
|
||||||
ios()
|
ios()
|
||||||
|
|
||||||
// Windows-specific targets:
|
|
||||||
mingwX64()
|
mingwX64()
|
||||||
@Suppress("DEPRECATION_ERROR")
|
|
||||||
mingwX86()
|
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
val commonMain by getting {
|
val commonMain by getting
|
||||||
dependencies {
|
|
||||||
implementation(kotlin("stdlib-common"))
|
val windowsAndLinuxMain by creating {
|
||||||
}
|
dependsOn(commonMain)
|
||||||
}
|
}
|
||||||
|
|
||||||
val linuxMain by creating {
|
val linuxMain by creating {
|
||||||
dependsOn(commonMain)
|
dependsOn(commonMain)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val mingwX64Main by getting {
|
||||||
configure(listOf(linuxX64(), linuxArm64())) {
|
dependsOn(windowsAndLinuxMain)
|
||||||
compilations["main"].defaultSourceSet.dependsOn(linuxMain)
|
}
|
||||||
|
val linuxX64Main by getting {
|
||||||
|
dependsOn(linuxMain)
|
||||||
|
dependsOn(windowsAndLinuxMain)
|
||||||
|
}
|
||||||
|
val linuxArm64Main by getting {
|
||||||
|
dependsOn(linuxMain)
|
||||||
}
|
}
|
||||||
|
|
||||||
val jvmAndJsMain by creating {
|
val jvmAndJsMain by creating {
|
||||||
@@ -53,35 +50,11 @@ kotlin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val jvmMain by getting {
|
val jvmMain by getting {
|
||||||
dependsOn(jvmAndJsMain)
|
dependsOn(jvmAndJsMain)
|
||||||
dependencies {
|
|
||||||
implementation(kotlin("stdlib-jdk8"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val jsMain by getting {
|
val jsMain by getting {
|
||||||
dependsOn(jvmAndJsMain)
|
dependsOn(jvmAndJsMain)
|
||||||
dependencies {
|
|
||||||
implementation(kotlin("stdlib-js"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val embeddedMain by creating {
|
|
||||||
dependsOn(commonMain)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress("DEPRECATION_ERROR")
|
|
||||||
configure(listOf(linuxMips32(), linuxMipsel32())) {
|
|
||||||
compilations["main"].defaultSourceSet.dependsOn(embeddedMain)
|
|
||||||
}
|
|
||||||
|
|
||||||
val windowsMain by creating {
|
|
||||||
dependsOn(commonMain)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress("DEPRECATION_ERROR")
|
|
||||||
configure(listOf(mingwX64(), mingwX86())) {
|
|
||||||
compilations["main"].defaultSourceSet.dependsOn(windowsMain)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
all {
|
all {
|
||||||
|
|||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package com.h0tk3y.hmpp.klib.demo
|
||||||
|
|
||||||
|
interface Bar
|
||||||
Reference in New Issue
Block a user