Skip to content

Commit

Permalink
Add a comment that explains reflection around konanHome
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnatBeresnev committed Mar 12, 2024
1 parent 1030214 commit c8a3481
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ internal class KotlinNativeDistributionAccessor(
project: Project
) {
private val konanDistribution = KonanDistribution(
// see this comment for the explanation of what's happening:
// https://github.com/Kotlin/dokka/pull/3516#issuecomment-1992141380
Class.forName("org.jetbrains.kotlin.compilerRunner.NativeToolRunnersKt")
.declaredMethods
.find { it.name == "getKonanHome" && it.returnType.simpleName == "String" }
Expand All @@ -35,13 +37,13 @@ internal class KotlinNativeDistributionAccessor(
?: error("Unable to find the Kotlin Native home")
)

val stdlibDir: File = konanDistribution.stdlib

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
.platformLibsDir
.resolve(target.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ private fun KotlinCompilation.newCompileClasspathOf(project: Project): FileColle
// Since Kotlin 2.0 native distributiuon dependencies will be included to compileDependencyFiles
if (kgpVersion != null && kgpVersion <= KotlinGradlePluginVersion(1, 9, 255)) {
if (this is AbstractKotlinNativeCompilation) {
val kotlinNativeDistributionAccessor = KotlinNativeDistributionAccessor(project)
result.from(kotlinNativeDistributionAccessor.stdlibDir)
result.from(kotlinNativeDistributionAccessor.platformDependencies(konanTarget))
val excludePlatformFiles = project.classpathProperty("excludeKonanPlatformDependencyFiles", default = false)
if (!excludePlatformFiles) {
val kotlinNativeDistributionAccessor = KotlinNativeDistributionAccessor(project)
result.from(kotlinNativeDistributionAccessor.stdlibDir)
result.from(kotlinNativeDistributionAccessor.platformDependencies(konanTarget))
}
}
}

Expand Down

0 comments on commit c8a3481

Please sign in to comment.