Support compiler plugins in native part of the mpp plugin
This commit is contained in:
committed by
Ilya Matveev
parent
41367b0285
commit
14e4f219da
+13
-1
@@ -28,6 +28,7 @@ import org.gradle.internal.cleanup.BuildOutputCleanupRegistry
|
||||
import org.gradle.language.base.plugins.LifecycleBasePlugin
|
||||
import org.gradle.language.jvm.tasks.ProcessResources
|
||||
import org.gradle.nativeplatform.test.tasks.RunTestExecutable
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.getSourceSetHierarchy
|
||||
@@ -374,7 +375,8 @@ open class KotlinTargetConfigurator<KotlinCompilationType: KotlinCompilation>(
|
||||
|
||||
|
||||
open class KotlinNativeTargetConfigurator(
|
||||
buildOutputCleanupRegistry: BuildOutputCleanupRegistry
|
||||
buildOutputCleanupRegistry: BuildOutputCleanupRegistry,
|
||||
private val kotlinPluginVersion: String
|
||||
) : AbstractKotlinTargetConfigurator<KotlinNativeTarget>(
|
||||
buildOutputCleanupRegistry,
|
||||
createDefaultSourceSets = true,
|
||||
@@ -438,6 +440,13 @@ open class KotlinNativeTargetConfigurator(
|
||||
return buildDir.resolve("classes/kotlin/$targetSubDirectory${compilation.name}")
|
||||
}
|
||||
|
||||
private fun KotlinNativeCompile.addCompilerPlugins() {
|
||||
SubpluginEnvironment
|
||||
.loadSubplugins(project, kotlinPluginVersion)
|
||||
.addSubpluginOptions<CommonCompilerArguments>(project, this, compilerPluginOptions)
|
||||
compilerPluginClasspath = project.configurations.getByName(PLUGIN_CLASSPATH_CONFIGURATION_NAME)
|
||||
}
|
||||
|
||||
private fun KotlinNativeCompile.registerOutputFiles(outputDirectory: File) {
|
||||
val konanTarget = compilation.target.konanTarget
|
||||
|
||||
@@ -504,6 +513,8 @@ open class KotlinNativeTargetConfigurator(
|
||||
debuggable = buildType.debuggable
|
||||
|
||||
registerOutputFiles(binaryOutputDirectory(buildType, kind, compilation))
|
||||
addCompilerPlugins()
|
||||
|
||||
dependsOnCompilerDownloading()
|
||||
linkAll.dependsOn(this)
|
||||
}
|
||||
@@ -555,6 +566,7 @@ open class KotlinNativeTargetConfigurator(
|
||||
enabled = compilation.target.konanTarget.enabledOnCurrentHost
|
||||
|
||||
registerOutputFiles(klibOutputDirectory(compilation))
|
||||
addCompilerPlugins()
|
||||
dependsOnCompilerDownloading()
|
||||
compilation.output.tryAddClassesDir {
|
||||
project.files(this.outputFile).builtBy(this)
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ class KotlinMultiplatformPlugin(
|
||||
add(KotlinAndroidTargetPreset(project, kotlinPluginVersion))
|
||||
add(KotlinJvmWithJavaTargetPreset(project, kotlinPluginVersion))
|
||||
HostManager().targets.forEach { _, target ->
|
||||
add(KotlinNativeTargetPreset(target.presetName, project, target, buildOutputCleanupRegistry))
|
||||
add(KotlinNativeTargetPreset(target.presetName, project, target, buildOutputCleanupRegistry, kotlinPluginVersion))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -239,7 +239,8 @@ class KotlinNativeTargetPreset(
|
||||
private val name: String,
|
||||
val project: Project,
|
||||
val konanTarget: KonanTarget,
|
||||
private val buildOutputCleanupRegistry: BuildOutputCleanupRegistry
|
||||
private val buildOutputCleanupRegistry: BuildOutputCleanupRegistry,
|
||||
private val kotlinPluginVersion: String
|
||||
) : KotlinTargetPreset<KotlinNativeTarget> {
|
||||
|
||||
override fun getName(): String = name
|
||||
@@ -273,7 +274,7 @@ class KotlinNativeTargetPreset(
|
||||
compilations = project.container(compilationFactory.itemClass, compilationFactory)
|
||||
}
|
||||
|
||||
KotlinNativeTargetConfigurator(buildOutputCleanupRegistry).configureTarget(result)
|
||||
KotlinNativeTargetConfigurator(buildOutputCleanupRegistry, kotlinPluginVersion).configureTarget(result)
|
||||
|
||||
// Allow IDE to resolve the libraries provided by the compiler by adding them into dependencies.
|
||||
result.compilations.all {
|
||||
|
||||
+33
-3
@@ -7,6 +7,7 @@ import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.file.FileTree
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.*
|
||||
import org.gradle.api.tasks.compile.AbstractCompile
|
||||
import org.jetbrains.kotlin.compilerRunner.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation
|
||||
import org.jetbrains.kotlin.konan.KonanVersion
|
||||
@@ -19,10 +20,19 @@ import java.io.File
|
||||
|
||||
// TODO: It's just temporary tasks used while KN isn't integrated with Big Kotlin compilation infrastructure.
|
||||
|
||||
open class KotlinNativeCompile : DefaultTask() {
|
||||
open class KotlinNativeCompile : AbstractCompile() {
|
||||
|
||||
init {
|
||||
super.dependsOn(KonanCompilerDownloadTask.KONAN_DOWNLOAD_TASK_NAME)
|
||||
dependsOn(KonanCompilerDownloadTask.KONAN_DOWNLOAD_TASK_NAME)
|
||||
|
||||
@Suppress("LeakingThis")
|
||||
setDestinationDir(project.provider {
|
||||
val output = outputFile.get()
|
||||
if (output.isDirectory) output else output.parentFile
|
||||
})
|
||||
|
||||
sourceCompatibility = "1.6"
|
||||
targetCompatibility = "1.6"
|
||||
}
|
||||
|
||||
@Internal
|
||||
@@ -34,6 +44,8 @@ open class KotlinNativeCompile : DefaultTask() {
|
||||
|
||||
// Inputs and outputs
|
||||
|
||||
override fun getSource(): FileTree = sources.asFileTree
|
||||
|
||||
val sources: FileCollection
|
||||
@InputFiles
|
||||
@SkipWhenEmpty
|
||||
@@ -46,6 +58,11 @@ open class KotlinNativeCompile : DefaultTask() {
|
||||
// It's already taken into account in libraries
|
||||
@Internal get() = compilation.friendCompilation?.output
|
||||
|
||||
override fun getClasspath(): FileCollection = libraries
|
||||
override fun setClasspath(configuration: FileCollection?) {
|
||||
throw UnsupportedOperationException("Setting class path directly is unsupported.")
|
||||
}
|
||||
|
||||
@Input
|
||||
var optimized = false
|
||||
@Input
|
||||
@@ -68,6 +85,8 @@ open class KotlinNativeCompile : DefaultTask() {
|
||||
val outputFile: Property<File> = project.objects.property(File::class.java)
|
||||
|
||||
// endregion
|
||||
val compilerPluginOptions = CompilerPluginOptions()
|
||||
var compilerPluginClasspath: FileCollection? = null
|
||||
|
||||
// region Useful extensions
|
||||
internal fun MutableList<String>.addArg(parameter: String, value: String) {
|
||||
@@ -116,7 +135,7 @@ open class KotlinNativeCompile : DefaultTask() {
|
||||
get() = toPath().startsWith(project.file(project.konanHome).toPath())
|
||||
|
||||
@TaskAction
|
||||
fun compile() {
|
||||
override fun compile() {
|
||||
val output = outputFile.get()
|
||||
output.parentFile.mkdirs()
|
||||
|
||||
@@ -132,6 +151,17 @@ open class KotlinNativeCompile : DefaultTask() {
|
||||
|
||||
add("-Xmulti-platform")
|
||||
|
||||
println("Trying to obtain a plugin classpath")
|
||||
compilerPluginClasspath?.let { pluginClasspath ->
|
||||
println(pluginClasspath)
|
||||
pluginClasspath.map { it.canonicalPath }.sorted().forEach { path ->
|
||||
add("-Xplugin=$path")
|
||||
}
|
||||
compilerPluginOptions.arguments.forEach {
|
||||
add("-P$it")
|
||||
}
|
||||
}
|
||||
|
||||
addAll(additionalCompilerOptions)
|
||||
|
||||
libraries.files.filter {
|
||||
|
||||
Reference in New Issue
Block a user