mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-03-10 08:31:29 +00:00
[kotlin gradle plugin] enable to work with embedded k/n compiler.
This commit is contained in:
@@ -246,6 +246,7 @@ task shadowJar(type: ShadowJar) {
|
||||
task distCompiler(type: Copy) {
|
||||
dependsOn ":kotlin-native:dependencies:update"
|
||||
dependsOn ':kotlin-native:shadowJar'
|
||||
dependsOn ":kotlin-native-compiler-embeddable:kotlin-native-compiler-embeddable"
|
||||
|
||||
destinationDir distDir
|
||||
|
||||
@@ -257,6 +258,10 @@ task distCompiler(type: Copy) {
|
||||
into('konan/lib')
|
||||
}
|
||||
|
||||
from(project(":kotlin-native-compiler-embeddable").file("build/libs")) {
|
||||
into("konan/lib")
|
||||
}
|
||||
|
||||
from(project(':kotlin-native:Interop').file('Indexer/build/nativelibs')) {
|
||||
into('konan/nativelib')
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ object KonanHomeProvider {
|
||||
val jarPath = PathUtil.getResourcePathForClass(this::class.java)
|
||||
|
||||
// Check that the path obtained really points to the distribution.
|
||||
val expectedRelativeJarPath = Paths.get("konan/lib/kotlin-native.jar")
|
||||
check(jarPath.toPath().endsWith(expectedRelativeJarPath)) {
|
||||
check(jarPath.toPath().endsWith(Paths.get("konan/lib/kotlin-native.jar")) ||
|
||||
jarPath.toPath().endsWith(Paths.get("konan/lib/kotlin-native-compiler-embeddable.jar"))) {
|
||||
val classesPath = if (jarPath.extension == "jar") jarPath else jarPath.parentFile
|
||||
"""
|
||||
Cannot determine a compiler distribution directory.
|
||||
|
||||
@@ -124,6 +124,7 @@ interface KotlinCompilerPluginSupportPlugin : Plugin<Project> {
|
||||
fun getCompilerPluginId(): String
|
||||
fun getPluginArtifact(): SubpluginArtifact
|
||||
fun getPluginArtifactForNative(): SubpluginArtifact? = null
|
||||
fun getPluginArtifactForNative(project: Project): SubpluginArtifact? = getPluginArtifactForNative()
|
||||
}
|
||||
|
||||
open class SubpluginArtifact(val groupId: String, val artifactId: String, val version: String? = null)
|
||||
|
||||
@@ -116,6 +116,7 @@ internal abstract class KotlinToolRunner(
|
||||
project.logger.info(
|
||||
"""|Run in-process tool "$displayName"
|
||||
|Entry point method = $mainClass.$daemonEntryPoint
|
||||
|Classpath = ${classpath.joinToString(File.pathSeparator) { it.absolutePath }}
|
||||
|Arguments = ${args.toPrettyString()}
|
||||
|Transformed arguments = ${if (transformedArgs == args) "same as arguments" else transformedArgs.toPrettyString()}
|
||||
""".trimMargin()
|
||||
|
||||
@@ -77,9 +77,22 @@ internal abstract class KotlinNativeToolRunner(
|
||||
}
|
||||
|
||||
final override val classpath by lazy {
|
||||
project.fileTree("${project.konanHome}/konan/lib/").apply { include("*.jar") }.toSet()
|
||||
project.files(
|
||||
project.kotlinNativeCompilerJar,
|
||||
"${project.konanHome}/konan/lib/trove4j.jar"
|
||||
).files
|
||||
}
|
||||
|
||||
private val Project.kotlinNativeCompilerJar: String
|
||||
get() = if (isNativeEmbedded)
|
||||
"$konanHome/konan/lib/kotlin-native-compiler-embeddable.jar"
|
||||
else
|
||||
"$konanHome/konan/lib/kotlin-native.jar"
|
||||
|
||||
//TODO: find better place (see org.jetbrains.kotlinx.serialization.gradle.SerializationGradleSubplugin.isNativeEmbedded)
|
||||
private val Project.isNativeEmbedded: Boolean
|
||||
get() = findProperty("kotlin.native.shaded")?.toString()?.toBoolean() == true
|
||||
|
||||
final override fun checkClasspath() =
|
||||
check(classpath.isNotEmpty()) {
|
||||
"""
|
||||
|
||||
@@ -72,7 +72,7 @@ class SubpluginEnvironment(
|
||||
|
||||
|
||||
if (kotlinCompilation is AbstractKotlinNativeCompilation) {
|
||||
subplugin.getPluginArtifactForNative()?.let { artifact ->
|
||||
subplugin.getPluginArtifactForNative(project)?.let { artifact ->
|
||||
project.addMavenDependency(kotlinCompilation.pluginConfigurationName, artifact)
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -167,7 +167,9 @@ class NativeCompilerDownloader(
|
||||
}
|
||||
|
||||
fun downloadIfNeeded() {
|
||||
if (KotlinNativeCompilerRunner(project).classpath.isEmpty()) {
|
||||
|
||||
val classpath = KotlinNativeCompilerRunner(project).classpath
|
||||
if (classpath.isEmpty() || classpath.any { !it.exists() }) {
|
||||
downloadAndExtract()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,12 @@ class SerializationGradleSubplugin :
|
||||
override fun getPluginArtifactForNative(): SubpluginArtifact? =
|
||||
SubpluginArtifact(SERIALIZATION_GROUP_NAME, SERIALIZATION_ARTIFACT_UNSHADED_NAME)
|
||||
|
||||
override fun getPluginArtifactForNative(project: Project): SubpluginArtifact? =
|
||||
if (project.isNativeEmbedded)
|
||||
getPluginArtifact()
|
||||
else getPluginArtifactForNative()
|
||||
|
||||
|
||||
override fun getCompilerPluginId() = "org.jetbrains.kotlinx.serialization"
|
||||
|
||||
//region Stub implementation for legacy API, KT-39809
|
||||
@@ -63,4 +69,9 @@ class SerializationGradleSubplugin :
|
||||
"Please use an older version of kotlin-serialization or upgrade the Kotlin Gradle plugin version to make them match."
|
||||
)
|
||||
//endregion
|
||||
|
||||
// TODO: find better place (see org.jetbrains.kotlin.compilerRunner.KotlinNativeToolRunner.isNativeEmbedded)
|
||||
private val Project.isNativeEmbedded: Boolean
|
||||
get() = findProperty("kotlin.native.shaded")?.toString()?.toBoolean() == true
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user