Allow running compiler only for libraries (#1508)

This commit is contained in:
ilmat192
2018-04-19 12:12:01 +07:00
committed by GitHub
parent f27d4452f4
commit 3572c98a8b
4 changed files with 32 additions and 7 deletions
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.backend.konan.util.profile
import org.jetbrains.kotlin.cli.common.CLICompiler
import org.jetbrains.kotlin.cli.common.CLITool
import org.jetbrains.kotlin.cli.common.ExitCode
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.config.CompilerConfiguration
@@ -49,15 +49,21 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
return ExitCode.OK
}
if (arguments.freeArgs.isEmpty() && !arguments.isUsefulWithoutFreeArgs) {
configuration.report(ERROR, "You have not specified any compilation arguments. No output has been produced.")
}
val environment = KotlinCoreEnvironment.createForProduction(rootDisposable,
configuration, EnvironmentConfigFiles.NATIVE_CONFIG_FILES)
val project = environment.project
val konanConfig = KonanConfig(project, configuration)
val enoughArguments = arguments.freeArgs.isNotEmpty() || arguments.isUsefulWithoutFreeArgs
if (!enoughArguments) {
configuration.report(ERROR, "You have not specified any compilation arguments. No output has been produced.")
}
if (konanConfig.linkOnly) {
configuration.report(WARNING, "You have not specified any source files. " +
"Only libraries will be used to produce the output binary.")
}
try {
runTopLevelPhases(konanConfig, environment)
} catch (e: KonanCompilationException) {
@@ -78,7 +84,7 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
}
val K2NativeCompilerArguments.isUsefulWithoutFreeArgs: Boolean
get() = this.listTargets || this.listPhases || this.checkDependencies
get() = this.listTargets || this.listPhases || this.checkDependencies || this.libraries?.isNotEmpty() ?: false
fun Array<String>?.toNonNullList(): List<String> {
return this?.asList<String>() ?: listOf<String>()