From e6bca819d49ed44e1fb4a2772e88cbeae2fa7dca Mon Sep 17 00:00:00 2001 From: Sergey Igushkin Date: Mon, 29 Jun 2020 18:20:26 +0300 Subject: [PATCH] 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. --- .../kotlin/gradle/NewMultiplatformIT.kt | 24 ---- .../targets/native/KotlinNativeCompilation.kt | 17 +-- .../targets/native/tasks/KotlinNativeTasks.kt | 108 ++++-------------- 3 files changed, 26 insertions(+), 123 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt index 977c153fcff..14010fca230 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt @@ -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). // TODO: Reenable the test when the args are separated. @Ignore diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/KotlinNativeCompilation.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/KotlinNativeCompilation.kt index cecd1e44d09..abe10ae5ac0 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/KotlinNativeCompilation.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/KotlinNativeCompilation.kt @@ -60,18 +60,11 @@ abstract class AbstractKotlinNativeCompilation( override val compileKotlinTaskProvider: TaskProvider get() = super.compileKotlinTaskProvider as TaskProvider - // (taking into account dependencies between source sets). Used by both compilation - // and linking tasks. Unlike kotlinSourceSets, includes dependency source sets. - // TODO: Move into the compilation task when the linking task does klib linking instead of compilation. - internal val allSources: MutableSet = mutableSetOf() - - // 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) { - allSources.add(sourceSet.kotlin) - commonSources.from(target.project.files(Callable { if (addAsCommonSources.value) sourceSet.kotlin else emptyList() })) - } + override fun addSourcesToCompileTask(sourceSet: KotlinSourceSet, addAsCommonSources: Lazy) = + compileKotlinTaskProvider.configure { task -> + task.source(sourceSet.kotlin) + task.commonSources.from(target.project.files(Callable { if (addAsCommonSources.value) sourceSet.kotlin else emptyList() })) + } // Endorsed library controller. var enableEndorsedLibs: Boolean = false diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeTasks.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeTasks.kt index 8281d6b3db6..d7b3c97e0bc 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeTasks.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeTasks.kt @@ -10,8 +10,10 @@ import groovy.lang.Closure import org.gradle.api.DefaultTask import org.gradle.api.Project import org.gradle.api.artifacts.* +import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.FileCollection import org.gradle.api.file.FileTree +import org.gradle.api.file.SourceDirectorySet import org.gradle.api.logging.Logger import org.gradle.api.provider.Provider import org.gradle.api.tasks.* @@ -339,13 +341,12 @@ open class KotlinNativeCompile : AbstractKotlinNativeCompile = mutableListOf().apply { addAll(getSource().map { it.absolutePath }) - if (!commonSources.isEmpty) { - add("-Xcommon-sources=${commonSources.map { it.absolutePath }.joinToString(separator = ",")}") + if (!commonSourcesTree.isEmpty) { + add("-Xcommon-sources=${commonSourcesTree.map { it.absolutePath }.joinToString(separator = ",")}") } } // endregion. @@ -427,9 +428,7 @@ open class KotlinNativeCompile : AbstractKotlinNativeCompile() { init { - if (!linkFromSources) { - dependsOn(project.provider { compilation.compileKotlinTask }) - } + dependsOn(project.provider { compilation.compileKotlinTask }) } @Internal @@ -447,14 +446,7 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile? - get() = languageSettings.enabledLanguageFeatures.takeIf { linkFromSources } - - @get:Optional - @get:Input - val experimentalAnnotationsInUse: Set? - get() = languageSettings.experimentalAnnotationsInUse.takeIf { linkFromSources } - // endregion. - // Binary-specific options. @get:Optional @get:Input @@ -563,13 +532,6 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile = mutableListOf().apply { addAll(super.buildCompilerArgs()) @@ -590,47 +552,20 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile - add("-XXLanguage:+$featureName") - } - it.experimentalAnnotationsInUse.forEach { annotationName -> - add("-Xopt-in=$annotationName") - } + languageSettings.let { + addArgIfNotNull("-language-version", it.languageVersion) + addArgIfNotNull("-api-version", it.apiVersion) + it.enabledLanguageFeatures.forEach { featureName -> + add("-XXLanguage:+$featureName") + } + it.experimentalAnnotationsInUse.forEach { annotationName -> + add("-Xopt-in=$annotationName") } } } - override fun buildSourceArgs(): List { - return if (!linkFromSources) { - 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().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 }}") - } - } - } - } + override fun buildSourceArgs(): List = + listOf("-Xinclude=${intermediateLibrary.get().absolutePath}") private fun validatedExportedLibraries() { val exportConfiguration = exportLibraries as? Configuration ?: return @@ -670,7 +605,6 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile