[K/N][gradle][test] Tests KGP ability to download artifacts from maven
This commit is contained in:
committed by
Space Team
parent
5c6af6559a
commit
82d28b6dbf
+123
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.native
|
||||
|
||||
import org.jetbrains.kotlin.gradle.BaseGradleIT
|
||||
import org.jetbrains.kotlin.gradle.GradleVersionRequired
|
||||
import org.jetbrains.kotlin.gradle.utils.NativeCompilerDownloader
|
||||
import org.jetbrains.kotlin.konan.MetaVersion
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
import org.jetbrains.kotlin.konan.util.DependencyDirectories
|
||||
|
||||
import kotlin.test.BeforeTest
|
||||
import kotlin.test.Test
|
||||
|
||||
class NativeDownloadIT : BaseGradleIT() {
|
||||
override val defaultGradleVersion = GradleVersionRequired.FOR_MPP_SUPPORT
|
||||
|
||||
private val currentCompilerVersion = NativeCompilerDownloader.DEFAULT_KONAN_VERSION
|
||||
|
||||
companion object {
|
||||
private const val KOTLIN_SPACE_DEV = "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev"
|
||||
private const val MAVEN_CENTRAL = "https://cache-redirector.jetbrains.com/maven-central"
|
||||
}
|
||||
|
||||
private fun mavenUrl(): String = when (currentCompilerVersion.meta) {
|
||||
MetaVersion.DEV -> KOTLIN_SPACE_DEV
|
||||
MetaVersion.RELEASE, MetaVersion.RC, MetaVersion("RC2"), MetaVersion.BETA -> MAVEN_CENTRAL
|
||||
else -> throw IllegalStateException("Not a published version $currentCompilerVersion")
|
||||
}
|
||||
|
||||
@BeforeTest
|
||||
fun deleteInstalledDistributions() {
|
||||
val currentOsName = HostManager.platformName()
|
||||
val lightDistDir = DependencyDirectories.localKonanDir
|
||||
.resolve("kotlin-native-$currentOsName-$currentCompilerVersion")
|
||||
val prebuiltDistDir = DependencyDirectories.localKonanDir
|
||||
.resolve("kotlin-native-prebuilt-$currentOsName-$currentCompilerVersion")
|
||||
|
||||
listOf(lightDistDir, prebuiltDistDir).forEach {
|
||||
it.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `download prebuilt Native bundle with maven`() {
|
||||
with(transformNativeTestProjectWithPluginDsl("native-download-maven")) {
|
||||
gradleProperties().appendText(
|
||||
"""
|
||||
kotlin.native.distribution.baseDownloadUrl=${mavenUrl()}
|
||||
kotlin.native.distribution.downloadFromMaven=true
|
||||
""".trimIndent()
|
||||
)
|
||||
build("assemble") {
|
||||
assertSuccessful()
|
||||
assertContains("Unpack Kotlin/Native compiler to ")
|
||||
assertNotContains("Generate platform libraries for ")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `download light Native bundle with maven`() {
|
||||
with(transformNativeTestProjectWithPluginDsl("native-download-maven")) {
|
||||
gradleProperties().appendText(
|
||||
"""
|
||||
kotlin.native.distribution.baseDownloadUrl=${mavenUrl()}
|
||||
kotlin.native.distribution.downloadFromMaven=true
|
||||
""".trimIndent()
|
||||
)
|
||||
build("assemble", "-Pkotlin.native.distribution.type=light") {
|
||||
assertSuccessful()
|
||||
assertContains("Unpack Kotlin/Native compiler to ")
|
||||
assertContains("Generate platform libraries for ")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `download from maven specified in the build`() {
|
||||
with(transformNativeTestProjectWithPluginDsl("native-download-maven")) {
|
||||
gradleProperties().appendText(
|
||||
"""
|
||||
kotlin.native.distribution.downloadFromMaven=true
|
||||
""".trimIndent()
|
||||
)
|
||||
gradleBuildScript().let {
|
||||
val text = it.readText()
|
||||
.replaceFirst(
|
||||
"mavenLocal()",
|
||||
"""
|
||||
mavenLocal()
|
||||
maven("${mavenUrl()}")
|
||||
""".trimIndent()
|
||||
)
|
||||
it.writeText(text)
|
||||
}
|
||||
|
||||
build("assemble") {
|
||||
assertSuccessful()
|
||||
assertContains("Unpack Kotlin/Native compiler to ")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `download from maven should fall if there is no such build in the default repos`() {
|
||||
with(transformNativeTestProjectWithPluginDsl("native-download-maven")) {
|
||||
gradleProperties().appendText(
|
||||
"""
|
||||
kotlin.native.version=1.8.0-dev-1234
|
||||
kotlin.native.distribution.downloadFromMaven=true
|
||||
""".trimIndent()
|
||||
)
|
||||
build("assemble") {
|
||||
assertContains("Could not find org.jetbrains.kotlin:kotlin-native")
|
||||
assertFailed()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
||||
|
||||
plugins {
|
||||
kotlin("multiplatform").version("<pluginMarkerVersion>")
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
kotlin {
|
||||
val nativeMain by sourceSets.creating {
|
||||
dependsOn(sourceSets["commonMain"])
|
||||
}
|
||||
|
||||
targets.withType(KotlinNativeTarget::class.java).all {
|
||||
compilations["main"].defaultSourceSet.dependsOn(nativeMain)
|
||||
}
|
||||
|
||||
<SingleNativeTarget>("host") {
|
||||
binaries {
|
||||
executable()
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
kotlin.native.cacheKind=none
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
import platform.posix.*
|
||||
|
||||
fun main() {
|
||||
printf("Hello world %d", 42)
|
||||
}
|
||||
Reference in New Issue
Block a user