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.CompilerConfiguration
|
||||||
import org.jetbrains.kotlin.config.Services
|
import org.jetbrains.kotlin.config.Services
|
||||||
import org.jetbrains.kotlin.config.addKotlinSourceRoots
|
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.CompilerOutputKind
|
||||||
import org.jetbrains.kotlin.konan.target.TargetManager
|
import org.jetbrains.kotlin.konan.target.TargetManager
|
||||||
import org.jetbrains.kotlin.utils.KotlinPaths
|
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 {
|
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,
|
val environment = KotlinCoreEnvironment.createForProduction(rootDisposable,
|
||||||
configuration, EnvironmentConfigFiles.NATIVE_CONFIG_FILES)
|
configuration, EnvironmentConfigFiles.NATIVE_CONFIG_FILES)
|
||||||
val project = environment.project
|
val project = environment.project
|
||||||
@@ -50,16 +55,12 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
|||||||
return ExitCode.COMPILATION_ERROR
|
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.
|
// TODO: catch Errors and IllegalStateException.
|
||||||
return ExitCode.OK
|
return ExitCode.OK
|
||||||
}
|
}
|
||||||
|
|
||||||
val K2NativeCompilerArguments.isUsefulWithoutFreeArgs: Boolean
|
val K2NativeCompilerArguments.isUsefulWithoutFreeArgs: Boolean
|
||||||
get() = this.listTargets || this.listPhases
|
get() = this.listTargets || this.listPhases || this.checkDependencies
|
||||||
|
|
||||||
fun Array<String>?.toNonNullList(): List<String> {
|
fun Array<String>?.toNonNullList(): List<String> {
|
||||||
return this?.asList<String>() ?: listOf<String>()
|
return this?.asList<String>() ?: listOf<String>()
|
||||||
@@ -129,6 +130,13 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
|||||||
put(TIME_PHASES, arguments.timePhases)
|
put(TIME_PHASES, arguments.timePhases)
|
||||||
|
|
||||||
put(ENABLE_ASSERTIONS, arguments.enableAssertions)
|
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.
|
// Make sure to prepend them with a double dash.
|
||||||
// Keep the list lexically sorted.
|
// Keep the list lexically sorted.
|
||||||
|
|
||||||
@Argument(value = "--enable", valueDescription = "<Phase>", description = "Enable backend phase")
|
@Argument(value = "--check_dependencies", description = "Check dependencies and download the missing ones")
|
||||||
var enablePhases: Array<String>? = null
|
var checkDependencies: Boolean = false
|
||||||
|
|
||||||
@Argument(value = "--disable", valueDescription = "<Phase>", description = "Disable backend phase")
|
@Argument(value = "--disable", valueDescription = "<Phase>", description = "Disable backend phase")
|
||||||
var disablePhases: Array<String>? = null
|
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")
|
@Argument(value = "--list_phases", description = "List all backend phases")
|
||||||
var listPhases: Boolean = false
|
var listPhases: Boolean = false
|
||||||
|
|
||||||
|
|||||||
+5
-3
@@ -49,14 +49,16 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Distribution.prepareDependencies() {
|
private fun Distribution.prepareDependencies(checkDependencies: Boolean) {
|
||||||
DependencyProcessor(java.io.File(dependenciesDir), targetProperties).run()
|
if (checkDependencies) {
|
||||||
|
DependencyProcessor(java.io.File(dependenciesDir), targetProperties).run()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal val distribution = Distribution(targetManager,
|
internal val distribution = Distribution(targetManager,
|
||||||
configuration.get(KonanConfigKeys.PROPERTY_FILE),
|
configuration.get(KonanConfigKeys.PROPERTY_FILE),
|
||||||
configuration.get(KonanConfigKeys.RUNTIME_FILE)).apply {
|
configuration.get(KonanConfigKeys.RUNTIME_FILE)).apply {
|
||||||
prepareDependencies()
|
prepareDependencies(configuration.getBoolean(KonanConfigKeys.CHECK_DEPENDENCIES))
|
||||||
}
|
}
|
||||||
|
|
||||||
private val produce = configuration.get(KonanConfigKeys.PRODUCE)!!
|
private val produce = configuration.get(KonanConfigKeys.PRODUCE)!!
|
||||||
|
|||||||
+2
@@ -25,6 +25,8 @@ class KonanConfigKeys {
|
|||||||
// Keep the list lexically sorted.
|
// Keep the list lexically sorted.
|
||||||
val ABI_VERSION: CompilerConfigurationKey<Int>
|
val ABI_VERSION: CompilerConfigurationKey<Int>
|
||||||
= CompilerConfigurationKey.create("current abi version")
|
= CompilerConfigurationKey.create("current abi version")
|
||||||
|
val CHECK_DEPENDENCIES: CompilerConfigurationKey<Boolean>
|
||||||
|
= CompilerConfigurationKey.create("check dependencies and download the missing ones")
|
||||||
val DEBUG: CompilerConfigurationKey<Boolean>
|
val DEBUG: CompilerConfigurationKey<Boolean>
|
||||||
= CompilerConfigurationKey.create("add debug information")
|
= CompilerConfigurationKey.create("add debug information")
|
||||||
val DISABLED_PHASES: CompilerConfigurationKey<List<String>>
|
val DISABLED_PHASES: CompilerConfigurationKey<List<String>>
|
||||||
|
|||||||
Reference in New Issue
Block a user