[Commonizer][test] Get K/N distribution in the test instead of the build
Get distribution and home path in the test to simplify gradle build. Using NativeCompilerDownloader in the build led to the undesired results where test get old K/N compiler from the bootstrap, also blocking K/N version class development.
This commit is contained in:
@@ -1,18 +1,3 @@
|
||||
import org.jetbrains.kotlin.gradle.utils.NativeCompilerDownloader
|
||||
|
||||
buildscript {
|
||||
val cacheRedirectorEnabled = findProperty("cacheRedirectorEnabled")?.toString()?.toBoolean() ?: false
|
||||
dependencies {
|
||||
classpath("org.jetbrains.kotlin:kotlin-build-gradle-plugin:0.0.36")
|
||||
}
|
||||
repositories {
|
||||
if (cacheRedirectorEnabled)
|
||||
maven("https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies")
|
||||
else
|
||||
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies")
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
id("jps-compatible")
|
||||
@@ -32,6 +17,11 @@ dependencies {
|
||||
testImplementation(commonDependency("junit:junit"))
|
||||
testImplementation(projectTests(":compiler:tests-common"))
|
||||
testRuntimeOnly(project(":native:kotlin-klib-commonizer"))
|
||||
testImplementation(project(":kotlin-gradle-plugin"))
|
||||
testImplementation(project(":kotlin-gradle-plugin-model"))
|
||||
testImplementation(gradleApi())
|
||||
testImplementation(gradleTestKit())
|
||||
testImplementation(gradleKotlinDsl())
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
@@ -39,57 +29,9 @@ sourceSets {
|
||||
"test" { projectDefault() }
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: This version hack on migrating period K/N into repository Kotlin, in new build infrostructure zero maintance claus isn't dropped,
|
||||
* so for old builds we need to keep this version to string representation till total switch on new infrostructure.
|
||||
*/
|
||||
val konanVersion = object : org.jetbrains.kotlin.konan.CompilerVersion by NativeCompilerDownloader.DEFAULT_KONAN_VERSION {
|
||||
override fun toString(showMeta: Boolean, showBuild: Boolean) = buildString {
|
||||
if (major > 1
|
||||
|| minor > 5
|
||||
|| maintenance > 20
|
||||
)
|
||||
return NativeCompilerDownloader.DEFAULT_KONAN_VERSION.toString(showMeta, showBuild)
|
||||
append(major)
|
||||
append('.')
|
||||
append(minor)
|
||||
if (maintenance != 0) {
|
||||
append('.')
|
||||
append(maintenance)
|
||||
}
|
||||
if (milestone != -1) {
|
||||
append("-M")
|
||||
append(milestone)
|
||||
}
|
||||
if (showMeta) {
|
||||
append('-')
|
||||
append(meta.metaString)
|
||||
}
|
||||
if (showBuild && build != -1) {
|
||||
append('-')
|
||||
append(build)
|
||||
}
|
||||
}
|
||||
|
||||
override fun toString() = toString(
|
||||
meta != org.jetbrains.kotlin.konan.MetaVersion.RELEASE,
|
||||
meta != org.jetbrains.kotlin.konan.MetaVersion.RELEASE
|
||||
)
|
||||
}
|
||||
|
||||
tasks.register("downloadNativeCompiler") {
|
||||
doFirst {
|
||||
if (NativeCompilerDownloader(project, konanVersion).compilerDirectory.exists()) return@doFirst
|
||||
NativeCompilerDownloader(project, konanVersion).downloadIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
projectTest(parallel = false) {
|
||||
dependsOn(":dist")
|
||||
dependsOn("downloadNativeCompiler")
|
||||
workingDir = projectDir
|
||||
environment("KONAN_HOME", NativeCompilerDownloader(project, konanVersion).compilerDirectory.absolutePath)
|
||||
}
|
||||
|
||||
runtimeJar()
|
||||
|
||||
@@ -5,10 +5,28 @@
|
||||
|
||||
package org.jetbrains.kotlin.commonizer.utils
|
||||
|
||||
import org.gradle.api.internal.project.ProjectInternal
|
||||
import org.gradle.testfixtures.ProjectBuilder
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
||||
import org.jetbrains.kotlin.gradle.utils.NativeCompilerDownloader
|
||||
import java.io.File
|
||||
|
||||
internal val konanHome: File
|
||||
get() {
|
||||
val konanHomePath = System.getenv("KONAN_HOME")?.toString() ?: error("Missing KONAN_HOME environment variable")
|
||||
return File(konanHomePath)
|
||||
}
|
||||
internal val konanHome: File by lazy {
|
||||
val project = ProjectBuilder
|
||||
.builder()
|
||||
.build()
|
||||
?.run {
|
||||
project.plugins.apply("kotlin-multiplatform")
|
||||
|
||||
(project.kotlinExtension as KotlinMultiplatformExtension).apply {
|
||||
macosX64()
|
||||
macosArm64()
|
||||
linuxX64()
|
||||
mingwX64()
|
||||
}
|
||||
this
|
||||
} as ProjectInternal
|
||||
project.evaluate()
|
||||
NativeCompilerDownloader(project).compilerDirectory
|
||||
}
|
||||
Reference in New Issue
Block a user