diff --git a/kotlin-native/klib/src/main/kotlin/org/jetbrains/kotlin/cli/klib/main.kt b/kotlin-native/klib/src/main/kotlin/org/jetbrains/kotlin/cli/klib/main.kt index 82135f92a0b..8d9ed42e9d4 100644 --- a/kotlin-native/klib/src/main/kotlin/org/jetbrains/kotlin/cli/klib/main.kt +++ b/kotlin-native/klib/src/main/kotlin/org/jetbrains/kotlin/cli/klib/main.kt @@ -2,16 +2,28 @@ * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license * that can be found in the LICENSE file. */ +@file:JvmName("Main") package org.jetbrains.kotlin.cli.klib -// TODO: Extract `library` package as a shared jar? import kotlin.system.exitProcess -fun main(rawArgs: Array) { - val output = KlibToolOutput(stdout = System.out, stderr = System.err) +/** + * This entry point is used in various KLIB dumping tests: dumping IR, dumping metadata, dumping signatures, etc. + */ +@Suppress("unused") +fun exec(stdout: Appendable, stderr: Appendable, args: Array): Int { + return execImpl(KlibToolOutput(stdout, stderr), args) +} +fun main(args: Array) { + val exitCode = execImpl(KlibToolOutput(stdout = System.out, stderr = System.err), args) + if (exitCode != 0) exitProcess(exitCode) +} + +private fun execImpl(output: KlibToolOutput, rawArgs: Array): Int { val args = KlibToolArgumentsParser(output).parseArguments(rawArgs) + if (args != null) { val command = when (args.commandName) { "dump-abi" -> DumpAbi(output, args) @@ -37,6 +49,5 @@ fun main(rawArgs: Array) { } } - if (output.hasErrors) - exitProcess(1) + return if (output.hasErrors) 1 else 0 }