[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"""))
|
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")) {
|
with(Project("commonize-kt-46248-singleNativeTargetPropagation")) {
|
||||||
build(":p1:listNativeMainDependencies") {
|
build(":p1:listNativeMainDependencies") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
assertTrue(containsPosixDependency(), "Expected dependency on posix in nativeMain")
|
assertTrue(containsPosixDependency(), "Expected dependency on posix in nativeMain")
|
||||||
|
assertTrue(containsDummyCInteropDependency(), "Expected dependency on dummy cinterop in nativeMain")
|
||||||
}
|
}
|
||||||
|
|
||||||
build(":p1:listNativeMainParentDependencies") {
|
build(":p1:listNativeMainParentDependencies") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
assertTrue(containsPosixDependency(), "Expected dependency on posix in nativeMainParent")
|
assertTrue(containsPosixDependency(), "Expected dependency on posix in nativeMainParent")
|
||||||
|
assertTrue(containsDummyCInteropDependency(), "Expected dependency on dummy cinterop in nativeMain")
|
||||||
}
|
}
|
||||||
|
|
||||||
build(":p1:listCommonMainDependencies") {
|
build(":p1:listCommonMainDependencies") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
assertFalse(containsPosixDependency(), "Expected **no** dependency on posix in commonMain (because of jvm target)")
|
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") {
|
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
|
@Test
|
||||||
fun `test KT-46856 filename too long - all native targets configured`() {
|
fun `test KT-46856 filename too long - all native targets configured`() {
|
||||||
with(Project("commonize-kt-46856-all-targets")) {
|
with(Project("commonize-kt-46856-all-targets")) {
|
||||||
|
|||||||
+20
-8
@@ -16,14 +16,16 @@ plugins {
|
|||||||
|
|
||||||
fun registerListDependenciesTask(sourceSet: KotlinSourceSet) {
|
fun registerListDependenciesTask(sourceSet: KotlinSourceSet) {
|
||||||
tasks.register("list${sourceSet.name.capitalize()}Dependencies") {
|
tasks.register("list${sourceSet.name.capitalize()}Dependencies") {
|
||||||
|
val dependencyConfiguration = project.configurations.getByName(
|
||||||
|
"${sourceSet.name}IntransitiveDependenciesMetadata"
|
||||||
|
)
|
||||||
|
|
||||||
dependsOn("commonize")
|
dependsOn("commonize")
|
||||||
|
dependsOn(dependencyConfiguration)
|
||||||
|
|
||||||
doLast {
|
doLast {
|
||||||
val dependencies = project.configurations.findByName(
|
val dependencies = dependencyConfiguration.files.orEmpty()
|
||||||
"${sourceSet.name}IntransitiveDependenciesMetadata"
|
|
||||||
)?.files.orEmpty()
|
|
||||||
|
|
||||||
logger.quiet("${sourceSet.name} Dependencies | Count: ${dependencies.size}")
|
logger.quiet("${sourceSet.name} Dependencies | Count: ${dependencies.size}")
|
||||||
|
|
||||||
dependencies.forEach { dependencyFile ->
|
dependencies.forEach { dependencyFile ->
|
||||||
logger.quiet("Dependency: ${dependencyFile.path}")
|
logger.quiet("Dependency: ${dependencyFile.path}")
|
||||||
}
|
}
|
||||||
@@ -32,21 +34,21 @@ fun registerListDependenciesTask(sourceSet: KotlinSourceSet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
|
val nativePlatform = when {
|
||||||
when {
|
|
||||||
isMac -> macosX64("nativePlatform")
|
isMac -> macosX64("nativePlatform")
|
||||||
isLinux -> linuxX64("nativePlatform")
|
isLinux -> linuxX64("nativePlatform")
|
||||||
isWindows -> mingwX64("nativePlatform")
|
isWindows -> mingwX64("nativePlatform")
|
||||||
else -> throw IllegalStateException("Unsupported host")
|
else -> throw IllegalStateException("Unsupported host")
|
||||||
}
|
}
|
||||||
|
|
||||||
when {
|
val unsupportedNativePlatform = when {
|
||||||
isMac -> mingwX64("unsupportedNativePlatform")
|
isMac -> mingwX64("unsupportedNativePlatform")
|
||||||
else -> macosX64("unsupportedNativePlatform")
|
else -> macosX64("unsupportedNativePlatform")
|
||||||
}
|
}
|
||||||
|
|
||||||
jvm()
|
jvm()
|
||||||
|
|
||||||
|
|
||||||
val commonMain by sourceSets.getting
|
val commonMain by sourceSets.getting
|
||||||
val jvmMain by sourceSets.getting
|
val jvmMain by sourceSets.getting
|
||||||
val nativeMain by sourceSets.creating
|
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(commonMain)
|
||||||
registerListDependenciesTask(nativeMain)
|
registerListDependenciesTask(nativeMain)
|
||||||
registerListDependenciesTask(nativeMainParent)
|
registerListDependenciesTask(nativeMainParent)
|
||||||
|
|||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
void dummyFunction();
|
||||||
+3
@@ -1,7 +1,10 @@
|
|||||||
@file:Suppress("unused")
|
@file:Suppress("unused")
|
||||||
|
|
||||||
import platform.posix.usleep
|
import platform.posix.usleep
|
||||||
|
import dummy.dummyFunction
|
||||||
|
|
||||||
fun nativeMain() {
|
fun nativeMain() {
|
||||||
usleep(100)
|
usleep(100)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun nativeMainUsingCInterop() = dummyFunction()
|
||||||
+4
@@ -1,7 +1,11 @@
|
|||||||
@file:Suppress("unused")
|
@file:Suppress("unused")
|
||||||
|
|
||||||
import platform.posix.usleep
|
import platform.posix.usleep
|
||||||
|
import dummy.dummyFunction
|
||||||
|
|
||||||
|
|
||||||
fun commonMain() {
|
fun commonMain() {
|
||||||
usleep(100)
|
usleep(100)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun nativeMainParentUsingCInterop() = dummyFunction()
|
||||||
|
|||||||
+3
@@ -1,7 +1,10 @@
|
|||||||
@file:Suppress("unused")
|
@file:Suppress("unused")
|
||||||
|
|
||||||
import platform.posix.usleep
|
import platform.posix.usleep
|
||||||
|
import dummy.dummyFunction
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
usleep(100)
|
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