[K/N] Remove old Compiler and Meta Version ^KT-55677 Fixed

* Replace it with KotlinCompilerVersion
* K/N version should be set now with `deployVersion`.
* Cleanup deprecated functions in older versions
 of the Gradle plugin
* Cleanup tests for older versions of compiler downloader

Merge-request: KT-MR-8436
Merged-by: Pavel Punegov <Pavel.Punegov@jetbrains.com>
This commit is contained in:
Pavel Punegov
2023-01-30 13:10:08 +00:00
committed by Space Team
parent 5ec626b29d
commit c9aeadd31f
33 changed files with 79 additions and 727 deletions
@@ -14,10 +14,6 @@ import org.jetbrains.kotlin.gradle.transformProjectWithPluginsDsl
import org.jetbrains.kotlin.gradle.util.modify
import org.jetbrains.kotlin.gradle.utils.NativeCompilerDownloader
import org.jetbrains.kotlin.gradle.utils.Xcode
import org.jetbrains.kotlin.konan.CompilerVersion
import org.jetbrains.kotlin.konan.CompilerVersionImpl
import org.jetbrains.kotlin.konan.MetaVersion
import org.jetbrains.kotlin.konan.isAtLeast
import org.jetbrains.kotlin.konan.target.HostManager
import org.jetbrains.kotlin.konan.target.KonanTarget
import org.jetbrains.kotlin.konan.target.presetName
@@ -46,7 +42,6 @@ class NativeDownloadAndPlatformLibsIT : BaseGradleIT() {
override val defaultGradleVersion: GradleVersionRequired
get() = GradleVersionRequired.FOR_MPP_SUPPORT
private val oldCompilerVersion = "1.3.61"
private val currentCompilerVersion = NativeCompilerDownloader.DEFAULT_KONAN_VERSION
private fun platformLibrariesProject(vararg targets: String): Project =
@@ -62,26 +57,16 @@ class NativeDownloadAndPlatformLibsIT : BaseGradleIT() {
}
}
private fun simpleOsName(compilerVersion: CompilerVersion): String =
if (compilerVersion.isAtLeast(CompilerVersionImpl(major = 1, minor = 5, maintenance = 30, build = 1466))) {
HostManager.platformName()
} else {
HostManager.simpleOsName()
}
private val platformName: String = HostManager.platformName()
@BeforeTest
fun deleteInstalledCompilers() {
val oldOsName = simpleOsName(CompilerVersion.fromString(oldCompilerVersion))
val currentOsName = simpleOsName(currentCompilerVersion)
val oldCompilerDir = DependencyDirectories.localKonanDir
.resolve("kotlin-native-$oldOsName-$oldCompilerVersion")
val currentCompilerDir = DependencyDirectories.localKonanDir
.resolve("kotlin-native-$currentOsName-$currentCompilerVersion")
.resolve("kotlin-native-$platformName-$currentCompilerVersion")
val prebuiltDistDir = DependencyDirectories.localKonanDir
.resolve("kotlin-native-prebuilt-$currentOsName-$currentCompilerVersion")
.resolve("kotlin-native-prebuilt-$platformName-$currentCompilerVersion")
for (compilerDirectory in listOf(oldCompilerDir, currentCompilerDir, prebuiltDistDir)) {
for (compilerDirectory in listOf(currentCompilerDir, prebuiltDistDir)) {
compilerDirectory.deleteRecursively()
}
}
@@ -89,19 +74,6 @@ class NativeDownloadAndPlatformLibsIT : BaseGradleIT() {
private fun Project.buildWithLightDist(vararg tasks: String, check: CompiledProject.() -> Unit) =
build(*tasks, "-Pkotlin.native.distribution.type=light", check = check)
@Test
fun testNoGenerationForOldCompiler() = with(platformLibrariesProject("linuxX64")) {
// Check that we don't run the library generator for old compiler distributions where libraries are prebuilt.
// Don't run the build to reduce execution time.
build("tasks", "-Pkotlin.native.version=$oldCompilerVersion") {
assertSuccessful()
assertContains("Unpack Kotlin/Native compiler to ")
val osName = simpleOsName(CompilerVersion.fromString(oldCompilerVersion))
assertContainsRegex("Kotlin/Native distribution: .*kotlin-native-$osName".toRegex())
assertNotContains("Generate platform libraries for ")
}
}
@Test
fun testNoGenerationByDefault() = with(platformLibrariesProject("linuxX64")) {
@@ -109,8 +81,7 @@ class NativeDownloadAndPlatformLibsIT : BaseGradleIT() {
// Check that a prebuilt distribution is used by default.
build("assemble") {
assertSuccessful()
val osName = simpleOsName(currentCompilerVersion)
assertContainsRegex("Kotlin/Native distribution: .*kotlin-native-prebuilt-$osName".toRegex())
assertContainsRegex("Kotlin/Native distribution: .*kotlin-native-prebuilt-$platformName".toRegex())
assertNotContains("Generate platform libraries for ")
}
}
@@ -132,8 +103,7 @@ class NativeDownloadAndPlatformLibsIT : BaseGradleIT() {
// Check that platform libraries are correctly generated for both root project and a subproject.
buildWithLightDist("assemble") {
assertSuccessful()
val osName = simpleOsName(currentCompilerVersion)
assertContainsRegex("Kotlin/Native distribution: .*kotlin-native-$osName".toRegex())
assertContainsRegex("Kotlin/Native distribution: .*kotlin-native-$platformName".toRegex())
assertContains("Generate platform libraries for linux_x64")
assertContains("Generate platform libraries for linux_arm64")
}
@@ -196,57 +166,18 @@ class NativeDownloadAndPlatformLibsIT : BaseGradleIT() {
fun testCanUsePrebuiltDistribution() = with(platformLibrariesProject("linuxX64")) {
build("assemble", "-Pkotlin.native.distribution.type=prebuilt") {
assertSuccessful()
val osName = simpleOsName(currentCompilerVersion)
assertContainsRegex("Kotlin/Native distribution: .*kotlin-native-prebuilt-$osName".toRegex())
assertContainsRegex("Kotlin/Native distribution: .*kotlin-native-prebuilt-$platformName".toRegex())
assertNotContains("Generate platform libraries for ")
}
}
@Test
fun testDeprecatedRestrictedDistributionProperty() = with(platformLibrariesProject("linuxX64")) {
build("tasks", "-Pkotlin.native.restrictedDistribution=true", "-Pkotlin.native.version=$oldCompilerVersion") {
assertSuccessful()
assertContains("Warning: Project property 'kotlin.native.restrictedDistribution' is deprecated. Please use 'kotlin.native.distribution.type=light' instead")
val osName = simpleOsName(CompilerVersion.fromString(oldCompilerVersion))
val regex = "Kotlin/Native distribution: .*kotlin-native-restricted-$osName".toRegex()
// Restricted distribution is available for Mac hosts only.
if (HostManager.hostIsMac) {
assertContainsRegex(regex)
} else {
assertNotContains(regex)
}
}
// We allow using this deprecated property for 1.4 too. Just download the distribution without platform libs in this case.
build("tasks", "-Pkotlin.native.restrictedDistribution=true") {
assertSuccessful()
val osName = simpleOsName(currentCompilerVersion)
assertContains("Warning: Project property 'kotlin.native.restrictedDistribution' is deprecated. Please use 'kotlin.native.distribution.type=light' instead")
assertContainsRegex("Kotlin/Native distribution: .*kotlin-native-$osName".toRegex())
}
}
@Test
fun testSettingDistributionTypeForOldCompiler() = with(platformLibrariesProject("linuxX64")) {
build("tasks", "-Pkotlin.native.distribution.type=prebuilt", "-Pkotlin.native.version=$oldCompilerVersion") {
assertSuccessful()
val osName = simpleOsName(CompilerVersion.fromString(oldCompilerVersion))
val regex = "Kotlin/Native distribution: .*kotlin-native-$osName".toRegex()
assertContainsRegex(regex)
}
build("tasks", "-Pkotlin.native.distribution.type=light", "-Pkotlin.native.version=$oldCompilerVersion") {
assertSuccessful()
val osName = simpleOsName(CompilerVersion.fromString(oldCompilerVersion))
val regex = "Kotlin/Native distribution: .*kotlin-native-restricted-$osName".toRegex()
// Restricted distribution is available for Mac hosts only.
if (HostManager.hostIsMac) {
assertContainsRegex(regex)
} else {
assertNotContains(regex)
}
assertContainsRegex("Kotlin/Native distribution: .*kotlin-native-$platformName".toRegex())
}
}
@@ -275,11 +206,15 @@ class NativeDownloadAndPlatformLibsIT : BaseGradleIT() {
}
}
private fun mavenUrl(): String = when (currentCompilerVersion.meta) {
MetaVersion.DEV -> KOTLIN_SPACE_DEV
MetaVersion.RELEASE, MetaVersion.RC, MetaVersion("RC2"), MetaVersion.BETA ->
if (currentCompilerVersion.build != -1) KOTLIN_SPACE_DEV else MAVEN_CENTRAL
else -> throw IllegalStateException("Not a published version $currentCompilerVersion")
private fun mavenUrl(): String {
val versionPattern = "(\\d+)\\.(\\d+)(?:\\.(\\d+))?(?:-(\\p{Alpha}*\\p{Alnum}|[\\p{Alpha}-]*))?(?:-(\\d+))?".toRegex()
val (_, _, _, metaString, build) = versionPattern.matchEntire(currentCompilerVersion)?.destructured
?: error("Unable to parse version $currentCompilerVersion")
return when {
metaString == "dev" || build.isNotEmpty() -> KOTLIN_SPACE_DEV
metaString in listOf("RC", "RC2", "Beta") || metaString.isEmpty() -> MAVEN_CENTRAL
else -> throw IllegalStateException("Not a published version $currentCompilerVersion")
}
}
@Test
@@ -12,11 +12,9 @@ import org.jetbrains.kotlin.gradle.dsl.NativeCacheKind
import org.jetbrains.kotlin.gradle.dsl.NativeCacheOrchestration
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.useXcodeMessageStyle
import org.jetbrains.kotlin.gradle.plugin.mpp.isAtLeast
import org.jetbrains.kotlin.gradle.plugin.mpp.nativeUseEmbeddableCompilerJar
import org.jetbrains.kotlin.gradle.targets.native.KonanPropertiesBuildService
import org.jetbrains.kotlin.gradle.utils.NativeCompilerDownloader
import org.jetbrains.kotlin.konan.CompilerVersion
import org.jetbrains.kotlin.konan.properties.resolvablePropertyString
import org.jetbrains.kotlin.konan.target.HostManager
import org.jetbrains.kotlin.konan.target.KonanTarget
@@ -35,8 +33,8 @@ internal val Project.konanHome: String
internal val Project.disableKonanDaemon: Boolean
get() = PropertiesProvider(this).nativeDisableCompilerDaemon == true
internal val Project.konanVersion: CompilerVersion
get() = PropertiesProvider(this).nativeVersion?.let { CompilerVersion.fromString(it) }
internal val Project.konanVersion: String
get() = PropertiesProvider(this).nativeVersion
?: NativeCompilerDownloader.DEFAULT_KONAN_VERSION
internal fun Project.getKonanCacheKind(target: KonanTarget): NativeCacheKind {
@@ -67,7 +65,7 @@ internal abstract class KotlinNativeToolRunner(
) : KotlinToolRunner(executionContext) {
class Settings(
val konanVersion: CompilerVersion,
val konanVersion: String,
val konanHome: String,
val konanPropertiesFile: File,
val useXcodeMessageStyle: Boolean,
@@ -102,16 +100,8 @@ internal abstract class KotlinNativeToolRunner(
}
final override val execSystemProperties by lazy {
// Still set konan.home for versions prior to 1.4-M3.
val konanHomeRequired = !settings.konanVersion.isAtLeast(1, 4, 0) ||
settings.konanVersion.toString(showMeta = false, showBuild = false) in listOf("1.4-M1", "1.4-M2")
val messageRenderer = if (settings.useXcodeMessageStyle) MessageRenderer.XCODE_STYLE else MessageRenderer.GRADLE_STYLE
listOfNotNull(
if (konanHomeRequired) "konan.home" to settings.konanHome else null,
MessageRenderer.PROPERTY_KEY to messageRenderer.name
).toMap()
mapOf(MessageRenderer.PROPERTY_KEY to messageRenderer.name)
}
final override val classpath get() = settings.classpath.files
@@ -16,7 +16,6 @@ import org.jetbrains.kotlin.gradle.targets.native.DisabledNativeTargetsReporter
import org.jetbrains.kotlin.gradle.targets.native.internal.*
import org.jetbrains.kotlin.gradle.utils.SingleActionPerProject
import org.jetbrains.kotlin.gradle.utils.setupNativeCompiler
import org.jetbrains.kotlin.konan.CompilerVersion
import org.jetbrains.kotlin.konan.target.HostManager
import org.jetbrains.kotlin.konan.target.KonanTarget
@@ -119,9 +118,3 @@ internal val KonanTarget.isCurrentHost: Boolean
internal val KonanTarget.enabledOnCurrentHost
get() = HostManager().isEnabled(this)
// KonanVersion doesn't provide an API to compare versions,
// so we have to transform it to KotlinVersion first.
// Note: this check doesn't take into account the meta version (release, eap, dev).
internal fun CompilerVersion.isAtLeast(major: Int, minor: Int, patch: Int): Boolean =
KotlinVersion(this.major, this.minor, this.maintenance).isAtLeast(major, minor, patch)
@@ -19,10 +19,6 @@ import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.kotlinPro
import org.jetbrains.kotlin.gradle.targets.native.internal.NativeDistributionType
import org.jetbrains.kotlin.gradle.targets.native.internal.NativeDistributionTypeProvider
import org.jetbrains.kotlin.gradle.targets.native.internal.PlatformLibrariesGenerator
import org.jetbrains.kotlin.konan.CompilerVersion
import org.jetbrains.kotlin.konan.CompilerVersionImpl
import org.jetbrains.kotlin.konan.MetaVersion
import org.jetbrains.kotlin.konan.isAtLeast
import org.jetbrains.kotlin.konan.target.HostManager
import org.jetbrains.kotlin.konan.target.KonanTarget
import org.jetbrains.kotlin.konan.util.DependencyDirectories
@@ -31,12 +27,12 @@ import java.nio.file.Files
class NativeCompilerDownloader(
val project: Project,
private val compilerVersion: CompilerVersion = project.konanVersion
private val compilerVersion: String = project.konanVersion
) {
companion object {
val DEFAULT_KONAN_VERSION: CompilerVersion by lazy {
CompilerVersion.fromString(loadPropertyFromResources("project.properties", "kotlin.native.version"))
val DEFAULT_KONAN_VERSION: String by lazy {
loadPropertyFromResources("project.properties", "kotlin.native.version")
}
internal const val BASE_DOWNLOAD_URL = "https://download.jetbrains.com/kotlin/native/builds"
@@ -55,13 +51,7 @@ class NativeCompilerDownloader(
get() = NativeDistributionTypeProvider(project).getDistributionType(compilerVersion)
private val simpleOsName: String
get() {
return if (compilerVersion.isAtLeast(CompilerVersionImpl(major = 1, minor = 5, maintenance = 30, build = 1466))) {
HostManager.platformName()
} else {
HostManager.simpleOsName()
}
}
get() = HostManager.platformName()
private val dependencyName: String
get() {
@@ -115,7 +105,7 @@ class NativeCompilerDownloader(
private val repoUrl by lazy {
buildString {
append("${kotlinProperties.nativeBaseDownloadUrl}/")
append(if (compilerVersion.meta == MetaVersion.DEV) "dev/" else "releases/")
append(if (compilerVersion.contains("-dev-")) "dev/" else "releases/")
append("$compilerVersion/")
append(simpleOsName)
}
@@ -7,11 +7,8 @@ package org.jetbrains.kotlin.gradle.targets.native.internal
import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
import org.jetbrains.kotlin.gradle.plugin.mpp.isAtLeast
import org.jetbrains.kotlin.gradle.targets.native.internal.NativeDistributionType.*
import org.jetbrains.kotlin.gradle.utils.SingleWarningPerBuild
import org.jetbrains.kotlin.konan.CompilerVersion
import org.jetbrains.kotlin.konan.target.HostManager
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly
internal enum class NativeDistributionType(val suffix: String?, val mustGeneratePlatformLibs: Boolean) {
@@ -59,19 +56,11 @@ internal class NativeDistributionTypeProvider(private val project: Project) {
}
}
fun getDistributionType(version: CompilerVersion): NativeDistributionType {
fun getDistributionType(version: String): NativeDistributionType {
if (propertiesProvider.nativeDeprecatedRestricted != null) {
warning("Project property 'kotlin.native.restrictedDistribution' is deprecated. Please use 'kotlin.native.distribution.type=light' instead")
}
return if (version.isAtLeast(1, 4, 0)) {
chooseDistributionType(prebuiltType = PREBUILT, lightType = LIGHT, defaultType = PREBUILT)
} else {
// In 1.3, the distribution type can be chosen for Mac hosts only.
if (!HostManager.hostIsMac) {
return PREBUILT_1_3
}
chooseDistributionType(prebuiltType = PREBUILT_1_3, lightType = LIGHT_1_3, defaultType = PREBUILT_1_3)
}
return chooseDistributionType(prebuiltType = PREBUILT, lightType = LIGHT, defaultType = PREBUILT)
}
}
@@ -42,7 +42,6 @@ import org.jetbrains.kotlin.gradle.targets.native.internal.isAllowCommonizer
import org.jetbrains.kotlin.gradle.targets.native.tasks.*
import org.jetbrains.kotlin.gradle.utils.*
import org.jetbrains.kotlin.gradle.utils.listFilesOrEmpty
import org.jetbrains.kotlin.konan.CompilerVersion
import org.jetbrains.kotlin.konan.library.KLIB_INTEROP_IR_PROVIDER_IDENTIFIER
import org.jetbrains.kotlin.konan.properties.saveToFile
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
@@ -522,17 +521,11 @@ internal class ExternalDependenciesBuilder(
get() = KonanPropertiesBuildService.registerIfAbsent(project).get()
fun buildCompilerArgs(): List<String> {
val compilerVersion = Distribution.getCompilerVersion(konanPropertiesService.compilerVersion, project.konanHome)
val konanVersion = compilerVersion?.let(CompilerVersion.Companion::fromString)
?: project.konanVersion
if (konanVersion.isAtLeast(1, 6, 0)) {
val dependenciesFile = writeDependenciesFile(buildDependencies(), deleteOnExit = true)
if (dependenciesFile != null)
return listOf("-Xexternal-dependencies=${dependenciesFile.path}")
}
return emptyList()
val dependenciesFile = writeDependenciesFile(buildDependencies(), deleteOnExit = true)
return if (dependenciesFile != null)
listOf("-Xexternal-dependencies=${dependenciesFile.path}")
else
emptyList()
}
private fun buildDependencies(): Collection<KResolvedDependency> {
@@ -989,7 +982,7 @@ open class CInteropProcess @Inject internal constructor(params: Params) : Defaul
val konanTarget: KonanTarget = params.konanTarget
@get:Input
val konanVersion: CompilerVersion = project.konanVersion
val konanVersion: String = project.konanVersion
@Suppress("unused")
@get:Input
@@ -1092,10 +1085,7 @@ open class CInteropProcess @Inject internal constructor(params: Params) : Defaul
addArgs("-compiler-option", allHeadersDirs.map { "-I${it.absolutePath}" })
addArgs("-headerFilterAdditionalSearchPrefix", headerFilterDirs.map { it.absolutePath })
if (konanVersion.isAtLeast(1, 4, 0)) {
addArg("-Xmodule-name", moduleName)
}
addArg("-Xmodule-name", moduleName)
// TODO: uncomment after advancing bootstrap.
//addArg("-libraryVersion", libraryVersion)
@@ -20,11 +20,8 @@ import org.jetbrains.kotlin.compilerRunner.konanVersion
import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessagesClientSettings
import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessagesTestExecutionSpec
import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessagesTestExecutor.Companion.TC_PROJECT_PROPERTY
import org.jetbrains.kotlin.gradle.plugin.mpp.isAtLeast
import org.jetbrains.kotlin.gradle.targets.native.internal.parseKotlinNativeStackTraceAsJvm
import org.jetbrains.kotlin.gradle.tasks.KotlinTest
import org.jetbrains.kotlin.gradle.utils.isConfigurationCacheAvailable
import org.jetbrains.kotlin.gradle.utils.property
import java.io.File
import java.util.concurrent.Callable
import javax.inject.Inject
@@ -152,9 +149,7 @@ abstract class KotlinNativeTest: KotlinTest() {
// The KotlinTest expects that the exit code is zero even if some tests failed.
// In this case it can check exit code and distinguish test failures from crashes.
// But K/N allows forcing a zero exit code only since 1.3 (which was included in Kotlin 1.3.40).
// Thus we check the exit code only for newer versions.
val checkExitCode = konanVersion.isAtLeast(1, 3, 0)
val checkExitCode = true
val cliArgs = testCommand.cliArgs("TEAMCITY", checkExitCode, includePatterns, excludePatterns, args)