Remove kotlin.native.linkFromSources, expose tasks' sources
* Drop the deprecated mode in the Kotlin/Native link tasks using sources rather than the intermediate compiled klib. * Remove the `allSources` and `commonSources` properties from the KotlinNativeCompilation, use the tasks' properties instead.
This commit is contained in:
-24
@@ -1390,30 +1390,6 @@ class NewMultiplatformIT : BaseGradleIT() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that we still can build binaries from sources if the corresponding property is specified.
|
|
||||||
// TODO: Drop in 1.4
|
|
||||||
@Test
|
|
||||||
fun testLinkNativeBinaryFromSources() = with(
|
|
||||||
transformProjectWithPluginsDsl("groovy-dsl", gradleVersion, "new-mpp-native-binaries")
|
|
||||||
) {
|
|
||||||
val linkTask = ":linkDebugExecutable${nativeHostTargetName.capitalize()}"
|
|
||||||
|
|
||||||
val prefix = CompilerOutputKind.PROGRAM.prefix(HostManager.host)
|
|
||||||
val suffix = CompilerOutputKind.PROGRAM.suffix(HostManager.host)
|
|
||||||
val fileName = "${prefix}native-binary$suffix"
|
|
||||||
val outputFile = "build/bin/$nativeHostTargetName/debugExecutable/$fileName"
|
|
||||||
|
|
||||||
build(linkTask, "-Pkotlin.native.linkFromSources") {
|
|
||||||
assertSuccessful()
|
|
||||||
assertTasksExecuted(linkTask)
|
|
||||||
assertFileExists(outputFile)
|
|
||||||
checkNativeCommandLineFor(linkTask) {
|
|
||||||
assertTrue(it.contains("-Xcommon-sources="))
|
|
||||||
assertTrue(it.contains(projectDir.resolve("src/commonMain/kotlin/RootMain.kt").absolutePath))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// We propagate compilation args to link tasks for now (see KT-33717).
|
// We propagate compilation args to link tasks for now (see KT-33717).
|
||||||
// TODO: Reenable the test when the args are separated.
|
// TODO: Reenable the test when the args are separated.
|
||||||
@Ignore
|
@Ignore
|
||||||
|
|||||||
+5
-12
@@ -60,18 +60,11 @@ abstract class AbstractKotlinNativeCompilation(
|
|||||||
override val compileKotlinTaskProvider: TaskProvider<out KotlinNativeCompile>
|
override val compileKotlinTaskProvider: TaskProvider<out KotlinNativeCompile>
|
||||||
get() = super.compileKotlinTaskProvider as TaskProvider<out KotlinNativeCompile>
|
get() = super.compileKotlinTaskProvider as TaskProvider<out KotlinNativeCompile>
|
||||||
|
|
||||||
// (taking into account dependencies between source sets). Used by both compilation
|
override fun addSourcesToCompileTask(sourceSet: KotlinSourceSet, addAsCommonSources: Lazy<Boolean>) =
|
||||||
// and linking tasks. Unlike kotlinSourceSets, includes dependency source sets.
|
compileKotlinTaskProvider.configure { task ->
|
||||||
// TODO: Move into the compilation task when the linking task does klib linking instead of compilation.
|
task.source(sourceSet.kotlin)
|
||||||
internal val allSources: MutableSet<SourceDirectorySet> = mutableSetOf()
|
task.commonSources.from(target.project.files(Callable { if (addAsCommonSources.value) sourceSet.kotlin else emptyList<Any>() }))
|
||||||
|
}
|
||||||
// TODO: Move into the compilation task when the linking task does klib linking instead of compilation.
|
|
||||||
internal val commonSources: ConfigurableFileCollection = target.project.files()
|
|
||||||
|
|
||||||
override fun addSourcesToCompileTask(sourceSet: KotlinSourceSet, addAsCommonSources: Lazy<Boolean>) {
|
|
||||||
allSources.add(sourceSet.kotlin)
|
|
||||||
commonSources.from(target.project.files(Callable { if (addAsCommonSources.value) sourceSet.kotlin else emptyList<Any>() }))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Endorsed library controller.
|
// Endorsed library controller.
|
||||||
var enableEndorsedLibs: Boolean = false
|
var enableEndorsedLibs: Boolean = false
|
||||||
|
|||||||
+21
-87
@@ -10,8 +10,10 @@ import groovy.lang.Closure
|
|||||||
import org.gradle.api.DefaultTask
|
import org.gradle.api.DefaultTask
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.artifacts.*
|
import org.gradle.api.artifacts.*
|
||||||
|
import org.gradle.api.file.ConfigurableFileCollection
|
||||||
import org.gradle.api.file.FileCollection
|
import org.gradle.api.file.FileCollection
|
||||||
import org.gradle.api.file.FileTree
|
import org.gradle.api.file.FileTree
|
||||||
|
import org.gradle.api.file.SourceDirectorySet
|
||||||
import org.gradle.api.logging.Logger
|
import org.gradle.api.logging.Logger
|
||||||
import org.gradle.api.provider.Provider
|
import org.gradle.api.provider.Provider
|
||||||
import org.gradle.api.tasks.*
|
import org.gradle.api.tasks.*
|
||||||
@@ -339,13 +341,12 @@ open class KotlinNativeCompile : AbstractKotlinNativeCompile<KotlinCommonOptions
|
|||||||
|
|
||||||
// Inputs and outputs.
|
// Inputs and outputs.
|
||||||
// region Sources.
|
// region Sources.
|
||||||
@InputFiles
|
|
||||||
@SkipWhenEmpty
|
|
||||||
override fun getSource(): FileTree = project.files(compilation.allSources).asFileTree
|
|
||||||
|
|
||||||
private val commonSources: FileCollection
|
@get:Internal // these sources are normally a subset of `source` ones which are already tracked
|
||||||
// Already taken into account in getSources method.
|
val commonSources: ConfigurableFileCollection = project.files()
|
||||||
get() = project.files(compilation.commonSources).asFileTree
|
|
||||||
|
private val commonSourcesTree: FileTree
|
||||||
|
get() = commonSources.asFileTree
|
||||||
|
|
||||||
private val friendModule: FileCollection?
|
private val friendModule: FileCollection?
|
||||||
get() = project.files(
|
get() = project.files(
|
||||||
@@ -414,8 +415,8 @@ open class KotlinNativeCompile : AbstractKotlinNativeCompile<KotlinCommonOptions
|
|||||||
|
|
||||||
override fun buildSourceArgs(): List<String> = mutableListOf<String>().apply {
|
override fun buildSourceArgs(): List<String> = mutableListOf<String>().apply {
|
||||||
addAll(getSource().map { it.absolutePath })
|
addAll(getSource().map { it.absolutePath })
|
||||||
if (!commonSources.isEmpty) {
|
if (!commonSourcesTree.isEmpty) {
|
||||||
add("-Xcommon-sources=${commonSources.map { it.absolutePath }.joinToString(separator = ",")}")
|
add("-Xcommon-sources=${commonSourcesTree.map { it.absolutePath }.joinToString(separator = ",")}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// endregion.
|
// endregion.
|
||||||
@@ -427,9 +428,7 @@ open class KotlinNativeCompile : AbstractKotlinNativeCompile<KotlinCommonOptions
|
|||||||
open class KotlinNativeLink : AbstractKotlinNativeCompile<KotlinCommonToolOptions>() {
|
open class KotlinNativeLink : AbstractKotlinNativeCompile<KotlinCommonToolOptions>() {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (!linkFromSources) {
|
dependsOn(project.provider { compilation.compileKotlinTask })
|
||||||
dependsOn(project.provider { compilation.compileKotlinTask })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Internal
|
@Internal
|
||||||
@@ -447,14 +446,7 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile<KotlinCommonToolOption
|
|||||||
@InputFiles
|
@InputFiles
|
||||||
@SkipWhenEmpty
|
@SkipWhenEmpty
|
||||||
override fun getSource(): FileTree =
|
override fun getSource(): FileTree =
|
||||||
if (linkFromSources) {
|
project.files(intermediateLibrary.get()).asFileTree
|
||||||
// Allow a user to force the old behaviour of a link task.
|
|
||||||
// It's better to keep this flag in 1.3.70 to be able to workaroud probable klib serialization bugs.
|
|
||||||
// TODO: Remove in 1.4.
|
|
||||||
project.files(compilation.allSources).asFileTree
|
|
||||||
} else {
|
|
||||||
project.files(intermediateLibrary.get()).asFileTree
|
|
||||||
}
|
|
||||||
|
|
||||||
@OutputDirectory
|
@OutputDirectory
|
||||||
override fun getDestinationDir(): File {
|
override fun getDestinationDir(): File {
|
||||||
@@ -508,29 +500,6 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile<KotlinCommonToolOption
|
|||||||
fn.call()
|
fn.call()
|
||||||
}
|
}
|
||||||
|
|
||||||
//region language settings inputs for the [linkFromSources] mode.
|
|
||||||
// TODO: Remove in 1.3.70.
|
|
||||||
@get:Optional
|
|
||||||
@get:Input
|
|
||||||
val languageVersion: String?
|
|
||||||
get() = languageSettings.languageVersion.takeIf { linkFromSources }
|
|
||||||
|
|
||||||
@get:Optional
|
|
||||||
@get:Input
|
|
||||||
val apiVersion: String?
|
|
||||||
get() = languageSettings.apiVersion.takeIf { linkFromSources }
|
|
||||||
|
|
||||||
@get:Optional
|
|
||||||
@get:Input
|
|
||||||
val enabledLanguageFeatures: Set<String>?
|
|
||||||
get() = languageSettings.enabledLanguageFeatures.takeIf { linkFromSources }
|
|
||||||
|
|
||||||
@get:Optional
|
|
||||||
@get:Input
|
|
||||||
val experimentalAnnotationsInUse: Set<String>?
|
|
||||||
get() = languageSettings.experimentalAnnotationsInUse.takeIf { linkFromSources }
|
|
||||||
// endregion.
|
|
||||||
|
|
||||||
// Binary-specific options.
|
// Binary-specific options.
|
||||||
@get:Optional
|
@get:Optional
|
||||||
@get:Input
|
@get:Input
|
||||||
@@ -563,13 +532,6 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile<KotlinCommonToolOption
|
|||||||
val embedBitcode: Framework.BitcodeEmbeddingMode
|
val embedBitcode: Framework.BitcodeEmbeddingMode
|
||||||
get() = (binary as? Framework)?.embedBitcode ?: Framework.BitcodeEmbeddingMode.DISABLE
|
get() = (binary as? Framework)?.embedBitcode ?: Framework.BitcodeEmbeddingMode.DISABLE
|
||||||
|
|
||||||
// This property allows a user to force the old behaviour of a link task
|
|
||||||
// to workaround issues that may occur after switching to the two-stage linking.
|
|
||||||
// If it is specified, the final binary is built directly from sources instead of a klib.
|
|
||||||
// TODO: Remove it in 1.3.70.
|
|
||||||
private val linkFromSources: Boolean
|
|
||||||
get() = project.hasProperty(LINK_FROM_SOURCES_PROPERTY)
|
|
||||||
|
|
||||||
override fun buildCompilerArgs(): List<String> = mutableListOf<String>().apply {
|
override fun buildCompilerArgs(): List<String> = mutableListOf<String>().apply {
|
||||||
addAll(super.buildCompilerArgs())
|
addAll(super.buildCompilerArgs())
|
||||||
|
|
||||||
@@ -590,47 +552,20 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile<KotlinCommonToolOption
|
|||||||
}
|
}
|
||||||
addKey("-Xstatic-framework", isStaticFramework)
|
addKey("-Xstatic-framework", isStaticFramework)
|
||||||
|
|
||||||
// Allow a user to force the old behaviour of a link task.
|
languageSettings.let {
|
||||||
// TODO: Remove in 1.3.70.
|
addArgIfNotNull("-language-version", it.languageVersion)
|
||||||
if (!linkFromSources) {
|
addArgIfNotNull("-api-version", it.apiVersion)
|
||||||
languageSettings.let {
|
it.enabledLanguageFeatures.forEach { featureName ->
|
||||||
addArgIfNotNull("-language-version", it.languageVersion)
|
add("-XXLanguage:+$featureName")
|
||||||
addArgIfNotNull("-api-version", it.apiVersion)
|
}
|
||||||
it.enabledLanguageFeatures.forEach { featureName ->
|
it.experimentalAnnotationsInUse.forEach { annotationName ->
|
||||||
add("-XXLanguage:+$featureName")
|
add("-Xopt-in=$annotationName")
|
||||||
}
|
|
||||||
it.experimentalAnnotationsInUse.forEach { annotationName ->
|
|
||||||
add("-Xopt-in=$annotationName")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun buildSourceArgs(): List<String> {
|
override fun buildSourceArgs(): List<String> =
|
||||||
return if (!linkFromSources) {
|
listOf("-Xinclude=${intermediateLibrary.get().absolutePath}")
|
||||||
listOf("-Xinclude=${intermediateLibrary.get().absolutePath}")
|
|
||||||
} else {
|
|
||||||
// Allow a user to force the old behaviour of a link task.
|
|
||||||
// TODO: Remove in 1.3.70.
|
|
||||||
mutableListOf<String>().apply {
|
|
||||||
val friendCompilations = compilation.associateWithTransitiveClosure.toList()
|
|
||||||
val friendFiles = if (friendCompilations.isNotEmpty())
|
|
||||||
project.files(
|
|
||||||
project.provider { friendCompilations.map { it.output.allOutputs } + compilation.friendArtifacts }
|
|
||||||
)
|
|
||||||
else null
|
|
||||||
|
|
||||||
if (friendFiles != null && !friendFiles.isEmpty) {
|
|
||||||
addArg("-friend-modules", friendFiles.joinToString(File.pathSeparator) { it.absolutePath })
|
|
||||||
}
|
|
||||||
|
|
||||||
addAll(project.files(compilation.allSources).map { it.absolutePath })
|
|
||||||
if (!compilation.commonSources.isEmpty) {
|
|
||||||
add("-Xcommon-sources=${compilation.commonSources.joinToString(separator = ",") { it.absolutePath }}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun validatedExportedLibraries() {
|
private fun validatedExportedLibraries() {
|
||||||
val exportConfiguration = exportLibraries as? Configuration ?: return
|
val exportConfiguration = exportLibraries as? Configuration ?: return
|
||||||
@@ -670,7 +605,6 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile<KotlinCommonToolOption
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val LINK_FROM_SOURCES_PROPERTY = "kotlin.native.linkFromSources"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user