Printing linker error message from gradle MPP plugin (#3979)
This commit is contained in:
+1
-1
@@ -133,7 +133,7 @@ internal class Linker(val context: Context) {
|
||||
it.execute()
|
||||
}
|
||||
} catch (e: KonanExternalToolFailure) {
|
||||
context.reportCompilationError("${e.toolName} invocation reported errors")
|
||||
context.reportCompilationError("${e.toolName} invocation reported errors\n${e.message}")
|
||||
}
|
||||
return executable
|
||||
}
|
||||
|
||||
@@ -16,9 +16,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.konan.exec
|
||||
|
||||
import java.lang.ProcessBuilder
|
||||
import java.lang.ProcessBuilder.Redirect
|
||||
import org.jetbrains.kotlin.konan.KonanExternalToolFailure
|
||||
import java.io.BufferedReader
|
||||
import java.io.InputStreamReader
|
||||
import java.lang.ProcessBuilder.Redirect
|
||||
|
||||
|
||||
open class Command(initialCommand: List<String>) {
|
||||
@@ -42,28 +43,33 @@ open class Command(initialCommand: List<String>) {
|
||||
|
||||
var logger: ((() -> String)->Unit)? = null
|
||||
|
||||
private var stdError: List<String> = emptyList()
|
||||
|
||||
fun logWith(newLogger: ((() -> String)->Unit)): Command {
|
||||
logger = newLogger
|
||||
return this
|
||||
}
|
||||
|
||||
open fun runProcess(): Int {
|
||||
stdError = emptyList()
|
||||
val builder = ProcessBuilder(command)
|
||||
|
||||
builder.redirectOutput(Redirect.INHERIT)
|
||||
builder.redirectInput(Redirect.INHERIT)
|
||||
builder.redirectError(Redirect.INHERIT)
|
||||
|
||||
val process = builder.start()
|
||||
|
||||
val reader = BufferedReader(InputStreamReader(process.errorStream))
|
||||
stdError = reader.readLines()
|
||||
|
||||
val exitCode = process.waitFor()
|
||||
return exitCode
|
||||
}
|
||||
|
||||
open fun execute() {
|
||||
log()
|
||||
|
||||
val code = runProcess()
|
||||
handleExitCode(code)
|
||||
handleExitCode(code, stdError)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,8 +110,15 @@ open class Command(initialCommand: List<String>) {
|
||||
private fun handleExitCode(code: Int, output: List<String> = emptyList()) {
|
||||
if (code != 0) throw KonanExternalToolFailure("""
|
||||
The ${command[0]} command returned non-zero exit code: $code.
|
||||
output: ${output.joinToString("\n")}
|
||||
output:
|
||||
${output.joinToString("\n")}
|
||||
""".trimIndent(), command[0])
|
||||
// Show warnings in case of success linkage.
|
||||
if (stdError.isNotEmpty()) {
|
||||
stdError.joinToString("\n").also { message ->
|
||||
logger?.let { it { message } } ?: println(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun log() {
|
||||
|
||||
Reference in New Issue
Block a user