Fix falsely skipped shared-native source sets in HMPP (KT-38746)

Issue #KT-38746 Fixed
This commit is contained in:
Sergey Igushkin
2020-05-06 20:43:09 +03:00
committed by Sergey Igushkin
parent a0400f59c2
commit 292563451c
7 changed files with 96 additions and 1 deletions
@@ -224,4 +224,28 @@ class KlibBasedMppIT : BaseGradleIT() {
assertSuccessful()
}
}
@Test
fun testAvoidSkippingSharedNativeSourceSetKt38746() = with(Project("hierarchical-all-native")) {
val targetNames = listOf(
// Try different alphabetical ordering of the targets to ensure that the behavior doesn't depend on it, as with 'first target'
listOf("a1", "a2", "a3"),
listOf("a3", "a1", "a2"),
listOf("a2", "a3", "a1"),
)
val targetParamNames = listOf("mingwTargetName", "linuxTargetName", "macosTargetName", "currentHostTargetName")
for (names in targetNames) {
val currentHostTargetName = when {
HostManager.hostIsMingw -> names[0]
HostManager.hostIsLinux -> names[1]
HostManager.hostIsMac -> names[2]
else -> error("unexpected host")
}
val params = targetParamNames.zip(names + currentHostTargetName) { k, v -> "-P$k=$v" }
build(":clean", ":compileCurrentHostAndLinuxKotlinMetadata", *params.toTypedArray()) {
assertSuccessful()
assertTasksExecuted(":compileCurrentHostAndLinuxKotlinMetadata", ":compileAllNativeKotlinMetadata")
}
}
}
}
@@ -0,0 +1,37 @@
plugins {
kotlin("multiplatform")
}
repositories {
mavenLocal()
jcenter()
}
kotlin {
val mingwTargetName: String by project
val linuxTargetName: String by project
val macosTargetName: String by project
val currentHostTargetName: String by project
val mingw = mingwX64(mingwTargetName) { }
val linux = linuxX64(linuxTargetName) { }
val macos = macosX64(macosTargetName) { }
val linuxArm = linuxArm64()
sourceSets {
val allNative by creating {
dependsOn(getByName("commonMain"))
listOf(mingw, linux, macos).forEach {
it.compilations["main"].defaultSourceSet.dependsOn(this@creating)
}
}
val currentHostAndLinux by creating {
dependsOn(allNative)
}
configure(listOf(linuxArm, targets.getByName(currentHostTargetName))) {
compilations["main"].defaultSourceSet.dependsOn(currentHostAndLinux)
}
}
}
@@ -0,0 +1 @@
kotlin.mpp.enableGranularSourceSetsMetadata=true
@@ -0,0 +1,12 @@
pluginManagement {
repositories {
mavenLocal()
gradlePluginPortal()
}
val kotlin_version: String by settings
plugins {
kotlin("multiplatform").version(kotlin_version)
}
}
rootProject.name = "my-lib-foo"
@@ -0,0 +1,10 @@
/*
* 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.example.foo
expect fun foo(): String
fun fooCommon() = "foo"
@@ -0,0 +1,10 @@
/*
* 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.example.foo
actual fun foo(): String = "foo"
fun useFooCommon() = fooCommon()
@@ -102,7 +102,8 @@ class KotlinSharedNativeCompilation(override val target: KotlinMetadataTarget, v
target,
// TODO: this will end up as '-target' argument passed to K2Native, which is wrong.
// Rewrite this when we'll compile native-shared source-sets against commonized platform libs
konanTargets.first(),
// We find any konan target that is enabled on the current host in order to pass the checks that avoid compiling the code otherwise.
konanTargets.find { it.enabledOnCurrentHost } ?: konanTargets.first(),
name
),
KotlinMetadataCompilation<KotlinCommonOptions> {