From 30fd4060d372073b0fb8a47e629560be9511f210 Mon Sep 17 00:00:00 2001 From: Alexander Gorshenev Date: Thu, 20 Sep 2018 16:55:01 +0300 Subject: [PATCH] Provide a forced compiler version compatibility -X control. --- .../cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt | 3 +++ .../jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt | 5 ++++- .../src/org/jetbrains/kotlin/backend/konan/KonanConfig.kt | 8 +++++++- .../kotlin/backend/konan/KonanConfigurationKeys.kt | 2 ++ .../jetbrains/kotlin/konan/library/SearchPathResolver.kt | 5 +++-- 5 files changed, 19 insertions(+), 4 deletions(-) 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 71a4ca00965..b749ffc9e5e 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 @@ -175,6 +175,9 @@ class K2Native : CLICompiler() { put(LIST_PHASES, arguments.listPhases) put(TIME_PHASES, arguments.timePhases) + put(COMPATIBLE_COMPILER_VERSIONS, + arguments.compatibleCompilerVersions.toNonNullList()) + put(ENABLE_ASSERTIONS, arguments.enableAssertions) put(GENERATE_TEST_RUNNER, arguments.generateTestRunner) 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 5b9e8eafde1..9527cac7481 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 @@ -81,12 +81,15 @@ class K2NativeCompilerArguments : CommonCompilerArguments() { var target: String? = null // The rest of the options are only interesting to the developers. - // Make sure to prepend them with a double dash. + // Make sure to prepend them with -X. // Keep the list lexically sorted. @Argument(value="-Xcheck-dependencies", deprecatedName = "--check_dependencies", description = "Check dependencies and download the missing ones") var checkDependencies: Boolean = false + @Argument(value="-Xcompatible-compiler-version", valueDescription = "", description = "Assume the given compiler version to be binary compatible") + var compatibleCompilerVersions: Array? = null + @Argument(value = "-Xdisable", deprecatedName = "--disable", valueDescription = "", description = "Disable backend phase") var disablePhases: Array? = null 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 67c8712668f..9f26ccf28d1 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 @@ -21,7 +21,9 @@ import org.jetbrains.kotlin.konan.library.libraryResolver import org.jetbrains.kotlin.konan.properties.loadProperties import org.jetbrains.kotlin.konan.target.* import org.jetbrains.kotlin.konan.KonanAbiVersion +import org.jetbrains.kotlin.konan.KonanVersion import org.jetbrains.kotlin.konan.library.toUnresolvedLibraries +import org.jetbrains.kotlin.konan.parseKonanVersion class KonanConfig(val project: Project, val configuration: CompilerConfiguration) { @@ -76,12 +78,16 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration private val repositories = configuration.getList(KonanConfigKeys.REPOSITORIES) private fun resolverLogger(msg: String) = configuration.report(STRONG_WARNING, msg) + private val compatibleCompilerVersions: List = + configuration.getList(KonanConfigKeys.COMPATIBLE_COMPILER_VERSIONS).map { it.parseKonanVersion() } + private val resolver = defaultResolver( repositories, libraryNames.filter { it.contains(File.separator) }, target, distribution, - ::resolverLogger + ::resolverLogger, + compatibleCompilerVersions = compatibleCompilerVersions ).libraryResolver() internal val resolvedLibraries by lazy { 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 ad3dc414312..62ad8452c39 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 @@ -14,6 +14,8 @@ class KonanConfigKeys { // Keep the list lexically sorted. val CHECK_DEPENDENCIES: CompilerConfigurationKey = CompilerConfigurationKey.create("check dependencies and download the missing ones") + val COMPATIBLE_COMPILER_VERSIONS: CompilerConfigurationKey> + = CompilerConfigurationKey.create("compatible compiler versions") val DEBUG: CompilerConfigurationKey = CompilerConfigurationKey.create("add debug information") val DISABLED_PHASES: CompilerConfigurationKey> diff --git a/shared/src/library/kotlin/org/jetbrains/kotlin/konan/library/SearchPathResolver.kt b/shared/src/library/kotlin/org/jetbrains/kotlin/konan/library/SearchPathResolver.kt index 4a93de1f5a9..2613df0aa8d 100644 --- a/shared/src/library/kotlin/org/jetbrains/kotlin/konan/library/SearchPathResolver.kt +++ b/shared/src/library/kotlin/org/jetbrains/kotlin/konan/library/SearchPathResolver.kt @@ -39,13 +39,14 @@ fun defaultResolver( target: KonanTarget, distribution: Distribution, logger: Logger = ::dummyLogger, - skipCurrentDir: Boolean = false + skipCurrentDir: Boolean = false, + compatibleCompilerVersions: List = emptyList() ): SearchPathResolverWithTarget = KonanLibraryProperResolver( repositories, directLibs, target, listOf(KonanAbiVersion.CURRENT), - listOf(KonanVersion.CURRENT), + listOf(KonanVersion.CURRENT) + compatibleCompilerVersions, distribution.klib, distribution.localKonanDir.absolutePath, skipCurrentDir,