[Gradle, K/N] Set LIBCLANG_DISABLE_CRASH_RECOVERY=1 for cinterop
Issue #KT-42485 Fixed
This commit is contained in:
committed by
Ilya Matveev
parent
37197a95cd
commit
a9c9406a55
+40
-9
@@ -677,10 +677,14 @@ class GeneralNativeIT : BaseGradleIT() {
|
|||||||
"$projectName/build/classes/kotlin/host/test/${projectName}_test.klib",
|
"$projectName/build/classes/kotlin/host/test/${projectName}_test.klib",
|
||||||
)
|
)
|
||||||
|
|
||||||
build(":projectLibrary:build") {
|
// Enable info log to see cinterop environment variables.
|
||||||
|
build(":projectLibrary:build", "--info") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
assertTasksExecuted(":projectLibrary:cinteropAnotherNumberHost")
|
assertTasksExecuted(":projectLibrary:cinteropAnotherNumberHost")
|
||||||
libraryFiles("projectLibrary", "anotherNumber").forEach { assertFileExists(it) }
|
libraryFiles("projectLibrary", "anotherNumber").forEach { assertFileExists(it) }
|
||||||
|
checkNativeCustomEnvironment(":projectLibrary:cinteropAnotherNumberHost", toolName = "cinterop") { env ->
|
||||||
|
assertEquals("1", env["LIBCLANG_DISABLE_CRASH_RECOVERY"])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
build(":publishedLibrary:build", ":publishedLibrary:publish") {
|
build(":publishedLibrary:build", ":publishedLibrary:publish") {
|
||||||
@@ -839,8 +843,18 @@ class GeneralNativeIT : BaseGradleIT() {
|
|||||||
return Collections.indexOfSubList(this, elements.toList()) != -1
|
return Collections.indexOfSubList(this, elements.toList()) != -1
|
||||||
}
|
}
|
||||||
|
|
||||||
fun CompiledProject.extractNativeCommandLineArguments(taskPath: String? = null, toolName: String): List<String> {
|
private enum class NativeToolSettingsKind(val title: String) {
|
||||||
val arguments = output.lineSequence()
|
COMMAND_LINE_ARGUMENTS("Arguments"),
|
||||||
|
CUSTOM_ENV_VARIABLES("Custom ENV variables")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun CompiledProject.extractNativeToolSettings(
|
||||||
|
toolName: String,
|
||||||
|
taskPath: String?,
|
||||||
|
settingsKind: NativeToolSettingsKind
|
||||||
|
): Sequence<String> {
|
||||||
|
val settingsPrefix = "${settingsKind.title} = ["
|
||||||
|
val settings = output.lineSequence()
|
||||||
.run {
|
.run {
|
||||||
if (taskPath != null) dropWhile { "Executing actions for task '$taskPath'" !in it }.drop(1) else this
|
if (taskPath != null) dropWhile { "Executing actions for task '$taskPath'" !in it }.drop(1) else this
|
||||||
}
|
}
|
||||||
@@ -851,22 +865,39 @@ class GeneralNativeIT : BaseGradleIT() {
|
|||||||
.drop(1)
|
.drop(1)
|
||||||
.dropWhile {
|
.dropWhile {
|
||||||
check(taskPath == null || "Executing actions for task" !in it) { "Unexpected log line with new Gradle task: $it" }
|
check(taskPath == null || "Executing actions for task" !in it) { "Unexpected log line with new Gradle task: $it" }
|
||||||
"Arguments = [" !in it
|
settingsPrefix !in it
|
||||||
}
|
}
|
||||||
|
|
||||||
val argumentsHeader = arguments.firstOrNull()
|
val settingsHeader = settings.firstOrNull()
|
||||||
check(argumentsHeader != null && "Arguments = [" in argumentsHeader) { "No arguments in $argumentsHeader" }
|
check(settingsHeader != null && settingsPrefix in settingsHeader) {
|
||||||
|
"Cannot find setting '${settingsKind.title}' for task ${taskPath}"
|
||||||
|
}
|
||||||
|
|
||||||
return if (argumentsHeader.trimEnd().endsWith(']'))
|
return if (settingsHeader.trimEnd().endsWith(']'))
|
||||||
emptyList() // no arguments
|
emptySequence() // No parameters.
|
||||||
else
|
else
|
||||||
arguments.drop(1).map { it.trim() }.takeWhile { it != "]" }.toList()
|
settings.drop(1).map { it.trim() }.takeWhile { it != "]" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun CompiledProject.extractNativeCommandLineArguments(taskPath: String? = null, toolName: String): List<String> =
|
||||||
|
extractNativeToolSettings(toolName, taskPath, NativeToolSettingsKind.COMMAND_LINE_ARGUMENTS).toList()
|
||||||
|
|
||||||
|
fun CompiledProject.extractNativeCustomEnvironment(taskPath: String? = null, toolName: String): Map<String, String> =
|
||||||
|
extractNativeToolSettings(toolName, taskPath, NativeToolSettingsKind.CUSTOM_ENV_VARIABLES).map {
|
||||||
|
val (key, value) = it.split("=")
|
||||||
|
key.trim() to value.trim()
|
||||||
|
}.toMap()
|
||||||
|
|
||||||
fun CompiledProject.checkNativeCommandLineArguments(
|
fun CompiledProject.checkNativeCommandLineArguments(
|
||||||
vararg taskPaths: String,
|
vararg taskPaths: String,
|
||||||
toolName: String = "konanc",
|
toolName: String = "konanc",
|
||||||
check: (List<String>) -> Unit
|
check: (List<String>) -> Unit
|
||||||
) = taskPaths.forEach { taskPath -> check(extractNativeCommandLineArguments(taskPath, toolName)) }
|
) = taskPaths.forEach { taskPath -> check(extractNativeCommandLineArguments(taskPath, toolName)) }
|
||||||
|
|
||||||
|
fun CompiledProject.checkNativeCustomEnvironment(
|
||||||
|
vararg taskPaths: String,
|
||||||
|
toolName: String = "konanc",
|
||||||
|
check: (Map<String, String>) -> Unit
|
||||||
|
) = taskPaths.forEach { taskPath -> check(extractNativeCustomEnvironment(taskPath, toolName)) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-2
@@ -136,12 +136,12 @@ internal abstract class KotlinToolRunner(
|
|||||||
private val isolatedClassLoadersMap = ConcurrentHashMap<Any, ClassLoader>()
|
private val isolatedClassLoadersMap = ConcurrentHashMap<Any, ClassLoader>()
|
||||||
|
|
||||||
private fun Map<String, String>.toPrettyString(): String = buildString {
|
private fun Map<String, String>.toPrettyString(): String = buildString {
|
||||||
append('{')
|
append('[')
|
||||||
if (this@toPrettyString.isNotEmpty()) append('\n')
|
if (this@toPrettyString.isNotEmpty()) append('\n')
|
||||||
this@toPrettyString.entries.forEach { (key, value) ->
|
this@toPrettyString.entries.forEach { (key, value) ->
|
||||||
append('\t').append(key).append(" = ").append(value.toPrettyString()).append('\n')
|
append('\t').append(key).append(" = ").append(value.toPrettyString()).append('\n')
|
||||||
}
|
}
|
||||||
append('}')
|
append(']')
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Collection<String>.toPrettyString(): String = buildString {
|
private fun Collection<String>.toPrettyString(): String = buildString {
|
||||||
|
|||||||
+7
-5
@@ -92,11 +92,13 @@ internal abstract class AbstractKotlinNativeCInteropRunner(toolName: String, pro
|
|||||||
override val mustRunViaExec get() = true
|
override val mustRunViaExec get() = true
|
||||||
|
|
||||||
override val execEnvironment by lazy {
|
override val execEnvironment by lazy {
|
||||||
val llvmExecutablesPath = llvmExecutablesPath
|
val result = mutableMapOf<String, String>()
|
||||||
if (llvmExecutablesPath != null)
|
result.putAll(super.execEnvironment)
|
||||||
super.execEnvironment + ("PATH" to "$llvmExecutablesPath;${System.getenv("PATH")}")
|
result["LIBCLANG_DISABLE_CRASH_RECOVERY"] = "1"
|
||||||
else
|
llvmExecutablesPath?.let {
|
||||||
super.execEnvironment
|
result["PATH"] = "$it;${System.getenv("PATH")}"
|
||||||
|
}
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
private val llvmExecutablesPath: String? by lazy {
|
private val llvmExecutablesPath: String? by lazy {
|
||||||
|
|||||||
Reference in New Issue
Block a user