Produce a warning in case we could not find an entry point.
This commit is contained in:
committed by
alexander-gorshenev
parent
43a975ad73
commit
63ace8add9
+12
-2
@@ -16,13 +16,23 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.backend.konan
|
package org.jetbrains.kotlin.backend.konan
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a common ancestor of all Kotlin/Native exceptions.
|
||||||
|
*/
|
||||||
|
open class KonanException(message: String = "", cause: Throwable? = null) : Exception(message, cause)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a compilation error caused by mistakes in an input file, e.g. undefined reference.
|
* Represents a compilation error caused by mistakes in an input file, e.g. undefined reference.
|
||||||
*/
|
*/
|
||||||
class KonanCompilationException(message: String = "", cause: Throwable? = null) : Exception(message, cause) {}
|
class KonanCompilationException(message: String = "", cause: Throwable? = null) : KonanException(message, cause)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal compiler error: could not deserialize IR for inline function body.
|
* Internal compiler error: could not deserialize IR for inline function body.
|
||||||
*/
|
*/
|
||||||
class KonanIrDeserializationException(message: String = "", cause: Throwable? = null) : Exception(message, cause)
|
class KonanIrDeserializationException(message: String = "", cause: Throwable? = null) : KonanException(message, cause)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An error occured during external tool invocation. Such as non-zero exit code.
|
||||||
|
*/
|
||||||
|
class KonanExternalToolFailure(message: String = "", cause: Throwable? = null) : KonanException(message, cause)
|
||||||
|
|
||||||
|
|||||||
+7
-4
@@ -292,7 +292,7 @@ internal class LinkStage(val context: Context) {
|
|||||||
private val entryPointSelector: List<String>
|
private val entryPointSelector: List<String>
|
||||||
get() = if (nomain) emptyList() else platform.entrySelector
|
get() = if (nomain) emptyList() else platform.entrySelector
|
||||||
|
|
||||||
private fun link(objectFiles: List<ObjectFile>, libraryProvidedLinkerFlags: List<String>): ExecutableFile {
|
private fun link(objectFiles: List<ObjectFile>, libraryProvidedLinkerFlags: List<String>): ExecutableFile? {
|
||||||
val executable = context.config.outputFile
|
val executable = context.config.outputFile
|
||||||
|
|
||||||
val linkCommand = platform.linkCommand(objectFiles, executable, optimize, debug) +
|
val linkCommand = platform.linkCommand(objectFiles, executable, optimize, debug) +
|
||||||
@@ -302,13 +302,16 @@ internal class LinkStage(val context: Context) {
|
|||||||
platform.linkCommandSuffix() +
|
platform.linkCommandSuffix() +
|
||||||
libraryProvidedLinkerFlags
|
libraryProvidedLinkerFlags
|
||||||
|
|
||||||
runTool(*linkCommand.toTypedArray())
|
try {
|
||||||
|
runTool(*linkCommand.toTypedArray())
|
||||||
|
} catch (e: KonanExternalToolFailure) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
if (platform is MacOSBasedPlatform && context.shouldContainDebugInfo()) {
|
if (platform is MacOSBasedPlatform && context.shouldContainDebugInfo()) {
|
||||||
if (context.phase?.verbose ?: false)
|
if (context.phase?.verbose ?: false)
|
||||||
runTool(*platform.dsymutilDryRunVerboseCommand(executable).toTypedArray())
|
runTool(*platform.dsymutilDryRunVerboseCommand(executable).toTypedArray())
|
||||||
runTool(*platform.dsymutilCommand(executable).toTypedArray())
|
runTool(*platform.dsymutilCommand(executable).toTypedArray())
|
||||||
}
|
}
|
||||||
|
|
||||||
return executable
|
return executable
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,7 +352,7 @@ internal class LinkStage(val context: Context) {
|
|||||||
|
|
||||||
private fun runTool(vararg command: String) {
|
private fun runTool(vararg command: String) {
|
||||||
val code = executeCommand(*command)
|
val code = executeCommand(*command)
|
||||||
if (code != 0) error("The ${command[0]} command returned non-zero exit code: $code.")
|
if (code != 0) throw KonanExternalToolFailure("The ${command[0]} command returned non-zero exit code: $code.")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun linkStage() {
|
fun linkStage() {
|
||||||
|
|||||||
+9
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.backend.konan
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||||
|
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||||
import org.jetbrains.kotlin.ir.util.getCompilerMessageLocation
|
import org.jetbrains.kotlin.ir.util.getCompilerMessageLocation
|
||||||
@@ -27,3 +28,11 @@ internal fun CommonBackendContext.reportCompilationError(message: String, irFile
|
|||||||
this.messageCollector.report(CompilerMessageSeverity.ERROR, message, location)
|
this.messageCollector.report(CompilerMessageSeverity.ERROR, message, location)
|
||||||
throw KonanCompilationException()
|
throw KonanCompilationException()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal fun CommonBackendContext.reportCompilationError(message: String) {
|
||||||
|
this.messageCollector.report(CompilerMessageSeverity.ERROR, message, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun CommonBackendContext.reportCompilationWarning(message: String) {
|
||||||
|
this.messageCollector.report(CompilerMessageSeverity.WARNING, message, null)
|
||||||
|
}
|
||||||
|
|||||||
+4
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.backend.konan.llvm
|
package org.jetbrains.kotlin.backend.konan.llvm
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.backend.konan.reportCompilationError
|
||||||
import org.jetbrains.kotlin.backend.konan.Context
|
import org.jetbrains.kotlin.backend.konan.Context
|
||||||
import org.jetbrains.kotlin.backend.konan.KonanConfigKeys
|
import org.jetbrains.kotlin.backend.konan.KonanConfigKeys
|
||||||
import org.jetbrains.kotlin.backend.konan.descriptors.isArray
|
import org.jetbrains.kotlin.backend.konan.descriptors.isArray
|
||||||
@@ -49,6 +50,9 @@ internal fun findMainEntryPoint(context: Context): FunctionDescriptor? {
|
|||||||
it.typeParameters.isEmpty() &&
|
it.typeParameters.isEmpty() &&
|
||||||
it.isExported()
|
it.isExported()
|
||||||
}
|
}
|
||||||
|
if (main == null) {
|
||||||
|
context.reportCompilationError("Could not find '$entryName' in '$packageName' package.")
|
||||||
|
}
|
||||||
return main
|
return main
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user