CLI: Add --check_dependencies flag
This commit is contained in:
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.Services
|
||||
import org.jetbrains.kotlin.config.addKotlinSourceRoots
|
||||
import org.jetbrains.kotlin.config.kotlinSourceRoots
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||
import org.jetbrains.kotlin.konan.target.TargetManager
|
||||
import org.jetbrains.kotlin.utils.KotlinPaths
|
||||
@@ -39,6 +40,10 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
||||
|
||||
override fun doExecute(@NotNull arguments: K2NativeCompilerArguments, @NotNull configuration: CompilerConfiguration, @NotNull rootDisposable: Disposable, @Nullable paths: KotlinPaths?): ExitCode {
|
||||
|
||||
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
|
||||
@@ -50,16 +55,12 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
||||
return ExitCode.COMPILATION_ERROR
|
||||
}
|
||||
|
||||
if (arguments.freeArgs.isEmpty() && !arguments.isUsefulWithoutFreeArgs) {
|
||||
configuration.report(ERROR, "You have not specified any compilation arguments. No output has been produced.")
|
||||
}
|
||||
|
||||
// TODO: catch Errors and IllegalStateException.
|
||||
return ExitCode.OK
|
||||
}
|
||||
|
||||
val K2NativeCompilerArguments.isUsefulWithoutFreeArgs: Boolean
|
||||
get() = this.listTargets || this.listPhases
|
||||
get() = this.listTargets || this.listPhases || this.checkDependencies
|
||||
|
||||
fun Array<String>?.toNonNullList(): List<String> {
|
||||
return this?.asList<String>() ?: listOf<String>()
|
||||
@@ -129,6 +130,13 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
||||
put(TIME_PHASES, arguments.timePhases)
|
||||
|
||||
put(ENABLE_ASSERTIONS, arguments.enableAssertions)
|
||||
|
||||
// We need to download dependencies only if we use them ( = there are files to compile).
|
||||
put(CHECK_DEPENDENCIES, if (configuration.kotlinSourceRoots.isNotEmpty()) {
|
||||
true
|
||||
} else {
|
||||
arguments.checkDependencies
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,12 +82,15 @@ class K2NativeCompilerArguments : CommonCompilerArguments() {
|
||||
// Make sure to prepend them with a double dash.
|
||||
// Keep the list lexically sorted.
|
||||
|
||||
@Argument(value = "--enable", valueDescription = "<Phase>", description = "Enable backend phase")
|
||||
var enablePhases: Array<String>? = null
|
||||
@Argument(value = "--check_dependencies", description = "Check dependencies and download the missing ones")
|
||||
var checkDependencies: Boolean = false
|
||||
|
||||
@Argument(value = "--disable", valueDescription = "<Phase>", description = "Disable backend phase")
|
||||
var disablePhases: Array<String>? = null
|
||||
|
||||
@Argument(value = "--enable", valueDescription = "<Phase>", description = "Enable backend phase")
|
||||
var enablePhases: Array<String>? = null
|
||||
|
||||
@Argument(value = "--list_phases", description = "List all backend phases")
|
||||
var listPhases: Boolean = false
|
||||
|
||||
|
||||
+5
-3
@@ -49,14 +49,16 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
|
||||
}
|
||||
}
|
||||
|
||||
private fun Distribution.prepareDependencies() {
|
||||
DependencyProcessor(java.io.File(dependenciesDir), targetProperties).run()
|
||||
private fun Distribution.prepareDependencies(checkDependencies: Boolean) {
|
||||
if (checkDependencies) {
|
||||
DependencyProcessor(java.io.File(dependenciesDir), targetProperties).run()
|
||||
}
|
||||
}
|
||||
|
||||
internal val distribution = Distribution(targetManager,
|
||||
configuration.get(KonanConfigKeys.PROPERTY_FILE),
|
||||
configuration.get(KonanConfigKeys.RUNTIME_FILE)).apply {
|
||||
prepareDependencies()
|
||||
prepareDependencies(configuration.getBoolean(KonanConfigKeys.CHECK_DEPENDENCIES))
|
||||
}
|
||||
|
||||
private val produce = configuration.get(KonanConfigKeys.PRODUCE)!!
|
||||
|
||||
+2
@@ -25,6 +25,8 @@ class KonanConfigKeys {
|
||||
// Keep the list lexically sorted.
|
||||
val ABI_VERSION: CompilerConfigurationKey<Int>
|
||||
= CompilerConfigurationKey.create("current abi version")
|
||||
val CHECK_DEPENDENCIES: CompilerConfigurationKey<Boolean>
|
||||
= CompilerConfigurationKey.create("check dependencies and download the missing ones")
|
||||
val DEBUG: CompilerConfigurationKey<Boolean>
|
||||
= CompilerConfigurationKey.create("add debug information")
|
||||
val DISABLED_PHASES: CompilerConfigurationKey<List<String>>
|
||||
|
||||
Reference in New Issue
Block a user