[Gradle][Native] Implement KotlinNativeCompileRefinesPathsTest
^KT-55071 Verification Pending
This commit is contained in:
committed by
Space Team
parent
4c62b3b46b
commit
5818187e57
+2
-2
@@ -11,7 +11,7 @@ import org.gradle.api.Project
|
||||
import org.gradle.api.file.ConfigurableFileCollection
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.file.SourceDirectorySet
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.internal
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.isMain
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.GradleKpmAbstractFragmentMetadataCompilationData
|
||||
@@ -76,7 +76,7 @@ internal sealed class KotlinCompilationInfo {
|
||||
|
||||
override val refinesPaths: FileCollection
|
||||
get() = project.filesProvider files@{
|
||||
val metadataTarget = project.multiplatformExtensionOrNull?.metadata() ?: return@files emptyList<Any>()
|
||||
val metadataTarget = origin.target as? KotlinMetadataTarget ?: return@files emptyList<Any>()
|
||||
origin.kotlinSourceSets.dependsOnClosure
|
||||
.mapNotNull { sourceSet -> metadataTarget.compilations.findByName(sourceSet.name)?.output?.classesDirs }
|
||||
}
|
||||
|
||||
+2
-2
@@ -179,10 +179,10 @@ abstract class AbstractKotlinNativeCompile<
|
||||
)
|
||||
|
||||
@get:Classpath
|
||||
protected val friendModule: FileCollection = project.files({ compilation.friendPaths })
|
||||
internal val friendModule: FileCollection = project.files({ compilation.friendPaths })
|
||||
|
||||
@get:Classpath
|
||||
protected val refinesModule: FileCollection = project.files({ compilation.refinesPaths })
|
||||
internal val refinesModule: FileCollection = project.files({ compilation.refinesPaths })
|
||||
|
||||
@get:Input
|
||||
val target: String by project.provider { konanTarget.name }
|
||||
|
||||
-4
@@ -7,14 +7,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCommonCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinSharedNativeCompilation
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompileCommon
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
|
||||
import java.io.File
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@@ -129,6 +127,4 @@ class KotlinCompileTaskSourcesTest {
|
||||
linuxArm64CompileTask.sources.files.relativeTo(project)
|
||||
)
|
||||
}
|
||||
|
||||
private fun Set<File>.relativeTo(project: Project): Set<File> = map { it.relativeTo(project.projectDir) }.toSet()
|
||||
}
|
||||
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.
|
||||
*/
|
||||
|
||||
@file:Suppress("FunctionName")
|
||||
|
||||
package org.jetbrains.kotlin.gradle
|
||||
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinSharedNativeCompilation
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class KotlinNativeCompileRefinesPathsTest {
|
||||
@Test
|
||||
fun `test - shared linux - refinesPaths`() {
|
||||
val project = buildProjectWithMPP()
|
||||
val kotlin = project.multiplatformExtension
|
||||
kotlin.targetHierarchy.default()
|
||||
|
||||
kotlin.linuxX64()
|
||||
kotlin.linuxArm64()
|
||||
|
||||
project.evaluate()
|
||||
|
||||
/* Check linuxMain metadata compilation */
|
||||
run {
|
||||
val compilation = kotlin.metadata().compilations.getByName("linuxMain") as KotlinSharedNativeCompilation
|
||||
val compileTask = compilation.compileTaskProvider.get()
|
||||
|
||||
assertEquals(
|
||||
project.files(
|
||||
"build/classes/kotlin/metadata/nativeMain/klib/test_nativeMain.klib",
|
||||
"build/classes/kotlin/metadata/commonMain/klib/test_commonMain.klib"
|
||||
).toSet().relativeTo(project),
|
||||
compileTask.refinesModule.files.relativeTo(project)
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
emptySet(), compileTask.friendModule.files.relativeTo(project),
|
||||
"Expected no friendModules on linuxMain metadata compilation"
|
||||
)
|
||||
}
|
||||
|
||||
/* Check linuxX64Main platform compilation */
|
||||
run {
|
||||
val compilation = kotlin.linuxX64().compilations.main
|
||||
val compileTask = compilation.compileTaskProvider.get() as KotlinNativeCompile
|
||||
|
||||
/* Platform compilation will compile all sources together, no refinesModules has to be set */
|
||||
assertEquals(
|
||||
emptySet(), compileTask.refinesModule.files.relativeTo(project)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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 org.jetbrains.kotlin.gradle
|
||||
|
||||
import org.gradle.api.Project
|
||||
import java.io.File
|
||||
|
||||
fun Set<File>.relativeTo(project: Project): Set<File> = map { it.relativeTo(project.projectDir) }.toSet()
|
||||
Reference in New Issue
Block a user