[Gradle] Extract configuration of KotlinJsIrLink to a class
Migrate KotlinJsIrLink to properties create Configurator class to configure the task properties.
This commit is contained in:
committed by
teamcityserver
parent
5eed9a4e6e
commit
ad9f6e63b6
+23
-31
@@ -5,28 +5,41 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.file.ConfigurableFileCollection
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.file.FileTree
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.model.ObjectFactory
|
||||
import org.gradle.api.tasks.*
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsOptionsImpl
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinCompilationData
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBinaryMode
|
||||
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.newFileProperty
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
|
||||
@CacheableTask
|
||||
open class KotlinJsIrLink @Inject constructor(
|
||||
abstract class KotlinJsIrLink @Inject constructor(
|
||||
objectFactory: ObjectFactory
|
||||
): Kotlin2JsCompile(objectFactory) {
|
||||
|
||||
class Configurator(compilation: KotlinCompilationData<*>): Kotlin2JsCompile.Configurator<KotlinJsIrLink>(compilation) {
|
||||
|
||||
override fun configure(task: KotlinJsIrLink) {
|
||||
super.configure(task)
|
||||
|
||||
task.entryModule.fileProvider(
|
||||
(compilation as KotlinJsIrCompilation).output.classesDirs.elements.map { it.single().asFile }
|
||||
).disallowChanges()
|
||||
task.kotlinOptionsProperty.value(KotlinJsOptionsImpl()).disallowChanges()
|
||||
task.destinationDirectory.fileProvider(task.outputFile.map { it.parentFile }).disallowChanges()
|
||||
}
|
||||
}
|
||||
|
||||
// Link tasks are not affected by compiler plugin
|
||||
override val pluginClasspath: FileCollection = project.objects.fileCollection()
|
||||
override val pluginClasspath: ConfigurableFileCollection = project.objects.fileCollection()
|
||||
|
||||
@Input
|
||||
lateinit var mode: KotlinJsBinaryMode
|
||||
@@ -35,34 +48,13 @@ open class KotlinJsIrLink @Inject constructor(
|
||||
@Internal
|
||||
override fun getSource(): FileTree = super.getSource()
|
||||
|
||||
override val kotlinOptions: KotlinJsOptions = KotlinJsOptionsImpl()
|
||||
|
||||
@get:SkipWhenEmpty
|
||||
@get:InputDirectory
|
||||
@get:PathSensitive(PathSensitivity.RELATIVE)
|
||||
internal val entryModule: File by lazy {
|
||||
File(
|
||||
(taskData.compilation as KotlinJsIrCompilation)
|
||||
.output
|
||||
.classesDirs
|
||||
.asPath
|
||||
)
|
||||
}
|
||||
internal abstract val entryModule: DirectoryProperty
|
||||
|
||||
override fun skipCondition(): Boolean =
|
||||
!entryModule.exists()
|
||||
|
||||
override fun getDestinationDir(): File {
|
||||
return if (kotlinOptions.outputFile == null) {
|
||||
super.getDestinationDir()
|
||||
} else {
|
||||
outputFile.parentFile
|
||||
}
|
||||
}
|
||||
|
||||
@OutputFile
|
||||
val outputFileProperty: RegularFileProperty = project.newFileProperty {
|
||||
outputFile
|
||||
override fun skipCondition(): Boolean {
|
||||
return !entryModule.get().asFile.exists()
|
||||
}
|
||||
|
||||
override fun setupCompilerArgs(args: K2JSCompilerArguments, defaultsOnly: Boolean, ignoreClasspathResolutionErrors: Boolean) {
|
||||
@@ -80,6 +72,6 @@ open class KotlinJsIrLink @Inject constructor(
|
||||
private fun KotlinJsOptions.configureOptions(vararg additionalCompilerArgs: String) {
|
||||
freeCompilerArgs += additionalCompilerArgs.toList() +
|
||||
PRODUCE_JS +
|
||||
"$ENTRY_IR_MODULE=${entryModule.canonicalPath}"
|
||||
"$ENTRY_IR_MODULE=${entryModule.get().asFile.canonicalPath}"
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ import java.io.File
|
||||
import javax.inject.Inject
|
||||
|
||||
@CacheableTask
|
||||
internal open class KotlinJsIrLinkWithWorkers
|
||||
internal abstract class KotlinJsIrLinkWithWorkers
|
||||
@Inject
|
||||
constructor(
|
||||
objectFactory: ObjectFactory,
|
||||
|
||||
Reference in New Issue
Block a user