Update KotlinCompileCommon task to use compiler options

^KT-27301 In Progress
This commit is contained in:
Yahor Berdnikau
2022-09-12 12:23:06 +02:00
parent ad62262f51
commit 5121db6e2c
3 changed files with 27 additions and 7 deletions
@@ -335,7 +335,12 @@ internal class KotlinCommonSourceSetProcessor(
override fun doRegisterTask(project: Project, taskName: String): TaskProvider<out KotlinCompileCommon> {
val configAction = KotlinCompileCommonConfig(kotlinCompilation)
applyStandardTaskConfiguration(configAction)
return tasksProvider.registerKotlinCommonTask(project, taskName, kotlinCompilation.kotlinOptions, configAction)
return tasksProvider.registerKotlinCommonTask(
project,
taskName,
kotlinCompilation.compilerOptions.options as CompilerMultiplatformCommonOptions,
configAction
)
}
}
@@ -33,17 +33,29 @@ import javax.inject.Inject
@CacheableTask
abstract class KotlinCompileCommon @Inject constructor(
override val kotlinOptions: KotlinMultiplatformCommonOptions,
override val compilerOptions: CompilerMultiplatformCommonOptions,
workerExecutor: WorkerExecutor,
objectFactory: ObjectFactory
) : AbstractKotlinCompile<K2MetadataCompilerArguments>(objectFactory, workerExecutor),
KotlinCompilationTask<CompilerMultiplatformCommonOptions>,
KotlinCommonCompile {
init {
compilerOptions.verbose.convention(logger.isDebugEnabled)
}
@Suppress("DEPRECATION")
@Deprecated("Replaced by compilerOptions input", replaceWith = ReplaceWith("compilerOptions"))
override val kotlinOptions: KotlinMultiplatformCommonOptions = object : KotlinMultiplatformCommonOptions {
override val options: CompilerMultiplatformCommonOptions
get() = compilerOptions
}
override fun createCompilerArgs(): K2MetadataCompilerArguments =
K2MetadataCompilerArguments()
override fun setupCompilerArgs(args: K2MetadataCompilerArguments, defaultsOnly: Boolean, ignoreClasspathResolutionErrors: Boolean) {
args.apply { fillDefaultValues() }
(compilerOptions as CompilerMultiplatformCommonOptionsDefault).fillDefaultValues(args)
super.setupCompilerArgs(args, defaultsOnly = defaultsOnly, ignoreClasspathResolutionErrors = ignoreClasspathResolutionErrors)
args.moduleName = this@KotlinCompileCommon.moduleName.get()
@@ -64,7 +76,7 @@ abstract class KotlinCompileCommon @Inject constructor(
refinesPaths = refinesMetadataPaths.map { it.absolutePath }.toTypedArray()
}
(kotlinOptions as KotlinMultiplatformCommonOptionsImpl).updateArguments(args)
(compilerOptions as CompilerMultiplatformCommonOptionsDefault).fillCompilerArguments(args)
}
@get:PathSensitive(PathSensitivity.RELATIVE)
@@ -24,7 +24,7 @@ import org.gradle.api.tasks.TaskContainer
import org.gradle.api.tasks.TaskProvider
import org.jetbrains.kotlin.gradle.dsl.CompilerJsOptions
import org.jetbrains.kotlin.gradle.dsl.CompilerJvmOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
import org.jetbrains.kotlin.gradle.dsl.CompilerMultiplatformCommonOptions
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink
import org.jetbrains.kotlin.gradle.tasks.configuration.*
@@ -134,12 +134,15 @@ internal open class KotlinTasksProvider {
}
fun registerKotlinCommonTask(
project: Project, taskName: String, kotlinOptions: KotlinCommonOptions, configuration: KotlinCompileCommonConfig
project: Project,
taskName: String,
compilerOptions: CompilerMultiplatformCommonOptions,
configuration: KotlinCompileCommonConfig
): TaskProvider<out KotlinCompileCommon> {
return project.registerTask(
taskName,
KotlinCompileCommon::class.java,
constructorArgs = listOf(kotlinOptions)
constructorArgs = listOf(compilerOptions)
).also {
configuration.execute(it)
}