[kotlin gradle plugin] enable to work with embedded k/n compiler.

This commit is contained in:
Vasily Levchenko
2021-07-09 14:39:46 +02:00
committed by Space
parent 1eb951749d
commit 2baf344f5f
8 changed files with 38 additions and 5 deletions

View File

@@ -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')
}

View File

@@ -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.

View File

@@ -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)

View File

@@ -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()

View File

@@ -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()) {
"""

View File

@@ -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 {

View File

@@ -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()
}
}

View File

@@ -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
}