[KT-40670] Allow override konan.properties

It is painful to edit konan.properties just to override some value (e.g. compiler flags or LLVM location), especially if it is needed only in a single project. Thus `-Xoverride-konan-properties` is added.
This commit is contained in:
Sergey Bogolepov
2020-10-15 18:02:05 +07:00
committed by Stanislav Erokhin
parent 4297b521e4
commit e2cb099d2b
4 changed files with 33 additions and 1 deletions
@@ -252,6 +252,7 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
}
put(DISABLE_FAKE_OVERRIDE_VALIDATOR, arguments.disableFakeOverrideValidator)
putIfNotNull(PRE_LINK_CACHES, parsePreLinkCachesValue(configuration, arguments.preLinkCaches))
putIfNotNull(OVERRIDE_KONAN_PROPERTIES, parseOverrideKonanProperties(arguments, configuration))
}
}
}
@@ -455,6 +456,24 @@ private fun parseDebugPrefixMap(
}
}.toMap()
private fun parseOverrideKonanProperties(
arguments: K2NativeCompilerArguments,
configuration: CompilerConfiguration
): Map<String, String>? =
arguments.overrideKonanProperties?.mapNotNull {
val keyValueSeparatorIndex = it.indexOf('=')
if (keyValueSeparatorIndex > 0) {
it.substringBefore('=') to it.substringAfter('=')
} else {
configuration.report(
ERROR,
"incorrect property format: expected '<key>=<value>', got '$it'"
)
null
}
}?.toMap()
fun main(args: Array<String>) = K2Native.main(args)
fun mainNoExitWithGradleRenderer(args: Array<String>) = K2Native.mainNoExitWithGradleRenderer(args)
@@ -278,6 +278,16 @@ class K2NativeCompilerArguments : CommonCompilerArguments() {
)
var preLinkCaches: String? = null
// We use `;` as delimiter because properties may contain comma-separated values.
// For example, target cpu features.
@Argument(
value = "-Xoverride-konan-properties",
valueDescription = "key1=value1;key2=value2;...",
description = "Override konan.properties.values",
delimiter = ";"
)
var overrideKonanProperties: Array<String>? = null
override fun configureAnalysisFlags(collector: MessageCollector): MutableMap<AnalysisFlag<*>, Any> =
super.configureAnalysisFlags(collector).also {
val useExperimental = it[AnalysisFlags.useExperimental] as List<*>
@@ -30,7 +30,8 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
internal val distribution = Distribution(
configuration.get(KonanConfigKeys.KONAN_HOME) ?: KonanHomeProvider.determineKonanHome(),
false,
configuration.get(KonanConfigKeys.RUNTIME_FILE)
configuration.get(KonanConfigKeys.RUNTIME_FILE),
configuration.get(KonanConfigKeys.OVERRIDE_KONAN_PROPERTIES)
)
private val platformManager = PlatformManager(distribution)
@@ -144,6 +144,8 @@ class KonanConfigKeys {
= CompilerConfigurationKey.create("remap file source paths in debug info")
val PRE_LINK_CACHES: CompilerConfigurationKey<Boolean>
= CompilerConfigurationKey.create("perform compiler caches pre-link")
val OVERRIDE_KONAN_PROPERTIES: CompilerConfigurationKey<Map<String, String>>
= CompilerConfigurationKey.create("override konan.properties values")
}
}