Skip to content

Commit

Permalink
Use reflection to get konan home
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnatBeresnev committed Mar 12, 2024
1 parent 55446ab commit 1030214
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
@file:Suppress("INVISIBLE_REFERENCE")
package org.jetbrains.dokka.gradle.kotlin

import java.io.File
import org.gradle.api.Project
import org.jetbrains.kotlin.commonizer.KonanDistribution
import org.jetbrains.kotlin.commonizer.platformLibsDir
import org.jetbrains.kotlin.commonizer.stdlib
import org.jetbrains.kotlin.compilerRunner.konanHome
import org.jetbrains.kotlin.gradle.utils.NativeCompilerDownloader
import org.jetbrains.kotlin.konan.target.KonanTarget
import java.io.File

/**
* Provides access to the Kotlin/Native distribution components:
Expand All @@ -27,10 +27,19 @@ internal class KotlinNativeDistributionAccessor(
project: Project
) {
private val konanDistribution = KonanDistribution(
@Suppress("INVISIBLE_MEMBER")
project.konanHome
Class.forName("org.jetbrains.kotlin.compilerRunner.NativeToolRunnersKt")
.declaredMethods
.find { it.name == "getKonanHome" && it.returnType.simpleName == "String" }
?.invoke(null, project) as? String
?: project.alternativeKonanHome()
?: error("Unable to find the Kotlin Native home")
)

private fun Project.alternativeKonanHome(): String? {
val nativeHome = this.findProperty("org.jetbrains.kotlin.native.home") as? String ?: return null
return File(nativeHome).absolutePath ?: NativeCompilerDownloader(project).compilerDirectory.absolutePath
}

val stdlibDir: File = konanDistribution.stdlib

fun platformDependencies(target: KonanTarget): List<File> = konanDistribution
Expand Down

0 comments on commit 1030214

Please sign in to comment.