[Gradle, Native] Switched downloading k/n to from Maven Central in KGP

#KT-62907 Fixed
This commit is contained in:
Dmitrii Krasnov
2023-11-03 17:58:39 +01:00
committed by Space Team
parent c5d1c4e816
commit f8507d5220
11 changed files with 57 additions and 82 deletions
@@ -275,6 +275,8 @@ abstract class BaseGradleIT {
val showDiagnosticsStacktrace: Boolean? = false, // false by default to not clutter the testdata + stacktraces change often
val stacktraceMode: String? = StacktraceOption.FULL_STACKTRACE_LONG_OPTION,
val konanDataDir: Path = konanDir,
// TODO(Dmitrii Krasnov): we can remove this, when downloading konan from maven local will be possible KT-63198
val distributionDownloadFromMaven: Boolean? = false,
) {
val safeAndroidGradlePluginVersion: AGPVersion
get() = androidGradlePluginVersion ?: error("AGP version is expected to be set")
@@ -1004,6 +1006,10 @@ abstract class BaseGradleIT {
add("-Pkonan.data.dir=${options.konanDataDir.absolutePathString().normalize()}")
options.distributionDownloadFromMaven?.let {
add("-Pkotlin.native.distribution.downloadFromMaven=${it}")
}
// Workaround: override a console type set in the user machine gradle.properties (since Gradle 4.3):
add("--console=plain")
//The feature of failing the build on deprecation warnings is introduced in gradle 5.6
@@ -810,45 +810,29 @@ class GeneralNativeIT : KGPBaseTest() {
}
@DisplayName("Checks builds with changing compiler version")
@OptIn(EnvironmentalVariablesOverride::class)
@GradleTestVersions(minVersion = TestVersions.Gradle.G_7_0)
@GradleTestVersions
@GradleTest
fun testCompilerVersionChange(gradleVersion: GradleVersion) {
if (KotlinToolingVersion(TestVersions.Kotlin.STABLE_RELEASE) < KotlinToolingVersion("1.9.20-Beta")) {
val konanDataDir = defaultBuildOptions.konanDataDir?.toAbsolutePath()?.normalize()?.absolutePathString()
?: error("konanDataDir must not be null in this test. Please set a custom konanDataDir property.")
nativeProject("native-compiler-version", gradleVersion) {
val compileTasks = ":compileKotlinHost"
nativeProject(
"native-compiler-version",
gradleVersion,
environmentVariables = EnvironmentalVariables(mapOf("KONAN_DATA_DIR" to konanDataDir)),
) {
val compileTasks = ":compileKotlinHost"
build(compileTasks) {
assertTasksExecuted(compileTasks)
}
build(compileTasks) {
assertTasksUpToDate(compileTasks)
}
// Check that changing K/N version lead to tasks rerun
build(
compileTasks, buildOptions = defaultBuildOptions.copy(
nativeOptions = defaultBuildOptions.nativeOptions.copy(version = TestVersions.Kotlin.STABLE_RELEASE)
)
) {
assertTasksExecuted(compileTasks)
}
build(compileTasks) {
assertTasksExecuted(compileTasks)
}
} else {
fail(
"Please remove setting KONAN_DATA_DIR environment variable," +
" because Kotlin stable release now supports konan.data.dir Gradle property."
)
}
build(compileTasks) {
assertTasksUpToDate(compileTasks)
}
// Check that changing K/N version lead to tasks rerun
build(
compileTasks, buildOptions = defaultBuildOptions.copy(
nativeOptions = defaultBuildOptions.nativeOptions.copy(version = TestVersions.Kotlin.STABLE_RELEASE)
)
) {
assertTasksExecuted(compileTasks)
}
}
}
@DisplayName("Assert that a project with a native target can be configure")
@@ -9,15 +9,10 @@ import org.gradle.testkit.runner.BuildResult
import org.gradle.util.GradleVersion
import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinToolingDiagnostics
import org.jetbrains.kotlin.gradle.testbase.*
import org.jetbrains.kotlin.gradle.util.replaceFirst
import org.jetbrains.kotlin.gradle.utils.NativeCompilerDownloader
import org.jetbrains.kotlin.konan.target.HostManager
import org.jetbrains.kotlin.konan.target.KonanTarget
import org.jetbrains.kotlin.konan.target.presetName
import org.jetbrains.kotlin.tooling.core.KotlinToolingVersion
import org.jetbrains.kotlin.tooling.core.KotlinToolingVersion.Maturity.*
import org.jetbrains.kotlin.tooling.core.buildNumber
import org.junit.jupiter.api.Assumptions
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.condition.OS
import org.junit.jupiter.api.io.TempDir
@@ -34,11 +29,6 @@ import kotlin.io.path.appendText
@NativeGradlePluginTests
class NativeDownloadAndPlatformLibsIT : KGPBaseTest() {
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 val platformName: String = HostManager.platformName()
private val currentCompilerVersion = NativeCompilerDownloader.DEFAULT_KONAN_VERSION
@@ -215,20 +205,15 @@ class NativeDownloadAndPlatformLibsIT : KGPBaseTest() {
@DisplayName("Download prebuilt Native bundle with maven")
@GradleTest
fun shouldDownloadPrebuiltNativeBundleWithMaven(gradleVersion: GradleVersion) {
val maven = mavenUrl()
Assumptions.assumeTrue(
maven != MAVEN_CENTRAL,
"Don't run this test for build that are not yet published to central.\n" +
" We won't public K/N into Maven central until this task is completed: KTI-1067"
)
nativeProject("native-download-maven", gradleVersion = gradleVersion) {
buildGradleKts.replaceFirst("// <MavenPlaceholder>", "maven(\"${maven}\")")
build(
"assemble",
buildOptions = defaultBuildOptions.copy(nativeOptions = defaultBuildOptions.nativeOptions.copy(distributionDownloadFromMaven = true))
buildOptions = defaultBuildOptions.copy(
nativeOptions = defaultBuildOptions.nativeOptions.copy(
version = TestVersions.Kotlin.STABLE_RELEASE,
)
)
) {
assertOutputContains("Unpack Kotlin/Native compiler to ")
assertOutputDoesNotContain("Generate platform libraries for ")
@@ -240,22 +225,14 @@ class NativeDownloadAndPlatformLibsIT : KGPBaseTest() {
@RequiredXCodeVersion(minSupportedMajor = 14, minSupportedMinor = 1)
@GradleTest
fun shouldDownloadLightNativeBundleWithMaven(gradleVersion: GradleVersion) {
val maven = mavenUrl()
Assumptions.assumeTrue(
maven != MAVEN_CENTRAL,
"Don't run this test for build that are not yet published to central.\n" +
" We won't public K/N into Maven central until this task is completed: KTI-1067"
)
nativeProject("native-download-maven", gradleVersion = gradleVersion) {
buildGradleKts.replaceFirst("// <MavenPlaceholder>", "maven(\"${maven}\")")
val nativeOptions = defaultBuildOptions.nativeOptions.copy(
distributionType = "light",
distributionDownloadFromMaven = true
version = TestVersions.Kotlin.STABLE_RELEASE,
)
build(
"assemble",
buildOptions = defaultBuildOptions.copy(nativeOptions = nativeOptions)
buildOptions = defaultBuildOptions.copy(nativeOptions = nativeOptions),
) {
assertOutputContains("Unpack Kotlin/Native compiler to ")
assertOutputContains("Generate platform libraries for ")
@@ -370,14 +347,4 @@ class NativeDownloadAndPlatformLibsIT : KGPBaseTest() {
assertions = assertions
)
private fun mavenUrl(): String {
val kotlinToolingVersion = KotlinToolingVersion(currentCompilerVersion)
val maturity = kotlinToolingVersion.maturity
val buildNumber = kotlinToolingVersion.buildNumber
return when {
maturity == DEV || buildNumber != null -> KOTLIN_SPACE_DEV
else -> MAVEN_CENTRAL
}
}
}
@@ -86,7 +86,8 @@ data class BuildOptions(
val cocoapodsConfiguration: String? = null,
val cocoapodsArchs: String? = null,
val distributionType: String? = null,
val distributionDownloadFromMaven: Boolean? = null,
// TODO(Dmitrii Krasnov): we can change false on null, when downloading konan from maven local will be possible KT-63198
val distributionDownloadFromMaven: Boolean? = false,
val reinstall: Boolean? = null,
val restrictedDistribution: Boolean? = null,
val useXcodeMessageStyle: Boolean? = null,
@@ -34,7 +34,7 @@ interface TestVersions {
}
object Kotlin {
const val STABLE_RELEASE = "1.8.22"
const val STABLE_RELEASE = "1.9.20"
// Copied from KOTLIN_VERSION.kt file
val CURRENT
@@ -5,7 +5,6 @@ plugins {
}
repositories {
// <MavenPlaceholder>
mavenCentral()
mavenLocal()
}
@@ -283,7 +283,7 @@ internal class PropertiesProvider private constructor(private val project: Proje
* Makes downloader search for bundles in maven repositories specified in the project.
*/
val nativeDownloadFromMaven: Boolean
get() = this.booleanProperty("kotlin.native.distribution.downloadFromMaven") ?: false
get() = this.booleanProperty("kotlin.native.distribution.downloadFromMaven") ?: true
/**
* Allows a user to provide a local Kotlin/Native distribution instead of a downloaded one.
@@ -133,7 +133,7 @@ class NativeCompilerDownloader(
mapOf(
"group" to KOTLIN_GROUP_ID,
"name" to dependencyName,
"version" to compilerVersion.toString(),
"version" to compilerVersion,
"classifier" to simpleOsName,
"ext" to archiveExtension
)
@@ -142,7 +142,7 @@ class NativeCompilerDownloader(
project.dependencies.create(
mapOf(
"name" to "$dependencyName-$simpleOsName",
"version" to compilerVersion.toString(),
"version" to compilerVersion,
"ext" to archiveExtension
)
)
@@ -14,8 +14,7 @@ import org.gradle.api.plugins.ExtraPropertiesExtension
import org.gradle.testfixtures.ProjectBuilder
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinAndroidPluginWrapper
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper
import org.jetbrains.kotlin.gradle.plugin.*
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ENABLE_INTRANSITIVE_METADATA_CONFIGURATION
import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension
@@ -32,6 +31,7 @@ fun buildProject(
.build()
//temporary solution for BuildEventsListenerRegistry
.also { addBuildEventsListenerRegistryMock(it) }
.also { disableDownloadingKonanFromMavenCentral(it) }
.apply(configureProject)
.let { it as ProjectInternal }
@@ -0,0 +1,14 @@
/*
* Copyright 2010-2023 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.util
import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.plugin.extraProperties
// TODO(Dmitrii Krasnov): we can remove this, when downloading konan from maven local will be possible KT-63198
internal fun disableDownloadingKonanFromMavenCentral(project: Project) {
project.extraProperties.set("kotlin.native.distribution.downloadFromMaven", "false")
}
@@ -9,6 +9,7 @@ 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.plugin.extraProperties
import org.jetbrains.kotlin.gradle.utils.NativeCompilerDownloader
import java.io.File
@@ -19,6 +20,9 @@ internal val konanHome: File by lazy {
.run {
project.plugins.apply("kotlin-multiplatform")
// TODO(Dmitrii Krasnov): remove this, when KT-58303 is done
project.extraProperties.set("kotlin.native.distribution.downloadFromMaven","false")
(project.kotlinExtension as KotlinMultiplatformExtension).apply {
macosX64()
macosArm64()