Add a test for host-specific metadata publishing and consumption
This commit is contained in:
+50
-1
@@ -9,8 +9,10 @@ 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 org.junit.Assume
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.util.zip.ZipFile
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertFalse
|
import kotlin.test.assertFalse
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class KlibBasedMppIT : BaseGradleIT() {
|
class KlibBasedMppIT : BaseGradleIT() {
|
||||||
override val defaultGradleVersion = GradleVersionRequired.AtLeast("6.0")
|
override val defaultGradleVersion = GradleVersionRequired.AtLeast("6.0")
|
||||||
@@ -32,6 +34,7 @@ class KlibBasedMppIT : BaseGradleIT() {
|
|||||||
fun testBuildWithPublishedDependency() = testBuildWithDependency {
|
fun testBuildWithPublishedDependency() = testBuildWithDependency {
|
||||||
build(":$dependencyModuleName:publish") {
|
build(":$dependencyModuleName:publish") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
|
checkPublishedHostSpecificMetadata(this@build)
|
||||||
}
|
}
|
||||||
|
|
||||||
gradleBuildScript().appendText("\n" + """
|
gradleBuildScript().appendText("\n" + """
|
||||||
@@ -81,7 +84,8 @@ class KlibBasedMppIT : BaseGradleIT() {
|
|||||||
|
|
||||||
val tasksToExecute = listOf(
|
val tasksToExecute = listOf(
|
||||||
":compileJvmAndJsMainKotlinMetadata",
|
":compileJvmAndJsMainKotlinMetadata",
|
||||||
":compileLinuxMainKotlinMetadata"
|
":compileLinuxMainKotlinMetadata",
|
||||||
|
":compile${hostSpecificSourceSet.capitalize()}KotlinMetadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
build("assemble") {
|
build("assemble") {
|
||||||
@@ -109,6 +113,51 @@ 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) {
|
||||||
|
val groupDir = project.projectDir.resolve("repo/com/example")
|
||||||
|
|
||||||
|
assertTasksExecuted(":$dependencyModuleName:compile${hostSpecificSourceSet.capitalize()}KotlinMetadata")
|
||||||
|
|
||||||
|
// 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:
|
||||||
|
|
||||||
|
ZipFile(groupDir.resolve("$dependencyModuleName-metadata/1.0/$dependencyModuleName-metadata-1.0.jar")).use { metadataJar ->
|
||||||
|
assertTrue { metadataJar.entries().asSequence().none { it.name.startsWith(hostSpecificSourceSet) } }
|
||||||
|
assertTrue { metadataJar.entries().asSequence().any { it.name.startsWith("linuxMain") } }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Then check that in the host-specific modules, there's a metadata artifact that contains the host-specific source set but not the
|
||||||
|
// common source sets:
|
||||||
|
|
||||||
|
val hostSpecificTargets = when {
|
||||||
|
HostManager.hostIsMac -> listOf("iosArm64", "iosX64")
|
||||||
|
HostManager.hostIsLinux -> listOf("linuxMips32", "linuxMipsel32")
|
||||||
|
HostManager.hostIsMingw -> listOf("mingwX64", "mingwX86")
|
||||||
|
else -> error("unexpected host")
|
||||||
|
}
|
||||||
|
|
||||||
|
hostSpecificTargets.forEach { targetName ->
|
||||||
|
val moduleName = "$dependencyModuleName-${targetName.toLowerCase()}"
|
||||||
|
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().none { it.name.startsWith("commonMain") } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Also check that the targets that don't include any host-specific sources don't even have the metadata artifact:
|
||||||
|
|
||||||
|
groupDir.resolve("$dependencyModuleName-linuxx64/1.0/$dependencyModuleName-linuxx64-1.0-metadata.jar").let { metadataJar ->
|
||||||
|
assertTrue { !metadataJar.exists() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private val transitiveDepModuleName = "transitive-dep"
|
private val transitiveDepModuleName = "transitive-dep"
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
+31
-6
@@ -18,6 +18,17 @@ kotlin {
|
|||||||
linuxX64()
|
linuxX64()
|
||||||
linuxArm64()
|
linuxArm64()
|
||||||
|
|
||||||
|
// Linux-specific targets – embedded:
|
||||||
|
linuxMips32()
|
||||||
|
linuxMipsel32()
|
||||||
|
|
||||||
|
// macOS-specific targets - created by the ios() shortcut:
|
||||||
|
ios()
|
||||||
|
|
||||||
|
// Windows-specific targets:
|
||||||
|
mingwX64()
|
||||||
|
mingwX86()
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
val commonMain by getting {
|
val commonMain by getting {
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -29,6 +40,11 @@ kotlin {
|
|||||||
dependsOn(commonMain)
|
dependsOn(commonMain)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
configure(listOf(linuxX64(), linuxArm64())) {
|
||||||
|
compilations["main"].defaultSourceSet.dependsOn(linuxMain)
|
||||||
|
}
|
||||||
|
|
||||||
val jvmAndJsMain by creating {
|
val jvmAndJsMain by creating {
|
||||||
dependsOn(commonMain)
|
dependsOn(commonMain)
|
||||||
}
|
}
|
||||||
@@ -47,8 +63,20 @@ kotlin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
configure(listOf(linuxX64(), linuxArm64())) {
|
val embeddedMain by creating {
|
||||||
compilations["main"].defaultSourceSet.dependsOn(linuxMain)
|
dependsOn(commonMain)
|
||||||
|
}
|
||||||
|
|
||||||
|
configure(listOf(linuxMips32(), linuxMipsel32())) {
|
||||||
|
compilations["main"].defaultSourceSet.dependsOn(embeddedMain)
|
||||||
|
}
|
||||||
|
|
||||||
|
val windowsMain by creating {
|
||||||
|
dependsOn(commonMain)
|
||||||
|
}
|
||||||
|
|
||||||
|
configure(listOf(mingwX64(), mingwX86())) {
|
||||||
|
compilations["main"].defaultSourceSet.dependsOn(windowsMain)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -60,10 +88,7 @@ publishing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
val skipCompilationOfTargets = setOf(
|
val skipCompilationOfTargets = kotlin.targets.matching { it.platformType.toString() == "native" }.names
|
||||||
"linuxX64",
|
|
||||||
"linuxArm64"
|
|
||||||
)
|
|
||||||
all {
|
all {
|
||||||
val target = name.removePrefix("compileKotlin").decapitalize()
|
val target = name.removePrefix("compileKotlin").decapitalize()
|
||||||
if (target in skipCompilationOfTargets) {
|
if (target in skipCompilationOfTargets) {
|
||||||
|
|||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.h0tk3y.hmpp.klib.demo
|
||||||
|
|
||||||
|
import kotlinx.cinterop.CArrayPointer
|
||||||
|
|
||||||
|
actual class LibCommonMainExpect : LibCommonMainIface {
|
||||||
|
actual fun libCommonMainExpectFun(): Unit {
|
||||||
|
println("actualized in embeddedMain")
|
||||||
|
libCommonMainTopLevelFun()
|
||||||
|
println(CArrayPointer::class)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun additionalFunInEmbeddedActual() {
|
||||||
|
println("additional fun in lib embeddedMain")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun libLinuxMainFun(): LibCommonMainIface = LibCommonMainExpect()
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.h0tk3y.hmpp.klib.demo
|
||||||
|
|
||||||
|
import kotlinx.cinterop.CArrayPointer
|
||||||
|
|
||||||
|
actual class LibCommonMainExpect : LibCommonMainIface {
|
||||||
|
actual fun libCommonMainExpectFun(): Unit {
|
||||||
|
println("actualized in iosMain")
|
||||||
|
libCommonMainTopLevelFun()
|
||||||
|
println(CArrayPointer::class)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun additionalFunInIosActual() {
|
||||||
|
println("additional fun in lib iosMain")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun libLinuxMainFun(): LibCommonMainIface = LibCommonMainExpect()
|
||||||
+1
-1
@@ -9,7 +9,7 @@ import kotlinx.cinterop.CArrayPointer
|
|||||||
|
|
||||||
actual class LibCommonMainExpect : LibCommonMainIface {
|
actual class LibCommonMainExpect : LibCommonMainIface {
|
||||||
actual fun libCommonMainExpectFun(): Unit {
|
actual fun libCommonMainExpectFun(): Unit {
|
||||||
println("actualized in iosMain")
|
println("actualized in linuxMain")
|
||||||
libCommonMainTopLevelFun()
|
libCommonMainTopLevelFun()
|
||||||
println(CArrayPointer::class)
|
println(CArrayPointer::class)
|
||||||
libCommonMainInternalFun()
|
libCommonMainInternalFun()
|
||||||
|
|||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.h0tk3y.hmpp.klib.demo
|
||||||
|
|
||||||
|
import kotlinx.cinterop.CArrayPointer
|
||||||
|
|
||||||
|
actual class LibCommonMainExpect : LibCommonMainIface {
|
||||||
|
actual fun libCommonMainExpectFun(): Unit {
|
||||||
|
println("actualized in windowsMain")
|
||||||
|
libCommonMainTopLevelFun()
|
||||||
|
println(CArrayPointer::class)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun additionalFunInWindowsActual() {
|
||||||
|
println("additional fun in lib windowsMain")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun libLinuxMainFun(): LibCommonMainIface = LibCommonMainExpect()
|
||||||
Reference in New Issue
Block a user