[Gradle] Support Native embeddable compiler jar in subplugins
Apply generic (backend-agnostic) compiler plugin artifact instead of Native-specific one when Native embeddable compiler jar is used (with `kotlin.native.useEmbeddableCompilerJar=true` project property).
This commit is contained in:
committed by
Space
parent
0b4dfd58fc
commit
71af22dba0
+8
@@ -123,6 +123,14 @@ interface KotlinCompilerPluginSupportPlugin : Plugin<Project> {
|
||||
|
||||
fun getCompilerPluginId(): String
|
||||
fun getPluginArtifact(): SubpluginArtifact
|
||||
|
||||
/**
|
||||
* Kotlin/Native-specific plugin artifact.
|
||||
*
|
||||
* If Gradle is configured to use Kotlin/Native embeddable compiler jar
|
||||
* (with `kotlin.native.useEmbeddableCompilerJar=true` project property),
|
||||
* then [getPluginArtifact] is used instead.
|
||||
*/
|
||||
fun getPluginArtifactForNative(): SubpluginArtifact? = null
|
||||
}
|
||||
|
||||
|
||||
+26
@@ -136,6 +136,32 @@ internal class CompilationSpecificPluginPath {
|
||||
assertEquals(listOf("native"), project.subplugins("linuxX64"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `native should use regular artifact when embeddable compiler jar is used`() {
|
||||
// Given plugin but with native-specific artifact
|
||||
class NativeSpecificPlugin : FakeSubPlugin("common1", "native", { true })
|
||||
|
||||
// And plugin without native artifact but applicable on all platforms
|
||||
class RegularPluginWithoutNativeArtifact : FakeSubPlugin("common2", null, { true })
|
||||
|
||||
// When applying these plugins
|
||||
val project = buildProjectWithMPP {
|
||||
plugins.apply(NativeSpecificPlugin::class.java)
|
||||
plugins.apply(RegularPluginWithoutNativeArtifact::class.java)
|
||||
|
||||
// With kotlin.native.useEmbeddableCompilerJar=true
|
||||
extensions.getByType(ExtraPropertiesExtension::class.java).set("kotlin.native.useEmbeddableCompilerJar", "true")
|
||||
|
||||
kotlin {
|
||||
linuxX64()
|
||||
}
|
||||
}
|
||||
project.evaluate()
|
||||
|
||||
// Expect native target have both regular artifacts
|
||||
assertEquals(listOf("common1", "common2"), project.subplugins("linuxX64"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `native plugin configuration should not be transitive`() {
|
||||
val project = buildProjectWithMPP {
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ class SubpluginEnvironment(
|
||||
project.logger.kotlinDebug { "Loading subplugin $pluginId" }
|
||||
|
||||
|
||||
if (kotlinCompilation is AbstractKotlinNativeCompilation) {
|
||||
if (kotlinCompilation is AbstractKotlinNativeCompilation && !kotlinCompilation.useGenericPluginArtifact) {
|
||||
subplugin.getPluginArtifactForNative()?.let { artifact ->
|
||||
project.addMavenDependency(kotlinCompilation.pluginConfigurationName, artifact)
|
||||
}
|
||||
|
||||
+3
@@ -72,6 +72,9 @@ abstract class AbstractKotlinNativeCompilation(
|
||||
addSourcesToKotlinNativeCompileTask(project, compileKotlinTaskName, { sourceSet.kotlin }, addAsCommonSources)
|
||||
}
|
||||
|
||||
internal val useGenericPluginArtifact: Boolean
|
||||
get() = project.nativeUseEmbeddableCompilerJar
|
||||
|
||||
// Endorsed library controller.
|
||||
override var enableEndorsedLibs: Boolean = false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user