CommonizerIT: implement test KT-46248 single supported native target dependency propagation to cover KT-46248

^KT-46248
This commit is contained in:
sebastian.sellmair
2021-04-22 15:10:51 +02:00
committed by Space
parent 683872ecbf
commit 965e328766
9 changed files with 154 additions and 0 deletions
@@ -301,6 +301,36 @@ class CommonizerIT : BaseGradleIT() {
}
}
@Test
fun `test KT-46248 single supported native target dependency propagation`() {
fun CompiledProject.containsPosixDependency(): Boolean = output.lineSequence().any { line ->
line.matches(Regex(""".*Dependency:.*[pP]osix"""))
}
with(Project("commonize-kt-46248-singleNativeTargetPropagation")) {
build(":p1:listNativeMainDependencies") {
assertSuccessful()
assertTrue(containsPosixDependency(), "Expected dependency on posix in nativeMain")
}
build(":p1:listNativeMainParentDependencies") {
assertSuccessful()
assertTrue(containsPosixDependency(), "Expected dependency on posix in nativeMainParent")
}
build(":p1:listCommonMainDependencies") {
assertSuccessful()
assertFalse(containsPosixDependency(), "Expected **no** dependency on posix in commonMain (because of jvm target)")
}
build("assemble") {
assertSuccessful()
assertTasksExecuted(":p1:compileCommonMainKotlinMetadata")
assertTasksExecuted(":p1:compileKotlinNativePlatform")
}
}
}
private fun preparedProject(name: String): Project {
return Project(name).apply {
setupWorkingDir()
@@ -0,0 +1,10 @@
plugins {
kotlin("multiplatform") apply false
}
allprojects {
repositories {
mavenLocal()
mavenCentral()
}
}
@@ -0,0 +1,6 @@
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.enableDependencyPropagation=false
kotlin.mpp.enableCInteropCommonization=true
kotlin.mpp.enableHierarchicalCommonization=true
kotlin.mpp.enableNativeDistributionCommonizationCache=false
kotlin.mpp.enableIntransitiveMetadataConfiguration=true
@@ -0,0 +1,70 @@
import org.jetbrains.kotlin.com.intellij.openapi.util.SystemInfo.*
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
operator fun KotlinSourceSet.invoke(builder: SourceSetHierarchyBuilder.() -> Unit): KotlinSourceSet {
SourceSetHierarchyBuilder(this).builder()
return this
}
class SourceSetHierarchyBuilder(private val node: KotlinSourceSet) {
operator fun KotlinSourceSet.unaryMinus() = this.dependsOn(node)
}
plugins {
kotlin("multiplatform")
}
fun registerListDependenciesTask(sourceSet: KotlinSourceSet) {
tasks.register("list${sourceSet.name.capitalize()}Dependencies") {
dependsOn("commonize")
doLast {
val dependencies = project.configurations.findByName(
"${sourceSet.name}IntransitiveDependenciesMetadata"
)?.files.orEmpty()
logger.quiet("${sourceSet.name} Dependencies | Count: ${dependencies.size}")
dependencies.forEach { dependencyFile ->
logger.quiet("Dependency: ${dependencyFile.path}")
}
}
}
}
kotlin {
when {
isMac -> macosX64("nativePlatform")
isLinux -> linuxX64("nativePlatform")
isWindows -> mingwX64("nativePlatform")
else -> throw IllegalStateException("Unsupported host")
}
when {
isMac -> mingwX64("unsupportedNativePlatform")
else -> macosX64("unsupportedNativePlatform")
}
jvm()
val commonMain by sourceSets.getting
val jvmMain by sourceSets.getting
val nativeMain by sourceSets.creating
val nativeMainParent by sourceSets.creating
val nativePlatformMain by sourceSets.getting
val unsupportedNativePlatformMain by sourceSets.getting
commonMain {
-jvmMain
-nativeMainParent {
-nativeMain {
-nativePlatformMain
-unsupportedNativePlatformMain
}
}
}
registerListDependenciesTask(commonMain)
registerListDependenciesTask(nativeMain)
registerListDependenciesTask(nativeMainParent)
}
@@ -0,0 +1,7 @@
@file:Suppress("unused")
import platform.posix.usleep
fun nativeMain() {
usleep(100)
}
@@ -0,0 +1,7 @@
@file:Suppress("unused")
import platform.posix.usleep
fun commonMain() {
usleep(100)
}
@@ -0,0 +1,12 @@
pluginManagement {
repositories {
mavenLocal()
gradlePluginPortal()
}
val kotlin_version: String by settings
plugins {
kotlin("multiplatform").version(kotlin_version)
}
}
include(":p1")