[Gradle] Add test and assertions to cover ^KT-47523
This commit is contained in:
committed by
Space
parent
d730db094a
commit
fee670e1a5
+41
@@ -323,20 +323,27 @@ class CommonizerIT : BaseGradleIT() {
|
||||
line.matches(Regex(""".*Dependency:.*[pP]osix"""))
|
||||
}
|
||||
|
||||
fun CompiledProject.containsDummyCInteropDependency(): Boolean = output.lineSequence().any { line ->
|
||||
line.matches(Regex(""".*Dependency:.*cinterop-dummy.*"""))
|
||||
}
|
||||
|
||||
with(Project("commonize-kt-46248-singleNativeTargetPropagation")) {
|
||||
build(":p1:listNativeMainDependencies") {
|
||||
assertSuccessful()
|
||||
assertTrue(containsPosixDependency(), "Expected dependency on posix in nativeMain")
|
||||
assertTrue(containsDummyCInteropDependency(), "Expected dependency on dummy cinterop in nativeMain")
|
||||
}
|
||||
|
||||
build(":p1:listNativeMainParentDependencies") {
|
||||
assertSuccessful()
|
||||
assertTrue(containsPosixDependency(), "Expected dependency on posix in nativeMainParent")
|
||||
assertTrue(containsDummyCInteropDependency(), "Expected dependency on dummy cinterop in nativeMain")
|
||||
}
|
||||
|
||||
build(":p1:listCommonMainDependencies") {
|
||||
assertSuccessful()
|
||||
assertFalse(containsPosixDependency(), "Expected **no** dependency on posix in commonMain (because of jvm target)")
|
||||
assertFalse(containsDummyCInteropDependency(), "Expected **no** dependency on dummy cinterop in nativeMain")
|
||||
}
|
||||
|
||||
build("assemble") {
|
||||
@@ -347,6 +354,40 @@ class CommonizerIT : BaseGradleIT() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test KT-46248 single supported native target dependency propagation - cinterop`() {
|
||||
fun CompiledProject.containsCinteropDependency(): Boolean {
|
||||
val nativeMainContainsCInteropDependencyRegex = Regex(""".*Dependency:.*cinterop-dummy.*""")
|
||||
return output.lineSequence().any { line ->
|
||||
line.matches(nativeMainContainsCInteropDependencyRegex)
|
||||
}
|
||||
}
|
||||
|
||||
with(Project("commonize-kt-47523-singleNativeTargetPropagation-cinterop")) {
|
||||
build("listNativePlatformMainDependencies") {
|
||||
assertSuccessful()
|
||||
assertFalse(
|
||||
containsCinteropDependency(),
|
||||
"Expected sourceSet 'nativeMain' to list cinterop dependency (not necessary, since included in compilation)"
|
||||
)
|
||||
}
|
||||
|
||||
build("listNativeMainDependencies") {
|
||||
assertSuccessful()
|
||||
assertTrue(containsCinteropDependency(), "Expected sourceSet 'nativeMain' to list cinterop dependency")
|
||||
}
|
||||
|
||||
build("listCommonMainDependencies") {
|
||||
assertSuccessful()
|
||||
assertTrue(containsCinteropDependency(), "Expected sourceSet 'commonMain' to list cinterop dependency")
|
||||
}
|
||||
|
||||
build("assemble") {
|
||||
assertSuccessful()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test KT-46856 filename too long - all native targets configured`() {
|
||||
with(Project("commonize-kt-46856-all-targets")) {
|
||||
|
||||
+20
-8
@@ -16,14 +16,16 @@ plugins {
|
||||
|
||||
fun registerListDependenciesTask(sourceSet: KotlinSourceSet) {
|
||||
tasks.register("list${sourceSet.name.capitalize()}Dependencies") {
|
||||
val dependencyConfiguration = project.configurations.getByName(
|
||||
"${sourceSet.name}IntransitiveDependenciesMetadata"
|
||||
)
|
||||
|
||||
dependsOn("commonize")
|
||||
dependsOn(dependencyConfiguration)
|
||||
|
||||
doLast {
|
||||
val dependencies = project.configurations.findByName(
|
||||
"${sourceSet.name}IntransitiveDependenciesMetadata"
|
||||
)?.files.orEmpty()
|
||||
|
||||
val dependencies = dependencyConfiguration.files.orEmpty()
|
||||
logger.quiet("${sourceSet.name} Dependencies | Count: ${dependencies.size}")
|
||||
|
||||
dependencies.forEach { dependencyFile ->
|
||||
logger.quiet("Dependency: ${dependencyFile.path}")
|
||||
}
|
||||
@@ -32,21 +34,21 @@ fun registerListDependenciesTask(sourceSet: KotlinSourceSet) {
|
||||
}
|
||||
|
||||
kotlin {
|
||||
|
||||
when {
|
||||
val nativePlatform = when {
|
||||
isMac -> macosX64("nativePlatform")
|
||||
isLinux -> linuxX64("nativePlatform")
|
||||
isWindows -> mingwX64("nativePlatform")
|
||||
else -> throw IllegalStateException("Unsupported host")
|
||||
}
|
||||
|
||||
when {
|
||||
val unsupportedNativePlatform = when {
|
||||
isMac -> mingwX64("unsupportedNativePlatform")
|
||||
else -> macosX64("unsupportedNativePlatform")
|
||||
}
|
||||
|
||||
jvm()
|
||||
|
||||
|
||||
val commonMain by sourceSets.getting
|
||||
val jvmMain by sourceSets.getting
|
||||
val nativeMain by sourceSets.creating
|
||||
@@ -64,6 +66,16 @@ kotlin {
|
||||
}
|
||||
}
|
||||
|
||||
nativePlatform.compilations.getByName("main").cinterops.create("dummy") {
|
||||
headers("libs/include/dummy.h")
|
||||
compilerOpts.add("-Ilibs/include")
|
||||
}
|
||||
|
||||
unsupportedNativePlatform.compilations.getByName("main").cinterops.create("dummy") {
|
||||
headers("libs/include/dummy.h")
|
||||
compilerOpts.add("-Ilibs/include")
|
||||
}
|
||||
|
||||
registerListDependenciesTask(commonMain)
|
||||
registerListDependenciesTask(nativeMain)
|
||||
registerListDependenciesTask(nativeMainParent)
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
void dummyFunction();
|
||||
+4
-1
@@ -1,7 +1,10 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
import platform.posix.usleep
|
||||
import dummy.dummyFunction
|
||||
|
||||
fun nativeMain() {
|
||||
usleep(100)
|
||||
}
|
||||
}
|
||||
|
||||
fun nativeMainUsingCInterop() = dummyFunction()
|
||||
+5
-1
@@ -1,7 +1,11 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
import platform.posix.usleep
|
||||
import dummy.dummyFunction
|
||||
|
||||
|
||||
fun commonMain() {
|
||||
usleep(100)
|
||||
}
|
||||
}
|
||||
|
||||
fun nativeMainParentUsingCInterop() = dummyFunction()
|
||||
|
||||
+4
-1
@@ -1,7 +1,10 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
import platform.posix.usleep
|
||||
import dummy.dummyFunction
|
||||
|
||||
fun main() {
|
||||
usleep(100)
|
||||
}
|
||||
}
|
||||
|
||||
fun nativePlatformMainUsingCInterop() = dummyFunction()
|
||||
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
|
||||
import org.jetbrains.kotlin.com.intellij.openapi.util.SystemInfo.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet
|
||||
|
||||
plugins {
|
||||
kotlin("multiplatform") apply true
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
kotlin {
|
||||
val nativePlatform = when {
|
||||
isMac -> macosX64("nativePlatform")
|
||||
isLinux -> linuxX64("nativePlatform")
|
||||
isWindows -> mingwX64("nativePlatform")
|
||||
else -> throw IllegalStateException("Unsupported host")
|
||||
}
|
||||
|
||||
val commonMain by sourceSets.getting
|
||||
val nativePlatformMain by sourceSets.getting
|
||||
val nativeMain by sourceSets.creating
|
||||
|
||||
nativeMain.dependsOn(commonMain)
|
||||
nativePlatformMain.dependsOn(nativeMain)
|
||||
|
||||
nativePlatform.compilations.getByName("main").cinterops.create("dummy") {
|
||||
headers("libs/include/dummy.h")
|
||||
compilerOpts.add("-Ilibs/include")
|
||||
}
|
||||
}
|
||||
|
||||
fun createListDependenciesTask(sourceSetName: String) {
|
||||
tasks.create("list${sourceSetName.capitalize()}Dependencies") {
|
||||
val sourceSet = kotlin.sourceSets[sourceSetName] as DefaultKotlinSourceSet
|
||||
val metadataConfiguration = project.configurations[sourceSet.intransitiveMetadataConfigurationName]
|
||||
dependsOn(metadataConfiguration)
|
||||
dependsOn("cinteropDummyNativePlatform")
|
||||
doFirst {
|
||||
metadataConfiguration.files.forEach { dependencyFile ->
|
||||
logger.quiet("Dependency: $dependencyFile")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
createListDependenciesTask("nativePlatformMain")
|
||||
createListDependenciesTask("nativeMain")
|
||||
createListDependenciesTask("commonMain")
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
kotlin.mpp.enableGranularSourceSetsMetadata=true
|
||||
kotlin.native.enableDependencyPropagation=false
|
||||
kotlin.mpp.enableCInteropCommonization=true
|
||||
kotlin.mpp.enableIntransitiveMetadataConfiguration=true
|
||||
kotlin.mpp.enableCompatibilityMetadataVariant=false
|
||||
+1
@@ -0,0 +1 @@
|
||||
void dummyFunction();
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
val kotlin_version: String by settings
|
||||
plugins {
|
||||
kotlin("multiplatform").version(kotlin_version)
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
import dummy.dummyFunction
|
||||
|
||||
fun commonMain() = dummyFunction()
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
import dummy.dummyFunction
|
||||
|
||||
fun nativeMain() = dummyFunction()
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
import dummy.dummyFunction
|
||||
|
||||
fun nativePlatformMain() = dummyFunction()
|
||||
Reference in New Issue
Block a user