diff --git a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/Exceptions.kt b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/Exceptions.kt index 3b779d3a918..ae5b7c217a5 100644 --- a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/Exceptions.kt +++ b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/Exceptions.kt @@ -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) + diff --git a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Xcode.kt b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Xcode.kt index 15842206e40..d2508aba603 100644 --- a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Xcode.kt +++ b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Xcode.kt @@ -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") }