Validate -Xbackend-threads CLI argument value

#KT-51846 Fixed
This commit is contained in:
Alexander Udalov
2022-04-06 00:13:07 +02:00
parent d69df1898d
commit 6402c3908c
10 changed files with 54 additions and 6 deletions
@@ -321,11 +321,27 @@ fun CompilerConfiguration.configureAdvancedJvmOptions(arguments: K2JVMCompilerAr
arguments.declarationsOutputPath?.let { put(JVMConfigurationKeys.DECLARATIONS_JSON_PATH, it) }
val nThreadsRaw = arguments.parallelBackendThreads.toIntOrNull() ?: 1
val nThreadsRaw = parseBackendThreads(arguments.backendThreads, messageCollector)
val nThreads = if (nThreadsRaw == 0) Runtime.getRuntime().availableProcessors() else nThreadsRaw
if (nThreads > 1) {
messageCollector.report(LOGGING, "Running backend in parallel with $nThreads threads")
}
put(CommonConfigurationKeys.PARALLEL_BACKEND_THREADS, nThreads)
}
private fun parseBackendThreads(stringValue: String, messageCollector: MessageCollector): Int {
val value = stringValue.toIntOrNull()
if (value == null) {
messageCollector.report(ERROR, "Cannot parse -Xbackend-threads value: \"$stringValue\". Please use an integer number")
return 1
}
if (value < 0) {
messageCollector.report(ERROR, "-Xbackend-threads value cannot be negative")
return 1
}
return value
}
fun CompilerConfiguration.configureKlibPaths(arguments: K2JVMCompilerArguments) {
val libraries = arguments.klibLibraries ?: return
assert(arguments.useIR && !arguments.useOldBackend) { "Klib libraries can only be used with IR backend" }