Get rid of konan.home in the compiler

This patch uses a path to a jar containing compiler classes
to determine the distribution path instead of relying on
the konan.home system property. However this property
still may be used to specify the distribution path e.g. when
the distribution isn't fully built and the compiler is
executed from classes located in a build directory.
This commit is contained in:
Ilya Matveev
2020-05-07 15:21:11 +07:00
committed by Ilya Matveev
parent f959f275e8
commit cc631f1f99
34 changed files with 132 additions and 68 deletions
+6 -1
View File
@@ -19,6 +19,11 @@ tasks.named<KotlinCompile>("compileKotlin") {
}
}
dependencies {
// Convert to normal strings since originally these properties contain GStrings.
val kotlinCompilerModule = rootProject.ext["kotlinCompilerModule"].toString()
val kotlinStdLibModule = rootProject.ext["kotlinStdLibModule"].toString()
dependencies {
api(kotlinStdLibModule)
implementation(kotlinCompilerModule)
}
@@ -0,0 +1,39 @@
package org.jetbrains.kotlin.konan.util
import org.jetbrains.kotlin.utils.PathUtil
import java.io.File
import java.nio.file.Paths
object KonanHomeProvider {
/**
* Determines a path to the current Kotlin/Native distribution.
*
* - If the system property "konan.home" is set, the method returns its value.
* - Otherwise, it determines a path to a jar containing this class. If this path corresponds to the jar path
* inside a distribution, the method calculates the path to the distribution on the basis of this jar path.
* Otherwise an IllegalStateException is thrown.
*/
fun determineKonanHome(): String {
val propertyValue = System.getProperty("konan.home")
return if (propertyValue != null) {
File(propertyValue).absolutePath
} else {
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)) {
val classesPath = if (jarPath.extension == "jar") jarPath else jarPath.parentFile
"""
Cannot determine a compiler distribution directory.
A path to compiler classes is not a part of a distribution: ${classesPath.absolutePath}.
Please set the konan.home system property to specify the distribution path manually.
""".trimIndent()
}
// The compiler jar is located in <dist>/konan/lib.
jarPath.parentFile.parentFile.parentFile.absolutePath
}
}
}
+5 -4
View File
@@ -22,8 +22,9 @@ compileKotlin {
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
compile project(':backend.native')
compile project(':Interop:StubGenerator')
compile project(':klib')
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
implementation project(':backend.native')
implementation project(':Interop:StubGenerator')
implementation project(':klib')
implementation project(":utilities:basic-utils")
}
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.konan.target.CompilerOutputKind
import org.jetbrains.kotlin.konan.target.HostManager
import org.jetbrains.kotlin.konan.target.KonanTarget
import org.jetbrains.kotlin.konan.target.customerDistribution
import org.jetbrains.kotlin.konan.util.KonanHomeProvider
import org.jetbrains.kotlin.konan.util.PlatformLibsInfo
import org.jetbrains.kotlin.konan.util.visibleName
import org.jetbrains.kotlin.native.interop.tool.CommonInteropArguments.Companion.DEFAULT_MODE
@@ -120,7 +121,7 @@ fun generatePlatformLibraries(args: Array<String>) {
argParser.parse(args)
val distribution = customerDistribution()
val distribution = customerDistribution(KonanHomeProvider.determineKonanHome())
val target = HostManager(distribution).targetByName(targetName)
val inputDirectory = inputDirectoryPath?.File()
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.cli.utilities
import org.jetbrains.kotlin.cli.bc.SHORT_MODULE_NAME_ARG
import org.jetbrains.kotlin.konan.file.File
import org.jetbrains.kotlin.konan.target.PlatformManager
import org.jetbrains.kotlin.konan.util.KonanHomeProvider
import org.jetbrains.kotlin.native.interop.gen.jvm.InternalInteropOptions
import org.jetbrains.kotlin.native.interop.gen.jvm.interop
import org.jetbrains.kotlin.native.interop.tool.*
@@ -39,7 +40,7 @@ fun invokeInterop(flavor: String, args: Array<String>): Array<String>? {
val repos = arguments.repo
val targetRequest = if (arguments is CInteropArguments) arguments.target
else (arguments as JSInteropArguments).target
val target = PlatformManager().targetManager(targetRequest).target
val target = PlatformManager(KonanHomeProvider.determineKonanHome()).targetManager(targetRequest).target
val cinteropArgsToCompiler = interop(flavor, args,
InternalInteropOptions(generatedDir.absolutePath,