diff --git a/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt b/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt index 51cb414c2fc..99d8c80c5e3 100644 --- a/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt +++ b/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt @@ -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() { 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() { 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?.toNonNullList(): List { return this?.asList() ?: listOf() @@ -129,6 +130,13 @@ class K2Native : CLICompiler() { 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 + }) } } } diff --git a/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt b/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt index fe405514e7d..b790f0e4d12 100644 --- a/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt +++ b/backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt @@ -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 = "", description = "Enable backend phase") - var enablePhases: Array? = null + @Argument(value = "--check_dependencies", description = "Check dependencies and download the missing ones") + var checkDependencies: Boolean = false @Argument(value = "--disable", valueDescription = "", description = "Disable backend phase") var disablePhases: Array? = null + @Argument(value = "--enable", valueDescription = "", description = "Enable backend phase") + var enablePhases: Array? = null + @Argument(value = "--list_phases", description = "List all backend phases") var listPhases: Boolean = false diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt index 0376d03ac0b..29024c7bd7c 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt @@ -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)!! diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfigurationKeys.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfigurationKeys.kt index 8be963dd725..493a462da38 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfigurationKeys.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanConfigurationKeys.kt @@ -25,6 +25,8 @@ class KonanConfigKeys { // Keep the list lexically sorted. val ABI_VERSION: CompilerConfigurationKey = CompilerConfigurationKey.create("current abi version") + val CHECK_DEPENDENCIES: CompilerConfigurationKey + = CompilerConfigurationKey.create("check dependencies and download the missing ones") val DEBUG: CompilerConfigurationKey = CompilerConfigurationKey.create("add debug information") val DISABLED_PHASES: CompilerConfigurationKey>