Process xcrun failures when a local Xcode is used
The K/N compiler uses a toolchain and command line tools provided by Xcode. But if Xcode or command line are not properly installed the compiler fails with a cryptic error message (e.g. see #3587). This patch processes failures during an xcrun execution and reports a better error message.
This commit is contained in:
committed by
Ilya Matveev
parent
7faa5a35bc
commit
b88f236ae4
@@ -22,7 +22,12 @@ package org.jetbrains.kotlin.konan
|
||||
open class KonanException(message: String = "", cause: Throwable? = null) : Exception(message, cause)
|
||||
|
||||
/**
|
||||
* An error occured during external tool invocation. Such as non-zero exit code.
|
||||
* An error occurred during external tool invocation. Such as non-zero exit code.
|
||||
*/
|
||||
class KonanExternalToolFailure(message: String, val toolName: String, cause: Throwable? = null) : KonanException(message, cause)
|
||||
|
||||
/**
|
||||
* An exception indicating a failed attempt to access some parts of Xcode (e.g. get SDK paths or version).
|
||||
*/
|
||||
class MissingXcodeException(message: String, cause: Throwable? = null) : KonanException(message, cause)
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.konan.target
|
||||
|
||||
import org.jetbrains.kotlin.konan.KonanExternalToolFailure
|
||||
import org.jetbrains.kotlin.konan.MissingXcodeException
|
||||
import org.jetbrains.kotlin.konan.exec.Command
|
||||
import org.jetbrains.kotlin.konan.file.File
|
||||
|
||||
@@ -69,8 +71,11 @@ private object CurrentXcode : Xcode {
|
||||
.removePrefix("Xcode ")
|
||||
}
|
||||
|
||||
private fun xcrun(vararg args: String): String =
|
||||
Command("/usr/bin/xcrun", *args).getOutputLines().first() // TODO: handle execution error
|
||||
private fun xcrun(vararg args: String): String = try {
|
||||
Command("/usr/bin/xcrun", *args).getOutputLines().first()
|
||||
} catch(e: KonanExternalToolFailure) {
|
||||
throw MissingXcodeException("An error occurred during an xcrun execution. Make sure that Xcode and its command line tools are properly installed.", e)
|
||||
}
|
||||
|
||||
private fun getSdkPath(sdk: String) = xcrun("--sdk", sdk, "--show-sdk-path")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user