Drop tasks inheritance from 'AbstractCompile' and 'SourceTask'
'AbstractCompile' task has inputs that are related only to Java compilation and should not used for Kotlin compile tasks. 'SourceTask' most probably will be deprecated in future Gradle releases - https://github.com/gradle/gradle/issues/9040. Plus it has old 'sources' with 'FileTree' type which is not stable for task inputs snapshotting. Another breaking change - 'destinationDir' task property is not longer available. It is replaced by 'destinationDirectory' which uses Gradle Provider API type. ^KT-32805 In Progress
This commit is contained in:
committed by
teamcity
parent
f70b477fa7
commit
e9498c8978
@@ -106,8 +106,6 @@ tasks.compileJava {
|
||||
|
||||
tasks.compileKotlin {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
sourceCompatibility = "1.8"
|
||||
targetCompatibility = "1.8"
|
||||
}
|
||||
|
||||
projectTest(parallel = true) {
|
||||
|
||||
@@ -57,7 +57,7 @@ val compileTestDevelopmentExecutableKotlinJs = tasks.named<KotlinJsIrLink>("comp
|
||||
val populateNodeModules = tasks.register<Copy>("populateNodeModules") {
|
||||
dependsOn("compileTestDevelopmentExecutableKotlinJs")
|
||||
dependsOn(nodeModules)
|
||||
from(compileTestDevelopmentExecutableKotlinJs.map { it.destinationDir })
|
||||
from(compileTestDevelopmentExecutableKotlinJs.map { it.destinationDirectory })
|
||||
|
||||
from {
|
||||
nodeModules.get().map {
|
||||
|
||||
@@ -36,7 +36,7 @@ buildDir = "$projectDir/build"
|
||||
tasks.register("populateNodeModules", Copy) {
|
||||
dependsOn(compileKotlin2Js)
|
||||
dependsOn(configurations.nodeModules)
|
||||
from compileKotlin2Js.destinationDir
|
||||
from compileKotlin2Js.destinationDirectory
|
||||
|
||||
from {
|
||||
configurations.nodeModules.collect {
|
||||
|
||||
+1
-1
@@ -84,7 +84,7 @@ class BuildCacheRelocationIT : KGPBaseTest() {
|
||||
testProject.subProject("libraryProject").buildGradle.modify {
|
||||
it.replace("/exampleapp.js", "/web/exampleapp.js")
|
||||
// Fix assembling the JAR from the whole buildDir
|
||||
it.replace("from buildDir", "from compileKotlin2Js.destinationDir")
|
||||
it.replace("from buildDir", "from compileKotlin2Js.destinationDirectory")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+13
-3
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle
|
||||
|
||||
import org.gradle.api.logging.configuration.WarningMode
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.gradle.testbase.*
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
@@ -127,14 +128,23 @@ class ConfigurationAvoidanceIT : KGPBaseTest() {
|
||||
@DisplayName("JS early configuration resolution")
|
||||
@GradleTest
|
||||
fun testEarlyConfigurationsResolutionKotlinJs(gradleVersion: GradleVersion) {
|
||||
testEarlyConfigurationsResolution("kotlin-js-browser-project", gradleVersion, kts = true)
|
||||
testEarlyConfigurationsResolution(
|
||||
"kotlin-js-browser-project",
|
||||
gradleVersion,
|
||||
kts = true,
|
||||
buildOptions = defaultBuildOptions.copy(
|
||||
// bug in Gradle: https://github.com/gradle/gradle/issues/15796
|
||||
warningMode = if (gradleVersion < GradleVersion.version("7.0")) WarningMode.Summary else defaultBuildOptions.warningMode
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private fun testEarlyConfigurationsResolution(
|
||||
projectName: String,
|
||||
gradleVersion: GradleVersion,
|
||||
kts: Boolean
|
||||
) = project(projectName, gradleVersion) {
|
||||
kts: Boolean,
|
||||
buildOptions: BuildOptions = defaultBuildOptions
|
||||
) = project(projectName, gradleVersion, buildOptions = buildOptions) {
|
||||
(if (kts) buildGradleKts else buildGradle).appendText(
|
||||
//language=Gradle
|
||||
"""${'\n'}
|
||||
|
||||
+2
-7
@@ -9,10 +9,7 @@ import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.gradle.testbase.*
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.createDirectories
|
||||
import kotlin.io.path.deleteExisting
|
||||
import kotlin.io.path.relativeTo
|
||||
import kotlin.io.path.writeText
|
||||
import kotlin.io.path.*
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@DisplayName("Default incremental compilation with default precise java tracking")
|
||||
@@ -66,9 +63,7 @@ open class IncrementalJavaChangeDefaultIT : IncrementalCompilationJavaChangesBas
|
||||
}
|
||||
build("compileKotlin", "--rerun-tasks") {
|
||||
assertTasksExecuted(":compileKotlin")
|
||||
val compiledKotlinClasses = kotlinClassesDir().allFilesWithExtension("class").toList()
|
||||
|
||||
assertTrue(compiledKotlinClasses.isEmpty())
|
||||
assertTrue(kotlinClassesDir().notExists())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-6
@@ -94,8 +94,7 @@ class KlibBasedMppIT : BaseGradleIT() {
|
||||
"published-producer-commonMain.klib",
|
||||
"published-dependency-$hostSpecificSourceSet.klib",
|
||||
"published-dependency-commonMain.klib"
|
||||
),
|
||||
isNative = true
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -318,13 +317,12 @@ class KlibBasedMppIT : BaseGradleIT() {
|
||||
private fun BaseGradleIT.Project.checkTaskCompileClasspath(
|
||||
taskPath: String,
|
||||
checkModulesInClasspath: List<String> = emptyList(),
|
||||
checkModulesNotInClasspath: List<String> = emptyList(),
|
||||
isNative: Boolean = false
|
||||
checkModulesNotInClasspath: List<String> = emptyList()
|
||||
) {
|
||||
val subproject = taskPath.substringBeforeLast(":").takeIf { it.isNotEmpty() && it != taskPath }
|
||||
val taskName = taskPath.removePrefix(subproject.orEmpty())
|
||||
val taskClass = if (isNative) "org.jetbrains.kotlin.gradle.tasks.AbstractKotlinNativeCompile<*, *>" else "AbstractCompile"
|
||||
val expression = """(tasks.getByName("$taskName") as $taskClass).${if (isNative) "libraries" else "classpath"}.toList()"""
|
||||
val taskClass = "org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompileTool<*>"
|
||||
val expression = """(tasks.getByName("$taskName") as $taskClass).libraries.toList()"""
|
||||
checkPrintedItems(subproject, expression, checkModulesInClasspath, checkModulesNotInClasspath)
|
||||
}
|
||||
|
||||
|
||||
+8
-1
@@ -1176,7 +1176,14 @@ class GeneralKotlin2JsGradlePluginIT : KGPBaseTest() {
|
||||
@DisplayName("nodejs up-to-date check works")
|
||||
@GradleTest
|
||||
fun testNodeJsAndYarnDownload(gradleVersion: GradleVersion) {
|
||||
project("cleanTask", gradleVersion) {
|
||||
project(
|
||||
"cleanTask",
|
||||
gradleVersion,
|
||||
buildOptions = defaultBuildOptions.copy(
|
||||
// bug in Gradle: https://github.com/gradle/gradle/issues/15796
|
||||
warningMode = if (gradleVersion < GradleVersion.version("7.0")) WarningMode.None else defaultBuildOptions.warningMode
|
||||
)
|
||||
) {
|
||||
build("checkDownloadedFolder")
|
||||
|
||||
build("checkIfLastModifiedNotNow", "--rerun-tasks")
|
||||
|
||||
+5
-2
@@ -551,12 +551,15 @@ class KotlinSpecificDependenciesIT : KGPBaseTest() {
|
||||
taskPath: String,
|
||||
checkModulesInClasspath: List<String> = emptyList(),
|
||||
checkModulesNotInClasspath: List<String> = emptyList(),
|
||||
isNative: Boolean = false,
|
||||
isBuildGradleKts: Boolean = false
|
||||
) {
|
||||
val subproject = taskPath.substringBeforeLast(":").takeIf { it.isNotEmpty() && it != taskPath }
|
||||
val taskName = taskPath.removePrefix(subproject.orEmpty())
|
||||
val taskClass = if (isNative) "org.jetbrains.kotlin.gradle.tasks.AbstractKotlinNativeCompile<*, *>" else "AbstractCompile"
|
||||
val taskClass = if (isBuildGradleKts) {
|
||||
"org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompileTool<*>"
|
||||
} else {
|
||||
"org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompileTool<?>"
|
||||
}
|
||||
val expression = """(tasks.getByName("$taskName") as $taskClass).${if (isNative) "libraries" else "classpath"}.toList()"""
|
||||
checkPrintedItems(subproject, expression, checkModulesInClasspath, checkModulesNotInClasspath, isBuildGradleKts)
|
||||
}
|
||||
|
||||
+9
-4
@@ -5,11 +5,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.tasks
|
||||
|
||||
import org.gradle.api.logging.configuration.WarningMode
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.gradle.BaseGradleIT
|
||||
import org.jetbrains.kotlin.gradle.testbase.*
|
||||
import org.jetbrains.kotlin.gradle.transformProjectWithPluginsDsl
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
|
||||
|
||||
@@ -19,7 +17,14 @@ class CleanDataTaskIT : KGPBaseTest() {
|
||||
@DisplayName("nodejs is deleted from Gradle user home")
|
||||
@GradleTest
|
||||
fun testDownloadedFolderDeletion(gradleVersion: GradleVersion) {
|
||||
project("cleanTask", gradleVersion) {
|
||||
project(
|
||||
"cleanTask",
|
||||
gradleVersion,
|
||||
buildOptions = defaultBuildOptions.copy(
|
||||
// bug in Gradle: https://github.com/gradle/gradle/issues/15796
|
||||
warningMode = if (gradleVersion < GradleVersion.version("7.0")) WarningMode.Summary else defaultBuildOptions.warningMode
|
||||
)
|
||||
) {
|
||||
build("testCleanTask")
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ dependencies {
|
||||
}
|
||||
|
||||
// important to test that destinationDir is configured before evaluation
|
||||
test.testClassesDirs = files(project.tasks.compileTestKotlin.destinationDir)
|
||||
test.testClassesDirs = files(project.tasks.compileTestKotlin.destinationDirectory)
|
||||
|
||||
test {
|
||||
testLogging {
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ kotlin {
|
||||
// Creating static library with a custom name.
|
||||
staticLib('customNameForiosSimLib') {
|
||||
outputDirectory = file("fooCustomNameForiosSimLib") // outputDir is a `val` property.
|
||||
linkTask.destinationDir = file("fooCustomNameForiosSimLib")
|
||||
linkTask.destinationDirectory = file("fooCustomNameForiosSimLib")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -39,7 +39,7 @@ kotlin {
|
||||
// Creating static library with a custom name.
|
||||
staticLib('customNameForLinuxLib') {
|
||||
outputDirectory = file("customNameForLinuxLib") // outputDir is a `val` property.
|
||||
linkTask.destinationDir = file("customNameForLinuxLib")
|
||||
linkTask.destinationDirectory = file("customNameForLinuxLib")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ kotlin {
|
||||
// Creating static library with a custom name.
|
||||
staticLib('customNameForMacosLib') {
|
||||
outputDirectory = file("customNameForMacosLib") // outputDir is a `val` property.
|
||||
linkTask.destinationDir = file("customNameForMacosLib")
|
||||
linkTask.destinationDirectory = file("customNameForMacosLib")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,7 @@ kotlin {
|
||||
// KT-29395 fix
|
||||
framework {
|
||||
outputDirectory = file("fooDummyiOS") // outputDir is a `val` property.
|
||||
linkTask.destinationDir = file("fooDummyiOS")
|
||||
linkTask.destinationDirectory = file("fooDummyiOS")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-5
@@ -8,12 +8,8 @@ package org.jetbrains.kotlin.gradle.mpp
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.Configuration
|
||||
import org.gradle.api.internal.project.ProjectInternal
|
||||
import org.gradle.api.plugins.ExtraPropertiesExtension
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.testfixtures.ProjectBuilder
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.tasks.*
|
||||
import kotlin.test.*
|
||||
@@ -293,7 +289,7 @@ internal class CompilationSpecificPluginPath {
|
||||
.getByName(taskName)
|
||||
.let {
|
||||
when (it) {
|
||||
is AbstractKotlinNativeCompile<*, *> -> it.compilerPluginClasspath
|
||||
is AbstractKotlinNativeCompile<*, *, *> -> it.compilerPluginClasspath
|
||||
is AbstractKotlinCompile<*> -> it.pluginClasspath.from.single()
|
||||
else -> error("Unexpected task type with name $taskName. Is it kotlin compile task?")
|
||||
}
|
||||
|
||||
+1
-1
@@ -144,7 +144,7 @@ class KpmCompilerPluginTest {
|
||||
.let {
|
||||
when (it) {
|
||||
is AbstractKotlinCompile<*> -> it.kotlinPluginData
|
||||
is AbstractKotlinNativeCompile<*, *> -> it.kotlinPluginData
|
||||
is AbstractKotlinNativeCompile<*, *, *> -> it.kotlinPluginData
|
||||
else -> error("Unknown task type: $it")
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -300,7 +300,7 @@ internal open class GradleCompilerRunner(
|
||||
task.buildHistoryFile.get().asFile,
|
||||
task.abiSnapshotFile.get().asFile
|
||||
)
|
||||
dirToModule[task.destinationDir] = module
|
||||
dirToModule[task.destinationDirectory.get().asFile] = module
|
||||
task.javaOutputDir.orNull?.asFile?.let { dirToModule[it] = module }
|
||||
nameToModules.getOrPut(module.name) { HashSet() }.add(module)
|
||||
|
||||
|
||||
+7
-7
@@ -35,7 +35,6 @@ import org.jetbrains.kotlin.gradle.utils.isParentOf
|
||||
import org.jetbrains.kotlin.incremental.classpathAsList
|
||||
import org.jetbrains.kotlin.incremental.destinationAsFile
|
||||
import java.io.File
|
||||
import java.util.concurrent.Callable
|
||||
import javax.inject.Inject
|
||||
|
||||
@CacheableTask
|
||||
@@ -63,7 +62,7 @@ abstract class KaptGenerateStubsTask @Inject constructor(
|
||||
val providerFactory = kotlinCompileTask.project.providers
|
||||
task.useModuleDetection.value(kotlinCompileTask.useModuleDetection).disallowChanges()
|
||||
task.moduleName.value(kotlinCompileTask.moduleName).disallowChanges()
|
||||
task.classpath = task.project.files(Callable { kotlinCompileTask.classpath })
|
||||
task.classpath.from(kotlinCompileTask.classpath)
|
||||
task.kotlinTaskPluginClasspath.from(
|
||||
providerFactory.provider { kotlinCompileTask.pluginClasspath }
|
||||
)
|
||||
@@ -119,16 +118,17 @@ abstract class KaptGenerateStubsTask @Inject constructor(
|
||||
@get:Incremental
|
||||
abstract val additionalSources: ConfigurableFileCollection
|
||||
|
||||
override fun source(vararg sources: Any): SourceTask {
|
||||
return super.source(sourceRootsContainer.add(sources))
|
||||
override fun setSource(vararg source: Any) {
|
||||
super.setSource(sourceRootsContainer.add(sources))
|
||||
}
|
||||
|
||||
override fun setSource(sources: Any) {
|
||||
override fun setSource(source: Any) {
|
||||
super.setSource(sourceRootsContainer.set(sources))
|
||||
}
|
||||
|
||||
// TODO: prevent querying destinationDirectory on configuration time
|
||||
private fun isSourceRootAllowed(source: File): Boolean =
|
||||
!destinationDir.isParentOf(source) &&
|
||||
!destinationDirectory.get().asFile.isParentOf(source) &&
|
||||
!stubsDir.asFile.get().isParentOf(source) &&
|
||||
generatedSourcesDirs.none { it.isParentOf(source) }
|
||||
|
||||
@@ -146,7 +146,7 @@ abstract class KaptGenerateStubsTask @Inject constructor(
|
||||
|
||||
args.verbose = verbose.get()
|
||||
args.classpathAsList = this.classpath.filter { it.exists() }.toList()
|
||||
args.destinationAsFile = this.destinationDir
|
||||
args.destinationAsFile = this.destinationDirectory.get().asFile
|
||||
}
|
||||
|
||||
@get:Internal
|
||||
|
||||
+2
-2
@@ -90,7 +90,7 @@ class KotlinModelBuilder(private val kotlinPluginVersion: String, private val an
|
||||
friendSourceSets.get(),
|
||||
kotlinSourceSet.kotlin.srcDirs,
|
||||
javaSourceSet.resources.srcDirs,
|
||||
destinationDir,
|
||||
destinationDirectory.get().asFile,
|
||||
javaSourceSet.output.resourcesDir!!,
|
||||
createCompilerArguments()
|
||||
)
|
||||
@@ -116,7 +116,7 @@ class KotlinModelBuilder(private val kotlinPluginVersion: String, private val an
|
||||
friendSourceSets.get(),
|
||||
sources,
|
||||
resources,
|
||||
destinationDir,
|
||||
destinationDirectory.get().asFile,
|
||||
compilation.output.resourcesDir,
|
||||
createCompilerArguments()
|
||||
)
|
||||
|
||||
+1
-1
@@ -175,7 +175,7 @@ open class KotlinPlatformImplementationPluginBase(platformName: String) : Kotlin
|
||||
|
||||
val commonSources = getKotlinSourceDirectorySetSafe(commonSourceSet)!!
|
||||
for (platformTask in platformTasks) {
|
||||
platformTask.source(commonSources)
|
||||
platformTask.setSource(commonSources)
|
||||
platformTask.commonSourceSet.from(commonSources)
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -36,7 +36,6 @@ import org.jetbrains.kotlin.gradle.model.builder.KotlinModelBuilder
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinCompilationData
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.isMainCompilationData
|
||||
import org.jetbrains.kotlin.gradle.report.BuildMetricsReporterService
|
||||
import org.jetbrains.kotlin.gradle.scripting.internal.ScriptingGradleSubplugin
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBinaryMode
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.*
|
||||
@@ -65,7 +64,7 @@ val KOTLIN_DSL_NAME = "kotlin"
|
||||
val KOTLIN_JS_DSL_NAME = "kotlin2js"
|
||||
val KOTLIN_OPTIONS_DSL_NAME = "kotlinOptions"
|
||||
|
||||
abstract class KotlinCompilationProcessor<out T : SourceTask>(
|
||||
abstract class KotlinCompilationProcessor<out T : AbstractKotlinCompileTool<*>>(
|
||||
open val kotlinCompilation: KotlinCompilationData<*>
|
||||
) {
|
||||
abstract val kotlinTask: TaskProvider<out T>
|
||||
@@ -123,7 +122,7 @@ internal abstract class KotlinSourceSetProcessor<T : AbstractKotlinCompile<*>>(
|
||||
return register(project, name) {
|
||||
it.description = taskDescription
|
||||
it.destinationDirectory.set(defaultKotlinDestinationDir)
|
||||
it.classpath = project.files({ kotlinCompilation.compileDependencyFiles })
|
||||
it.classpath.from({ kotlinCompilation.compileDependencyFiles })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1049,7 +1048,7 @@ abstract class AbstractAndroidProjectHandler(private val kotlinConfigurationTool
|
||||
val kotlinTask = compilation.compileKotlinTaskProvider
|
||||
compilation.androidVariant.forEachJavaSourceDir { sources ->
|
||||
kotlinTask.configure {
|
||||
it.source(sources.dir)
|
||||
it.setSource(sources.dir)
|
||||
it.dependsOn(sources)
|
||||
}
|
||||
}
|
||||
|
||||
+12
-5
@@ -2,7 +2,6 @@ package org.jetbrains.kotlin.gradle.plugin
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.gradle.api.tasks.compile.AbstractCompile
|
||||
import org.gradle.api.tasks.compile.JavaCompile
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
|
||||
import org.jetbrains.kotlin.gradle.logging.kotlinDebug
|
||||
@@ -13,6 +12,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinWithJavaCompilation
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.JsIrBinary
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation
|
||||
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile
|
||||
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompileTool
|
||||
import org.jetbrains.kotlin.gradle.tasks.CompilerPluginOptions
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
|
||||
|
||||
@@ -89,13 +89,20 @@ class SubpluginEnvironment(
|
||||
}
|
||||
}
|
||||
|
||||
internal fun addCompilationSourcesToExternalCompileTask(compilation: KotlinCompilation<*>, task: TaskProvider<out AbstractCompile>) {
|
||||
internal fun addCompilationSourcesToExternalCompileTask(
|
||||
compilation: KotlinCompilation<*>,
|
||||
task: TaskProvider<out AbstractKotlinCompileTool<*>>
|
||||
) {
|
||||
if (compilation is KotlinJvmAndroidCompilation) {
|
||||
compilation.androidVariant.forEachKotlinSourceSet { sourceSet -> task.configure { it.source(sourceSet.kotlin) } }
|
||||
compilation.androidVariant.forEachJavaSourceDir { sources -> task.configure { it.source(sources.dir) } }
|
||||
compilation.androidVariant.forEachKotlinSourceSet { sourceSet ->
|
||||
task.configure { it.setSource(sourceSet.kotlin) }
|
||||
}
|
||||
compilation.androidVariant.forEachJavaSourceDir { sources ->
|
||||
task.configure { it.setSource(sources.dir) }
|
||||
}
|
||||
} else {
|
||||
task.configure { taskInstance ->
|
||||
compilation.allKotlinSourceSets.forEach { sourceSet -> taskInstance.source(sourceSet.kotlin) }
|
||||
compilation.allKotlinSourceSets.forEach { sourceSet -> taskInstance.setSource(sourceSet.kotlin) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -163,7 +163,7 @@ internal fun addSourcesToKotlinCompileTask(
|
||||
fun AbstractKotlinCompile<*>.configureAction() {
|
||||
// In this call, the super-implementation of `source` adds the directories files to the roots of the union file tree,
|
||||
// so it's OK to pass just the source roots.
|
||||
source(Callable(sources))
|
||||
setSource(Callable(sources))
|
||||
sourceFilesExtensions.addAll(sourceFileExtensions)
|
||||
|
||||
// The `commonSourceSet` is passed to the compiler as-is, converted with toList
|
||||
|
||||
+1
-2
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.gradle.plugin.mpp.pm20
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.gradle.api.tasks.compile.AbstractCompile
|
||||
import org.jetbrains.kotlin.gradle.plugin.Kotlin2JvmSourceSetProcessor
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinNativeTargetConfigurator
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.addCommonSourcesToKotlinCompileTask
|
||||
@@ -57,7 +56,7 @@ open class KotlinCompilationTaskConfigurator(
|
||||
val commonSources = getCommonSourcesForFragmentCompilation(fragment)
|
||||
|
||||
compileTask.configure {
|
||||
it.source(allSources)
|
||||
it.setSource(allSources)
|
||||
it.commonSources.from(commonSources)
|
||||
|
||||
it.configure()
|
||||
|
||||
+2
-2
@@ -77,7 +77,7 @@ internal class DefaultLanguageSettingsBuilder : LanguageSettingsBuilder {
|
||||
val pluginOptionsTask = compilerPluginOptionsTask.value ?: return null
|
||||
return when (pluginOptionsTask) {
|
||||
is AbstractKotlinCompile<*> -> pluginOptionsTask.pluginOptions
|
||||
is AbstractKotlinNativeCompile<*, *> -> pluginOptionsTask.compilerPluginOptions
|
||||
is AbstractKotlinNativeCompile<*, *, *> -> pluginOptionsTask.compilerPluginOptions
|
||||
else -> error("Unexpected task: $pluginOptionsTask")
|
||||
}.arguments
|
||||
}
|
||||
@@ -87,7 +87,7 @@ internal class DefaultLanguageSettingsBuilder : LanguageSettingsBuilder {
|
||||
val pluginClasspathTask = compilerPluginOptionsTask.value ?: return null
|
||||
return when (pluginClasspathTask) {
|
||||
is AbstractKotlinCompile<*> -> pluginClasspathTask.pluginClasspath
|
||||
is AbstractKotlinNativeCompile<*, *> -> pluginClasspathTask.compilerPluginClasspath ?: pluginClasspathTask.project.files()
|
||||
is AbstractKotlinNativeCompile<*, *, *> -> pluginClasspathTask.compilerPluginClasspath ?: pluginClasspathTask.project.files()
|
||||
else -> error("Unexpected task: $pluginClasspathTask")
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -17,7 +17,6 @@ import org.gradle.api.attributes.Attribute
|
||||
import org.gradle.api.attributes.Category
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.specs.Spec
|
||||
import org.gradle.api.tasks.PathSensitivity
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.gradle.api.tasks.bundling.AbstractArchiveTask
|
||||
import org.gradle.api.tasks.compile.AbstractCompile
|
||||
@@ -49,7 +48,7 @@ class Android25ProjectHandler(
|
||||
) {
|
||||
val preJavaKotlinOutput = project.files(project.provider {
|
||||
mutableListOf<File>().apply {
|
||||
add(kotlinTask.get().destinationDir)
|
||||
add(kotlinTask.get().destinationDirectory.get().asFile)
|
||||
if (Kapt3GradleSubplugin.isEnabled(project)) {
|
||||
// Add Kapt3 output as well, since there's no SyncOutputTask with the new API
|
||||
val kaptClasssesDir = Kapt3GradleSubplugin.getKaptGeneratedClassesDir(project, getVariantName(variantData))
|
||||
@@ -60,7 +59,7 @@ class Android25ProjectHandler(
|
||||
|
||||
val preJavaClasspathKey = variantData.registerPreJavacGeneratedBytecode(preJavaKotlinOutput)
|
||||
kotlinTask.configure { kotlinTaskInstance ->
|
||||
kotlinTaskInstance.classpath = project.files()
|
||||
kotlinTaskInstance.classpath
|
||||
.from(variantData.getCompileClasspath(preJavaClasspathKey))
|
||||
.from(Callable { AndroidGradleWrapper.getRuntimeJars(androidPlugin, androidExt) })
|
||||
|
||||
|
||||
+1
-1
@@ -130,7 +130,7 @@ class AndroidSubplugin : KotlinCompilerPluginSupportPlugin {
|
||||
)
|
||||
)
|
||||
kotlinCompilation.compileKotlinTaskProvider.configure {
|
||||
it.source(getLayoutDirectories(project, sourceSet.res.srcDirs))
|
||||
it.setSource(getLayoutDirectories(project, sourceSet.res.srcDirs))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -76,9 +76,9 @@ class KotlinJsDcePlugin : Plugin<Project> {
|
||||
val configuration = project.configurations.getByName(kotlinCompilation.compileDependencyConfigurationName)
|
||||
|
||||
dceTask.configure {
|
||||
it.classpath = configuration
|
||||
it.destinationDir = it.dceOptions.outputDirectory?.let { File(it) } ?: outputDir
|
||||
it.source((kotlinTask.get() as Kotlin2JsCompile).outputFileProperty.get())
|
||||
it.classpath.from(configuration)
|
||||
it.destinationDirectory.set(it.dceOptions.outputDirectory?.let { File(it) } ?: outputDir)
|
||||
it.setSource((kotlinTask.get() as Kotlin2JsCompile).outputFileProperty)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+18
-12
@@ -7,10 +7,9 @@ package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||
|
||||
import org.gradle.api.file.ConfigurableFileCollection
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.file.FileTree
|
||||
import org.gradle.api.file.ProjectLayout
|
||||
import org.gradle.api.model.ObjectFactory
|
||||
import org.gradle.api.tasks.*
|
||||
import org.gradle.internal.hash.FileHasher
|
||||
import org.gradle.workers.WorkerExecutor
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.parseCommandLineArguments
|
||||
@@ -26,6 +25,7 @@ import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBinaryMode.DEVELOPMENT
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBinaryMode.PRODUCTION
|
||||
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
|
||||
import org.jetbrains.kotlin.gradle.utils.getValue
|
||||
import org.jetbrains.kotlin.gradle.utils.property
|
||||
import org.jetbrains.kotlin.gradle.utils.toHexString
|
||||
import org.jetbrains.kotlin.statistics.metrics.BooleanMetrics
|
||||
import org.jetbrains.kotlin.statistics.metrics.StringMetrics
|
||||
@@ -36,8 +36,9 @@ import javax.inject.Inject
|
||||
|
||||
@CacheableTask
|
||||
abstract class KotlinJsIrLink @Inject constructor(
|
||||
objectFactory: ObjectFactory,
|
||||
workerExecutor: WorkerExecutor
|
||||
private val objectFactory: ObjectFactory,
|
||||
workerExecutor: WorkerExecutor,
|
||||
private val projectLayout: ProjectLayout
|
||||
) : Kotlin2JsCompile(
|
||||
KotlinJsOptionsImpl(),
|
||||
objectFactory,
|
||||
@@ -81,8 +82,8 @@ abstract class KotlinJsIrLink @Inject constructor(
|
||||
lateinit var mode: KotlinJsBinaryMode
|
||||
|
||||
// Not check sources, only klib module
|
||||
@Internal
|
||||
override fun getSource(): FileTree = super.getSource()
|
||||
@get:Internal
|
||||
abstract override val sources: ConfigurableFileCollection
|
||||
|
||||
private val buildDir = project.buildDir
|
||||
|
||||
@@ -92,13 +93,18 @@ abstract class KotlinJsIrLink @Inject constructor(
|
||||
@get:PathSensitive(PathSensitivity.RELATIVE)
|
||||
internal abstract val entryModule: DirectoryProperty
|
||||
|
||||
override fun getDestinationDir(): File {
|
||||
return if (kotlinOptions.outputFile == null) {
|
||||
super.getDestinationDir()
|
||||
} else {
|
||||
outputFile.parentFile
|
||||
override val destinationDirectory: DirectoryProperty
|
||||
get() = objectFactory.directoryProperty().apply {
|
||||
set(
|
||||
destinationDirectory.flatMap { dir ->
|
||||
if (kotlinOptions.outputFile == null) {
|
||||
objectFactory.property(dir)
|
||||
} else {
|
||||
projectLayout.dir(outputFileProperty.map { it.parentFile })
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun skipCondition(): Boolean {
|
||||
return !entryModule.get().asFile.exists()
|
||||
|
||||
+1
-2
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
||||
import org.jetbrains.kotlin.gradle.tasks.locateOrRegisterTask
|
||||
import org.jetbrains.kotlin.gradle.tasks.registerTask
|
||||
import org.jetbrains.kotlin.gradle.utils.listProperty
|
||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||
import org.jetbrains.kotlin.gradle.utils.setProperty
|
||||
import javax.inject.Inject
|
||||
@@ -137,7 +136,7 @@ constructor(
|
||||
binary.linkSyncTaskName
|
||||
) { task ->
|
||||
task.from(
|
||||
project.layout.file(binary.linkTask.map { it.destinationDir })
|
||||
project.layout.file(binary.linkTask.flatMap { it.destinationDirectory.map { it.asFile } })
|
||||
)
|
||||
|
||||
task.from(project.tasks.named(compilation.processResourcesTaskName))
|
||||
|
||||
+3
-3
@@ -97,9 +97,9 @@ open class KotlinJsIrTargetConfigurator() :
|
||||
|
||||
compilation.compileKotlinTaskProvider.configure { task ->
|
||||
val outputFilePath = outputFile ?: if (produceUnzippedKlib) {
|
||||
task.destinationDir.absoluteFile.normalize().absolutePath
|
||||
task.destinationDirectory.get().asFile.absoluteFile.normalize().absolutePath
|
||||
} else {
|
||||
File(task.destinationDir, "$baseName.$KLIB_TYPE").absoluteFile.normalize().absolutePath
|
||||
File(task.destinationDirectory.get().asFile, "$baseName.$KLIB_TYPE").absoluteFile.normalize().absolutePath
|
||||
}
|
||||
outputFile = outputFilePath
|
||||
|
||||
@@ -112,7 +112,7 @@ open class KotlinJsIrTargetConfigurator() :
|
||||
"To fix this, consider using the default outputFile location instead of providing it explicitly."
|
||||
)
|
||||
|
||||
task.destinationDir = taskOutputDir
|
||||
task.destinationDirectory.set(taskOutputDir)
|
||||
}
|
||||
|
||||
val klibModuleName = target.project.klibModuleName(baseName)
|
||||
|
||||
+13
-8
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
|
||||
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
|
||||
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig.Mode
|
||||
import org.jetbrains.kotlin.gradle.targets.js.webpack.WebpackDevtool
|
||||
import org.jetbrains.kotlin.gradle.targets.js.webpack.WebpackMajorVersion
|
||||
import org.jetbrains.kotlin.gradle.targets.js.webpack.WebpackMajorVersion.Companion.choose
|
||||
import org.jetbrains.kotlin.gradle.tasks.dependsOn
|
||||
import org.jetbrains.kotlin.gradle.tasks.registerTask
|
||||
@@ -266,9 +265,13 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
||||
}
|
||||
|
||||
entryProperty.set(
|
||||
project.layout.file(actualDceTaskProvider.map {
|
||||
it.destinationDir.resolve(compilation.compileKotlinTask.outputFileProperty.get().name)
|
||||
})
|
||||
project.layout.file(
|
||||
actualDceTaskProvider
|
||||
.map {
|
||||
it.destinationDirectory.file(compilation.compileKotlinTask.outputFileProperty.get().name)
|
||||
}
|
||||
.flatMap { it.map { it.asFile } }
|
||||
)
|
||||
)
|
||||
|
||||
resolveFromModulesFirst = true
|
||||
@@ -305,12 +308,14 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
||||
|
||||
it.kotlinFilesOnly = true
|
||||
|
||||
it.classpath = project.configurations.getByName(compilation.runtimeDependencyConfigurationName)
|
||||
it.destinationDir = it.dceOptions.outputDirectory?.let { File(it) }
|
||||
?: compilation.npmProject.dir.resolve(if (dev) DCE_DEV_DIR else DCE_DIR)
|
||||
it.classpath.from(project.configurations.getByName(compilation.runtimeDependencyConfigurationName))
|
||||
it.destinationDirectory.set(
|
||||
it.dceOptions.outputDirectory?.let { File(it) }
|
||||
?: compilation.npmProject.dir.resolve(if (dev) DCE_DEV_DIR else DCE_DIR)
|
||||
)
|
||||
it.defaultCompilerClasspath.setFrom(project.configurations.named(COMPILER_CLASSPATH_CONFIGURATION_NAME))
|
||||
|
||||
it.source(kotlinTask.map { it.outputFileProperty.get() })
|
||||
it.setSource(kotlinTask.map { it.outputFileProperty })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+23
-17
@@ -224,23 +224,29 @@ constructor(
|
||||
compilation.platformType
|
||||
}
|
||||
|
||||
/**
|
||||
* [forNpmDependencies] is used to avoid querying [destinationDirectory] before task execution.
|
||||
* Otherwise, Gradle will fail the build.
|
||||
*/
|
||||
private fun createWebpackConfig(forNpmDependencies: Boolean = false) = KotlinWebpackConfig(
|
||||
mode = mode,
|
||||
entry = if (forNpmDependencies) null else entry,
|
||||
reportEvaluatedConfigFile = if (!forNpmDependencies && saveEvaluatedConfigFile) evaluatedConfigFile else null,
|
||||
output = output,
|
||||
outputPath = if (forNpmDependencies) null else destinationDirectory,
|
||||
outputFileName = outputFileName,
|
||||
configDirectory = configDirectory,
|
||||
bundleAnalyzerReportDir = if (!forNpmDependencies && report) reportDir else null,
|
||||
cssSupport = cssSupport,
|
||||
devServer = devServer,
|
||||
devtool = devtool,
|
||||
sourceMaps = sourceMaps,
|
||||
resolveFromModulesFirst = resolveFromModulesFirst,
|
||||
webpackMajorVersion = webpackMajorVersion
|
||||
)
|
||||
|
||||
private fun createRunner(): KotlinWebpackRunner {
|
||||
val config = KotlinWebpackConfig(
|
||||
mode = mode,
|
||||
entry = entry,
|
||||
reportEvaluatedConfigFile = if (saveEvaluatedConfigFile) evaluatedConfigFile else null,
|
||||
output = output,
|
||||
outputPath = destinationDirectory,
|
||||
outputFileName = outputFileName,
|
||||
configDirectory = configDirectory,
|
||||
bundleAnalyzerReportDir = if (report) reportDir else null,
|
||||
cssSupport = cssSupport,
|
||||
devServer = devServer,
|
||||
devtool = devtool,
|
||||
sourceMaps = sourceMaps,
|
||||
resolveFromModulesFirst = resolveFromModulesFirst,
|
||||
webpackMajorVersion = webpackMajorVersion
|
||||
)
|
||||
val config = createWebpackConfig()
|
||||
|
||||
if (platformType == KotlinPlatformType.wasm) {
|
||||
config.experiments += listOf(
|
||||
@@ -268,7 +274,7 @@ constructor(
|
||||
@Internal get() = true
|
||||
|
||||
override val requiredNpmDependencies: Set<RequiredKotlinJsDependency>
|
||||
@Internal get() = createRunner().config.getRequiredDependencies(versions)
|
||||
@Internal get() = createWebpackConfig(true).getRequiredDependencies(versions)
|
||||
|
||||
private val isContinuous = project.gradle.startParameter.isContinuous
|
||||
|
||||
|
||||
+4
-4
@@ -6,13 +6,11 @@
|
||||
@file:Suppress("PackageDirectoryMismatch") // Old package for compatibility
|
||||
package org.jetbrains.kotlin.gradle.plugin.mpp
|
||||
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.tasks.SourceSet
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.gradle.api.tasks.compile.JavaCompile
|
||||
import org.gradle.kotlin.dsl.named
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationOutput
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationWithResources
|
||||
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile
|
||||
|
||||
@@ -45,7 +43,9 @@ class KotlinWithJavaCompilation<KotlinOptionsType : KotlinCommonOptions>(
|
||||
fun source(javaSourceSet: SourceSet) {
|
||||
with(target.project) {
|
||||
afterEvaluate {
|
||||
(tasks.getByName(compileKotlinTaskName) as AbstractKotlinCompile<*>).source(javaSourceSet.java)
|
||||
tasks.named<AbstractKotlinCompile<*>>(compileKotlinTaskName).configure {
|
||||
it.setSource(javaSourceSet.java)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ internal fun addSourcesToKotlinNativeCompileTask(
|
||||
addAsCommonSources: Lazy<Boolean>
|
||||
) {
|
||||
project.tasks.withType(KotlinNativeCompile::class.java).matching { it.name == taskName }.configureEach { task ->
|
||||
task.source(sourceFiles)
|
||||
task.setSource(sourceFiles)
|
||||
task.commonSources.from(project.files(Callable { if (addAsCommonSources.value) sourceFiles() else emptyList() }))
|
||||
}
|
||||
|
||||
|
||||
-2
@@ -32,7 +32,6 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.apple.registerEmbedAndSignAppleFra
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.isMain
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KpmAwareTargetConfigurator
|
||||
import org.jetbrains.kotlin.gradle.targets.metadata.KotlinMetadataTargetConfigurator
|
||||
import org.jetbrains.kotlin.gradle.targets.metadata.isKotlinGranularMetadataEnabled
|
||||
import org.jetbrains.kotlin.gradle.targets.native.*
|
||||
import org.jetbrains.kotlin.gradle.targets.native.internal.commonizeCInteropTask
|
||||
@@ -63,7 +62,6 @@ open class KotlinNativeTargetConfigurator<T : KotlinNativeTarget> : AbstractKotl
|
||||
it.group = BasePlugin.BUILD_GROUP
|
||||
it.description = "Links ${binary.outputKind.description} '${binary.name}' for a target '${target.name}'."
|
||||
it.enabled = binary.konanTarget.enabledOnCurrentHost
|
||||
it.destinationDir = binary.outputDirectory
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -220,7 +220,7 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
|
||||
check(targets.size == 1) { "The project has more than one target for the requested platform: `${requestedPlatform.visibleName}`" }
|
||||
|
||||
val frameworkLinkTask = targets.single().binaries.getFramework(POD_FRAMEWORK_PREFIX, requestedBuildType).linkTaskProvider
|
||||
project.createSyncFrameworkTask(frameworkLinkTask.map { it.destinationDir }, frameworkLinkTask)
|
||||
project.createSyncFrameworkTask(frameworkLinkTask.flatMap { it.destinationDirectory.map { it.asFile }}, frameworkLinkTask)
|
||||
}
|
||||
|
||||
private fun createSyncTask(
|
||||
|
||||
+57
-48
@@ -15,11 +15,13 @@ import org.gradle.api.artifacts.component.ModuleComponentSelector
|
||||
import org.gradle.api.artifacts.result.DependencyResult
|
||||
import org.gradle.api.artifacts.result.ResolvedDependencyResult
|
||||
import org.gradle.api.file.ConfigurableFileCollection
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.file.FileTree
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.tasks.*
|
||||
import org.gradle.api.tasks.compile.AbstractCompile
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonToolArguments
|
||||
import org.jetbrains.kotlin.compilerRunner.*
|
||||
import org.jetbrains.kotlin.compilerRunner.KotlinNativeCInteropRunner.Companion.run
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
|
||||
@@ -126,7 +128,11 @@ private fun Collection<File>.filterKlibsPassedToCompiler(): List<File> = filter
|
||||
}
|
||||
|
||||
// endregion
|
||||
abstract class AbstractKotlinNativeCompile<T : KotlinCommonToolOptions, K : KotlinNativeCompilationData<*>> : AbstractCompile() {
|
||||
abstract class AbstractKotlinNativeCompile<
|
||||
T : KotlinCommonToolOptions,
|
||||
K : KotlinNativeCompilationData<*>,
|
||||
M : CommonToolArguments
|
||||
> : AbstractKotlinCompileTool<M>() {
|
||||
@get:Internal
|
||||
abstract val compilation: K
|
||||
|
||||
@@ -151,15 +157,6 @@ abstract class AbstractKotlinNativeCompile<T : KotlinCommonToolOptions, K : Kotl
|
||||
compilation.konanTarget
|
||||
}
|
||||
|
||||
// Inputs and outputs
|
||||
@IgnoreEmptyDirectories
|
||||
@InputFiles
|
||||
@SkipWhenEmpty
|
||||
@PathSensitive(PathSensitivity.RELATIVE)
|
||||
override fun getSource(): FileTree {
|
||||
return super.getSource()
|
||||
}
|
||||
|
||||
@get:Classpath
|
||||
val libraries: FileCollection by project.provider {
|
||||
// Avoid resolving these dependencies during task graph construction when we can't build the target:
|
||||
@@ -174,10 +171,8 @@ abstract class AbstractKotlinNativeCompile<T : KotlinCommonToolOptions, K : Kotl
|
||||
}
|
||||
|
||||
@Deprecated("For native tasks use 'libraries' instead", ReplaceWith("libraries"))
|
||||
override fun getClasspath(): FileCollection = libraries
|
||||
override fun setClasspath(configuration: FileCollection?) {
|
||||
throw UnsupportedOperationException("Setting classpath directly is unsupported.")
|
||||
}
|
||||
override val classpath: ConfigurableFileCollection
|
||||
get() = objects.fileCollection().from(libraries)
|
||||
|
||||
@get:Input
|
||||
val target: String by project.provider { compilation.konanTarget.name }
|
||||
@@ -212,22 +207,23 @@ abstract class AbstractKotlinNativeCompile<T : KotlinCommonToolOptions, K : Kotl
|
||||
internal val useEmbeddableCompilerJar: Boolean
|
||||
get() = project.nativeUseEmbeddableCompilerJar
|
||||
|
||||
@Internal
|
||||
open val outputFile: Provider<File> = project.provider {
|
||||
val prefix = outputKind.prefix(konanTarget)
|
||||
val suffix = outputKind.suffix(konanTarget)
|
||||
val filename = "$prefix${baseName}$suffix".let {
|
||||
when {
|
||||
outputKind == FRAMEWORK ->
|
||||
it.asValidFrameworkName()
|
||||
outputKind in listOf(STATIC, DYNAMIC) || outputKind == PROGRAM && konanTarget == KonanTarget.WASM32 ->
|
||||
it.replace('-', '_')
|
||||
else -> it
|
||||
@get:Internal
|
||||
open val outputFile: Provider<File>
|
||||
get() = destinationDirectory.map {
|
||||
val prefix = outputKind.prefix(konanTarget)
|
||||
val suffix = outputKind.suffix(konanTarget)
|
||||
val filename = "$prefix${baseName}$suffix".let {
|
||||
when {
|
||||
outputKind == FRAMEWORK ->
|
||||
it.asValidFrameworkName()
|
||||
outputKind in listOf(STATIC, DYNAMIC) || outputKind == PROGRAM && konanTarget == KonanTarget.WASM32 ->
|
||||
it.replace('-', '_')
|
||||
else -> it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
destinationDir.resolve(filename)
|
||||
}
|
||||
it.file(filename).asFile
|
||||
}
|
||||
|
||||
// endregion
|
||||
@Internal
|
||||
@@ -250,12 +246,12 @@ abstract class AbstractKotlinNativeCompile<T : KotlinCommonToolOptions, K : Kotl
|
||||
|
||||
// Used by IDE via reflection.
|
||||
@get:Internal
|
||||
val serializedCompilerArguments: List<String>
|
||||
override val serializedCompilerArguments: List<String>
|
||||
get() = buildCommonArgs()
|
||||
|
||||
// Used by IDE via reflection.
|
||||
@get:Internal
|
||||
val defaultSerializedCompilerArguments: List<String>
|
||||
override val defaultSerializedCompilerArguments: List<String>
|
||||
get() = buildCommonArgs(true)
|
||||
|
||||
private val languageSettingsBuilder by project.provider {
|
||||
@@ -301,17 +297,20 @@ abstract class AbstractKotlinNativeCompile<T : KotlinCommonToolOptions, K : Kotl
|
||||
}
|
||||
}
|
||||
|
||||
// Remove it once actual K2NativeCompilerArguments will be available without 'kotlin.native.enabled = true' flag
|
||||
class StubK2NativeCompilerArguments : CommonCompilerArguments()
|
||||
|
||||
/**
|
||||
* A task producing a klibrary from a compilation.
|
||||
*/
|
||||
@CacheableTask
|
||||
open class KotlinNativeCompile
|
||||
abstract class KotlinNativeCompile
|
||||
@Inject
|
||||
constructor(
|
||||
@Internal
|
||||
@Transient // can't be serialized for Gradle configuration cache
|
||||
final override val compilation: KotlinNativeCompilationData<*>
|
||||
) : AbstractKotlinNativeCompile<KotlinCommonOptions, KotlinNativeCompilationData<*>>(),
|
||||
) : AbstractKotlinNativeCompile<KotlinCommonOptions, KotlinNativeCompilationData<*>, StubK2NativeCompilerArguments>(),
|
||||
KotlinCompile<KotlinCommonOptions> {
|
||||
|
||||
@get:Input
|
||||
@@ -395,6 +394,14 @@ constructor(
|
||||
}
|
||||
// endregion.
|
||||
|
||||
override fun createCompilerArgs(): StubK2NativeCompilerArguments = StubK2NativeCompilerArguments()
|
||||
|
||||
override fun setupCompilerArgs(
|
||||
args: StubK2NativeCompilerArguments,
|
||||
defaultsOnly: Boolean,
|
||||
ignoreClasspathResolutionErrors: Boolean
|
||||
) = Unit
|
||||
|
||||
@TaskAction
|
||||
fun compile() {
|
||||
val output = outputFile.get()
|
||||
@@ -440,7 +447,7 @@ constructor(
|
||||
shortModuleName,
|
||||
friendModule,
|
||||
sharedCompilationData,
|
||||
source,
|
||||
sources.asFileTree,
|
||||
commonSourcesTree
|
||||
)
|
||||
|
||||
@@ -452,12 +459,12 @@ constructor(
|
||||
* A task producing a final binary from a compilation.
|
||||
*/
|
||||
@CacheableTask
|
||||
open class KotlinNativeLink
|
||||
abstract class KotlinNativeLink
|
||||
@Inject
|
||||
constructor(
|
||||
@Internal
|
||||
val binary: NativeBinary
|
||||
) : AbstractKotlinNativeCompile<KotlinCommonToolOptions, KotlinNativeCompilation>() {
|
||||
) : AbstractKotlinNativeCompile<KotlinCommonToolOptions, KotlinNativeCompilation, StubK2NativeCompilerArguments>() {
|
||||
@get:Internal
|
||||
final override val compilation: KotlinNativeCompilation
|
||||
get() = binary.compilation
|
||||
@@ -472,19 +479,13 @@ constructor(
|
||||
@Internal // Taken into account by getSources().
|
||||
val intermediateLibrary: Provider<File> = project.provider { compilation.compileKotlinTask.outputFile.get() }
|
||||
|
||||
@IgnoreEmptyDirectories
|
||||
@InputFiles
|
||||
@SkipWhenEmpty
|
||||
override fun getSource(): FileTree =
|
||||
objects.fileCollection().from(intermediateLibrary).asFileTree
|
||||
override val sources: ConfigurableFileCollection = objects
|
||||
.fileCollection()
|
||||
.from(intermediateLibrary)
|
||||
.apply { disallowChanges() }
|
||||
|
||||
@OutputDirectory
|
||||
override fun getDestinationDir(): File {
|
||||
return binary.outputDirectory
|
||||
}
|
||||
|
||||
override fun setDestinationDir(destinationDir: File) {
|
||||
binary.outputDirectory = destinationDir
|
||||
override val destinationDirectory: DirectoryProperty = objects.directoryProperty().apply {
|
||||
set(binary.outputDirectory)
|
||||
}
|
||||
|
||||
override val outputKind: CompilerOutputKind
|
||||
@@ -572,6 +573,14 @@ constructor(
|
||||
project.configurations.getByName(compilation.apiConfigurationName).files.filterKlibsPassedToCompiler()
|
||||
}
|
||||
|
||||
override fun createCompilerArgs(): StubK2NativeCompilerArguments = StubK2NativeCompilerArguments()
|
||||
|
||||
override fun setupCompilerArgs(
|
||||
args: StubK2NativeCompilerArguments,
|
||||
defaultsOnly: Boolean,
|
||||
ignoreClasspathResolutionErrors: Boolean
|
||||
) = Unit
|
||||
|
||||
private fun validatedExportedLibraries() {
|
||||
val exportConfiguration = exportLibraries as? Configuration ?: return
|
||||
val apiFiles = apiFilesProvider.get()
|
||||
|
||||
+2
-2
@@ -102,7 +102,7 @@ abstract class KotlinCompileCommon @Inject constructor(
|
||||
K2MetadataCompilerArguments()
|
||||
|
||||
override fun getSourceRoots(): SourceRoots =
|
||||
SourceRoots.KotlinOnly.create(getSource(), sourceFilesExtensions.get())
|
||||
SourceRoots.KotlinOnly.create(sources, sourceFilesExtensions.get())
|
||||
|
||||
override fun setupCompilerArgs(args: K2MetadataCompilerArguments, defaultsOnly: Boolean, ignoreClasspathResolutionErrors: Boolean) {
|
||||
args.apply { fillDefaultValues() }
|
||||
@@ -120,7 +120,7 @@ abstract class KotlinCompileCommon @Inject constructor(
|
||||
|
||||
with(args) {
|
||||
classpath = classpathList.joinToString(File.pathSeparator)
|
||||
destination = destinationDir.canonicalPath
|
||||
destination = destinationDirectory.get().asFile.canonicalPath
|
||||
|
||||
friendPaths = this@KotlinCompileCommon.friendPaths.files.map { it.absolutePath }.toTypedArray()
|
||||
refinesPaths = refinesMetadataPaths.map { it.absolutePath }.toTypedArray()
|
||||
|
||||
+4
-13
@@ -16,14 +16,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.tasks
|
||||
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.file.FileTree
|
||||
import org.gradle.api.tasks.CacheableTask
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.work.ChangeType
|
||||
import org.gradle.work.Incremental
|
||||
import org.gradle.work.InputChanges
|
||||
import org.jetbrains.kotlin.cli.common.arguments.DevModeOverwritingStrategies
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSDceArguments
|
||||
@@ -73,11 +70,6 @@ abstract class KotlinJsDce : AbstractKotlinCompileTool<K2JSDceArguments>(), Kotl
|
||||
@Input
|
||||
var jvmArgs = mutableListOf<String>()
|
||||
|
||||
@Incremental
|
||||
override fun getClasspath(): FileCollection {
|
||||
return super.getClasspath()
|
||||
}
|
||||
|
||||
private val buildDir by lazy {
|
||||
project.buildDir
|
||||
}
|
||||
@@ -101,13 +93,12 @@ abstract class KotlinJsDce : AbstractKotlinCompileTool<K2JSDceArguments>(), Kotl
|
||||
.filter { it.changeType == ChangeType.MODIFIED || it.changeType == ChangeType.ADDED }
|
||||
.map { it.file }
|
||||
} else {
|
||||
classpath
|
||||
classpath.asFileTree.files
|
||||
}
|
||||
val inputFiles = (listOf(source) + classpathFiles
|
||||
// TODO: use PatternFilterable here!
|
||||
val inputFiles = sources.asFileTree.files.plus(classpathFiles)
|
||||
.filter { !kotlinFilesOnly || isDceCandidate(it) }
|
||||
.map { objects.fileCollection().from(it).asFileTree })
|
||||
.reduce(FileTree::plus)
|
||||
.files.map { it.path }
|
||||
.map { it.path }
|
||||
|
||||
val outputDirArgs = arrayOf("-output-dir", destinationDirectory.get().asFile.path)
|
||||
|
||||
|
||||
+2
-2
@@ -30,7 +30,7 @@ internal sealed class SourceRoots(val kotlinSourceFiles: FileCollection) {
|
||||
|
||||
companion object {
|
||||
fun create(
|
||||
taskSource: FileTree,
|
||||
taskSource: FileCollection,
|
||||
sourceRoots: FilteringSourceRootsContainer,
|
||||
sourceFilesExtensions: List<String>
|
||||
): ForJvm {
|
||||
@@ -58,7 +58,7 @@ internal sealed class SourceRoots(val kotlinSourceFiles: FileCollection) {
|
||||
class KotlinOnly(kotlinSourceFiles: FileCollection) : SourceRoots(kotlinSourceFiles) {
|
||||
companion object {
|
||||
fun create(
|
||||
taskSource: FileTree,
|
||||
taskSource: FileCollection,
|
||||
sourceFilesExtensions: List<String>
|
||||
) = KotlinOnly(
|
||||
taskSource.filter { it.isKotlinFile(sourceFilesExtensions) }
|
||||
|
||||
+40
-27
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.tasks
|
||||
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
@@ -13,7 +14,6 @@ import org.gradle.api.file.*
|
||||
import org.gradle.api.invocation.Gradle
|
||||
import org.gradle.api.logging.Logger
|
||||
import org.gradle.api.model.ObjectFactory
|
||||
import org.gradle.api.model.ReplacedBy
|
||||
import org.gradle.api.provider.ListProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.provider.Provider
|
||||
@@ -22,6 +22,7 @@ import org.gradle.api.services.BuildServiceParameters
|
||||
import org.gradle.api.tasks.*
|
||||
import org.gradle.api.tasks.compile.AbstractCompile
|
||||
import org.gradle.api.tasks.compile.JavaCompile
|
||||
import org.gradle.api.tasks.util.PatternFilterable
|
||||
import org.gradle.work.ChangeType
|
||||
import org.gradle.work.Incremental
|
||||
import org.gradle.work.InputChanges
|
||||
@@ -77,26 +78,40 @@ const val USING_JS_INCREMENTAL_COMPILATION_MESSAGE = "Using Kotlin/JS incrementa
|
||||
const val USING_JS_IR_BACKEND_MESSAGE = "Using Kotlin/JS IR backend"
|
||||
|
||||
abstract class AbstractKotlinCompileTool<T : CommonToolArguments>
|
||||
: AbstractCompile(),
|
||||
: DefaultTask(),
|
||||
//PatternFilterable,
|
||||
CompilerArgumentAwareWithInput<T>,
|
||||
TaskWithLocalState {
|
||||
|
||||
@ReplacedBy("stableSources")
|
||||
override fun getSource() = super.getSource()
|
||||
|
||||
@get:InputFiles
|
||||
@get:SkipWhenEmpty
|
||||
@get:IgnoreEmptyDirectories
|
||||
@get:PathSensitive(PathSensitivity.RELATIVE)
|
||||
internal val stableSources: FileCollection = project.files(
|
||||
{ source }
|
||||
)
|
||||
abstract val sources: ConfigurableFileCollection
|
||||
|
||||
@Incremental
|
||||
override fun getClasspath(): FileCollection {
|
||||
return super.getClasspath()
|
||||
/**
|
||||
* Sets the source for this task.
|
||||
* The given source object is evaluated as per [org.gradle.api.Project.files].
|
||||
*/
|
||||
open fun setSource(source: Any) {
|
||||
sources.from(source)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the source for this task.
|
||||
* The given source object is evaluated as per [org.gradle.api.Project.files].
|
||||
*/
|
||||
open fun setSource(vararg source: Any) {
|
||||
sources.from(source)
|
||||
}
|
||||
|
||||
@get:Classpath
|
||||
@get:Incremental
|
||||
abstract val classpath: ConfigurableFileCollection
|
||||
|
||||
@get:OutputDirectory
|
||||
abstract val destinationDirectory: DirectoryProperty
|
||||
|
||||
@get:Internal
|
||||
override val metrics: Property<BuildMetricsReporter> = project.objects
|
||||
.property(BuildMetricsReporterImpl())
|
||||
@@ -403,7 +418,7 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments> : AbstractKotl
|
||||
@get:Internal
|
||||
protected open val incrementalProps: List<FileCollection>
|
||||
get() = listOfNotNull(
|
||||
stableSources,
|
||||
sources,
|
||||
classpath,
|
||||
commonSourceSet
|
||||
)
|
||||
@@ -508,7 +523,7 @@ class KotlinJvmCompilerArgumentsProvider
|
||||
val moduleName: String = taskProvider.moduleName.get()
|
||||
val friendPaths: FileCollection = taskProvider.friendPaths
|
||||
val compileClasspath: Iterable<File> = taskProvider.classpath
|
||||
val destinationDir: File = taskProvider.destinationDir
|
||||
val destinationDir: File = taskProvider.destinationDirectory.get().asFile
|
||||
internal val kotlinOptions: List<KotlinJvmOptionsImpl> = listOfNotNull(
|
||||
taskProvider.parentKotlinOptionsImpl.orNull as? KotlinJvmOptionsImpl,
|
||||
taskProvider.kotlinOptions as KotlinJvmOptionsImpl
|
||||
@@ -628,7 +643,7 @@ abstract class KotlinCompile @Inject constructor(
|
||||
|
||||
private val jvmSourceRoots by project.provider {
|
||||
// serialize in the task state for configuration caching; avoid building anew in task execution, as it may access the project model
|
||||
SourceRoots.ForJvm.create(source, sourceRootsContainer, sourceFilesExtensions.get())
|
||||
SourceRoots.ForJvm.create(sources, sourceRootsContainer, sourceFilesExtensions.get())
|
||||
}
|
||||
|
||||
/** A package prefix that is used for locating Java sources in a directory structure with non-full-depth packages.
|
||||
@@ -646,10 +661,8 @@ abstract class KotlinCompile @Inject constructor(
|
||||
logger.kotlinDebug { "Set $this.usePreciseJavaTracking=$value" }
|
||||
}
|
||||
|
||||
@Internal // To support compile avoidance (ClasspathSnapshotProperties.classpathSnapshot will be used as input instead)
|
||||
override fun getClasspath(): FileCollection {
|
||||
return super.getClasspath()
|
||||
}
|
||||
@get:Internal // To support compile avoidance (ClasspathSnapshotProperties.classpathSnapshot will be used as input instead)
|
||||
override abstract val classpath: ConfigurableFileCollection
|
||||
|
||||
@get:Input
|
||||
abstract val useKotlinAbiSnapshot: Property<Boolean>
|
||||
@@ -678,7 +691,7 @@ abstract class KotlinCompile @Inject constructor(
|
||||
}
|
||||
|
||||
override val incrementalProps: List<FileCollection>
|
||||
get() = listOf(stableSources, commonSourceSet, classpathSnapshotProperties.classpath, classpathSnapshotProperties.classpathSnapshot)
|
||||
get() = listOf(sources, commonSourceSet, classpathSnapshotProperties.classpath, classpathSnapshotProperties.classpathSnapshot)
|
||||
|
||||
// Exclude classpathSnapshotDir from TaskOutputsBackup (see TaskOutputsBackup's kdoc for more info). */
|
||||
override val taskOutputsBackupExcludes: List<File>
|
||||
@@ -859,15 +872,15 @@ abstract class KotlinCompile @Inject constructor(
|
||||
}
|
||||
|
||||
// override setSource to track source directory sets and files (for generated android folders)
|
||||
override fun setSource(sources: Any) {
|
||||
sourceRootsContainer.set(sources)
|
||||
super.setSource(sources)
|
||||
override fun setSource(source: Any) {
|
||||
sourceRootsContainer.set(source)
|
||||
super.setSource(source)
|
||||
}
|
||||
|
||||
// override source to track source directory sets and files (for generated android folders)
|
||||
override fun source(vararg sources: Any): SourceTask {
|
||||
sourceRootsContainer.add(*sources)
|
||||
return super.source(*sources)
|
||||
override fun setSource(vararg source: Any) {
|
||||
sourceRootsContainer.add(*source)
|
||||
super.setSource(*source)
|
||||
}
|
||||
|
||||
private fun getClasspathChanges(inputChanges: InputChanges): ClasspathChanges = when {
|
||||
@@ -1018,7 +1031,7 @@ abstract class Kotlin2JsCompile @Inject constructor(
|
||||
(kotlinOptions as KotlinJsOptionsImpl).updateArguments(args)
|
||||
}
|
||||
|
||||
override fun getSourceRoots() = SourceRoots.KotlinOnly.create(getSource(), sourceFilesExtensions.get())
|
||||
override fun getSourceRoots() = SourceRoots.KotlinOnly.create(sources, sourceFilesExtensions.get())
|
||||
|
||||
@get:InputFiles
|
||||
@get:IgnoreEmptyDirectories
|
||||
@@ -1115,7 +1128,7 @@ abstract class Kotlin2JsCompile @Inject constructor(
|
||||
sourceRoots as SourceRoots.KotlinOnly
|
||||
|
||||
logger.debug("Calling compiler")
|
||||
destinationDir.mkdirs()
|
||||
//destinationDir.mkdirs()
|
||||
|
||||
if (kotlinOptions.isIrBackendEnabled()) {
|
||||
logger.info(USING_JS_IR_BACKEND_MESSAGE)
|
||||
|
||||
Reference in New Issue
Block a user