Added property for overriding konan distribution location

#KT-50463 Fixed

Merge-request: KT-MR-10310
Merged-by: Dmitrii Krasnov <Dmitrii.Krasnov@jetbrains.com>
This commit is contained in:
Dmitrii Krasnov
2023-07-12 12:36:51 +00:00
committed by Space Team
parent 2f7f69ed4f
commit f2816a5531
32 changed files with 174 additions and 108 deletions
@@ -126,7 +126,7 @@ abstract class KotlinToolRunner(
}
}
fun run(args: List<String>) {
open fun run(args: List<String>) {
checkClasspath()
if (mustRunViaExec) runViaExec(args) else runInProcess(args)
@@ -37,6 +37,9 @@ internal val Project.konanVersion: String
get() = PropertiesProvider(this).nativeVersion
?: NativeCompilerDownloader.DEFAULT_KONAN_VERSION
internal val Project.konanDataDir: String?
get() = PropertiesProvider(this).konanDataDir
internal fun Project.getKonanCacheKind(target: KonanTarget): NativeCacheKind {
val commonCacheKind = PropertiesProvider(this).nativeCacheKind
val targetCacheKind = PropertiesProvider(this).nativeCacheKindForTarget(target)
@@ -69,7 +72,7 @@ private val Project.kotlinNativeCompilerJar: String
internal abstract class KotlinNativeToolRunner(
protected val toolName: String,
private val settings: Settings,
executionContext: GradleExecutionContext
executionContext: GradleExecutionContext,
) : KotlinToolRunner(executionContext) {
class Settings(
@@ -78,7 +81,8 @@ internal abstract class KotlinNativeToolRunner(
val konanPropertiesFile: File,
val useXcodeMessageStyle: Boolean,
val jvmArgs: List<String>,
val classpath: FileCollection
val classpath: FileCollection,
val konanDataDir: String?,
) {
companion object {
fun fromProject(project: Project) = Settings(
@@ -87,7 +91,8 @@ internal abstract class KotlinNativeToolRunner(
konanPropertiesFile = project.file("${project.konanHome}/konan/konan.properties"),
useXcodeMessageStyle = project.useXcodeMessageStyle,
jvmArgs = project.jvmArgs,
classpath = project.files(project.kotlinNativeCompilerJar, "${project.konanHome}/konan/lib/trove4j.jar")
classpath = project.files(project.kotlinNativeCompilerJar, "${project.konanHome}/konan/lib/trove4j.jar"),
konanDataDir = project.konanDataDir
)
}
}
@@ -131,13 +136,21 @@ internal abstract class KotlinNativeToolRunner(
override fun transformArgs(args: List<String>) = listOf(toolName) + args
final override fun getCustomJvmArgs() = settings.jvmArgs
final override fun run(args: List<String>) {
super.run(args + extractArgsFromSettings())
}
private fun extractArgsFromSettings(): List<String> {
return settings.konanDataDir?.let { listOf("-Xkonan-data-dir", it) } ?: emptyList()
}
}
/** A common ancestor for all runners that run the cinterop tool. */
internal abstract class AbstractKotlinNativeCInteropRunner(
toolName: String,
settings: Settings,
executionContext: GradleExecutionContext
executionContext: GradleExecutionContext,
) : KotlinNativeToolRunner(toolName, settings, executionContext) {
override val mustRunViaExec get() = true
@@ -160,7 +173,7 @@ internal abstract class AbstractKotlinNativeCInteropRunner(
}
konanProperties.resolvablePropertyString("llvmHome.mingw_x64")?.let { toolchainDir ->
DependencyDirectories.defaultDependenciesRoot
DependencyDirectories.getDependenciesRoot(settings.konanDataDir)
.resolve("$toolchainDir/bin")
.absolutePath
}
@@ -193,7 +206,7 @@ private constructor(
/** Kotlin/Native compiler runner */
internal class KotlinNativeCompilerRunner(
private val settings: Settings,
executionContext: GradleExecutionContext
executionContext: GradleExecutionContext,
) : KotlinNativeToolRunner("konanc", settings.parent, executionContext) {
class Settings(
val parent: KotlinNativeToolRunner.Settings,
@@ -231,7 +244,7 @@ internal class KotlinNativeCompilerRunner(
/** Platform libraries generation tool. Runs the cinterop tool under the hood. */
internal class KotlinNativeLibraryGenerationRunner(
private val settings: Settings,
executionContext: GradleExecutionContext
executionContext: GradleExecutionContext,
) :
AbstractKotlinNativeCInteropRunner("generatePlatformLibraries", settings, executionContext) {
@@ -535,6 +535,13 @@ internal class PropertiesProvider private constructor(private val project: Proje
val suppressExperimentalArtifactsDslWarning: Boolean
get() = booleanProperty(KOTLIN_NATIVE_SUPPRESS_EXPERIMENTAL_ARTIFACTS_DSL_WARNING) ?: false
/**
* Allows the user to specify a custom location for the Kotlin/Native distribution.
* This property takes precedence over the 'KONAN_DATA_DIR' environment variable.
*/
val konanDataDir: String?
get() = property(PropertyNames.KONAN_DATA_DIR)
/**
* Retrieves a comma-separated list of browsers to use when running karma tests for [target]
* @see KOTLIN_JS_KARMA_BROWSERS
@@ -632,6 +639,7 @@ internal class PropertiesProvider private constructor(private val project: Proje
const val KOTLIN_SUPPRESS_GRADLE_PLUGIN_ERRORS = "kotlin.internal.suppressGradlePluginErrors"
const val KOTLIN_NATIVE_IGNORE_DISABLED_TARGETS = "kotlin.native.ignoreDisabledTargets"
const val KOTLIN_NATIVE_SUPPRESS_EXPERIMENTAL_ARTIFACTS_DSL_WARNING = "kotlin.native.suppressExperimentalArtifactsDslWarning"
const val KONAN_DATA_DIR = "konan.data.dir"
}
companion object {
@@ -40,7 +40,9 @@ class NativeCompilerDownloader(
}
val compilerDirectory: File
get() = DependencyDirectories.localKonanDir.resolve(dependencyNameWithOsAndVersion)
get() = DependencyDirectories
.getLocalKonanDir(project.kotlinPropertiesProvider.konanDataDir)
.resolve(dependencyNameWithOsAndVersion)
private val logger: Logger
get() = project.logger
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.gradle.targets.native.internal
import org.gradle.api.Project
import org.jetbrains.kotlin.compilerRunner.KotlinNativeLibraryGenerationRunner
import org.jetbrains.kotlin.compilerRunner.getKonanCacheKind
import org.jetbrains.kotlin.compilerRunner.konanDataDir
import org.jetbrains.kotlin.compilerRunner.konanHome
import org.jetbrains.kotlin.gradle.dsl.NativeCacheKind
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
@@ -28,7 +29,7 @@ import java.util.concurrent.ConcurrentHashMap
internal class PlatformLibrariesGenerator(val project: Project, val konanTarget: KonanTarget) {
private val distribution =
customerDistribution(project.konanHome)
customerDistribution(project.konanHome, konanDataDir = project.konanDataDir)
private val platformLibsDirectory =
File(distribution.platformLibs(konanTarget)).absoluteFile
@@ -353,6 +353,10 @@ internal constructor(
@get:Internal // these sources are normally a subset of `source` ones which are already tracked
val commonSources: ConfigurableFileCollection = project.files()
@Optional
@get:Input
val konanDataDir: String? = project.konanDataDir
@get:Nested
override val multiplatformStructure: K2MultiplatformStructure = objectFactory.newInstance()
@@ -941,7 +945,7 @@ internal class CacheBuilder(
}
private fun ensureCompilerProvidedLibsPrecached() {
val distribution = Distribution(settings.runnerSettings.parent.konanHome)
val distribution = Distribution(settings.runnerSettings.parent.konanHome, konanDataDir = settings.runnerSettings.parent.konanDataDir)
val platformLibs = mutableListOf<File>().apply {
this += File(distribution.stdlib)
this += File(distribution.platformLibs(konanTarget)).listFiles().orEmpty()