[Gradle] Moved downloading konan dependencies from compiler to Gradle
^KT-65823 Fixed
This commit is contained in:
committed by
Space Team
parent
8ae6e98295
commit
f525d03e67
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2010-2024 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.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.gradle.testbase.*
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.condition.OS
|
||||
import org.junit.jupiter.api.io.TempDir
|
||||
import java.nio.file.Path
|
||||
|
||||
// We temporarily disable it for windows until a proper fix is found for this issue: KT-62761
|
||||
@OsCondition(
|
||||
supportedOn = [OS.MAC, OS.LINUX], enabledOnCI = [OS.MAC, OS.LINUX]
|
||||
)
|
||||
@DisplayName("This test class contains different scenarios with downloading dependencies for Kotlin Native Compiler during build.")
|
||||
@NativeGradlePluginTests
|
||||
class KotlinNativeDependenciesDownloadIT : KGPBaseTest() {
|
||||
|
||||
@TempDir
|
||||
lateinit var konanDataTempDir: Path
|
||||
|
||||
override val defaultBuildOptions: BuildOptions
|
||||
get() = super.defaultBuildOptions.withBundledKotlinNative().copy(
|
||||
// For each test in this class, we need to provide an isolated .konan directory,
|
||||
// so we create it within each test project folder
|
||||
konanDataDir = konanDataTempDir
|
||||
)
|
||||
|
||||
@DisplayName("Gradle should download dependencies before compile execution")
|
||||
@GradleTest
|
||||
fun shouldDownloadDependenciesBeforeCompilerExecution(gradleVersion: GradleVersion) {
|
||||
nativeProject("mpp-default-hierarchy", gradleVersion) {
|
||||
build("assemble") {
|
||||
assertOutputContains("Downloading dependency for Kotlin Native")
|
||||
assertOutputDoesNotContain("(KonanProperties) Downloading dependency")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("Compiler should download dependencies when Kotlin Native Toolchain disabled ")
|
||||
@GradleTest
|
||||
fun checkCompilerDownloadsDependenciesWhenToochainDisabled(gradleVersion: GradleVersion) {
|
||||
nativeProject("mpp-default-hierarchy", gradleVersion) {
|
||||
|
||||
build(
|
||||
"assemble", buildOptions = defaultBuildOptions.copy(
|
||||
freeArgs = listOf("-Pkotlin.native.toolchain.enabled=false"),
|
||||
)
|
||||
) {
|
||||
assertOutputContains("(KonanProperties) Downloading dependency")
|
||||
assertOutputDoesNotContain("Downloading dependency for Kotlin Native")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-4
@@ -22,9 +22,6 @@ import org.jetbrains.kotlin.build.report.metrics.GradleBuildTime
|
||||
import org.jetbrains.kotlin.commonizer.SharedCommonizerTarget
|
||||
import org.jetbrains.kotlin.commonizer.konanTargets
|
||||
import org.jetbrains.kotlin.compilerRunner.*
|
||||
import org.jetbrains.kotlin.compilerRunner.GradleCliCommonizer
|
||||
import org.jetbrains.kotlin.compilerRunner.KotlinNativeCommonizerToolRunner
|
||||
import org.jetbrains.kotlin.compilerRunner.konanHome
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.kotlinPropertiesProvider
|
||||
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
|
||||
@@ -104,7 +101,12 @@ internal abstract class NativeDistributionCommonizerTask
|
||||
|
||||
@get:Nested
|
||||
internal val kotlinNativeProvider: Provider<KotlinNativeProvider> = project.provider {
|
||||
KotlinNativeProvider(project, commonizerTargets.flatMap { target -> target.konanTargets }.toSet(), kotlinNativeBundleBuildService)
|
||||
KotlinNativeProvider(
|
||||
project,
|
||||
commonizerTargets.flatMap { target -> target.konanTargets }.toSet(),
|
||||
kotlinNativeBundleBuildService,
|
||||
enableDependenciesDownloading = false
|
||||
)
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
|
||||
+31
@@ -17,10 +17,14 @@ import org.jetbrains.kotlin.compilerRunner.konanHome
|
||||
import org.jetbrains.kotlin.compilerRunner.kotlinNativeToolchainEnabled
|
||||
import org.jetbrains.kotlin.gradle.plugin.KOTLIN_NATIVE_BUNDLE_CONFIGURATION_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.kotlinPropertiesProvider
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.enabledOnCurrentHost
|
||||
import org.jetbrains.kotlin.gradle.utils.NativeCompilerDownloader
|
||||
import org.jetbrains.kotlin.gradle.utils.filesProvider
|
||||
import org.jetbrains.kotlin.gradle.utils.property
|
||||
import org.jetbrains.kotlin.konan.properties.KonanPropertiesLoader
|
||||
import org.jetbrains.kotlin.konan.target.Distribution
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import org.jetbrains.kotlin.konan.target.loadConfigurables
|
||||
|
||||
/**
|
||||
* This is a nested provider for all native tasks
|
||||
@@ -29,6 +33,7 @@ internal class KotlinNativeProvider(
|
||||
project: Project,
|
||||
konanTargets: Set<KonanTarget>,
|
||||
kotlinNativeBundleBuildService: Provider<KotlinNativeBundleBuildService>,
|
||||
enableDependenciesDownloading: Boolean = true,
|
||||
) {
|
||||
constructor(
|
||||
project: Project,
|
||||
@@ -65,6 +70,32 @@ internal class KotlinNativeProvider(
|
||||
kotlinNativeVersion
|
||||
}
|
||||
|
||||
@get:Input
|
||||
val kotlinNativeDependencies: Provider<Set<String>> =
|
||||
kotlinNativeBundleVersion
|
||||
.zip(bundleDirectory) { _, bundleDir ->
|
||||
val requiredDependencies = mutableSetOf<String>()
|
||||
if (project.kotlinNativeToolchainEnabled && enableDependenciesDownloading) {
|
||||
val distribution = Distribution(bundleDir.asFile.absolutePath, konanDataDir = konanDataDir.orNull)
|
||||
konanTargets.forEach { konanTarget ->
|
||||
if (konanTarget.enabledOnCurrentHost) {
|
||||
val konanPropertiesLoader = loadConfigurables(
|
||||
konanTarget,
|
||||
distribution.properties,
|
||||
distribution.dependenciesDir,
|
||||
progressCallback = { url, currentBytes, totalBytes ->
|
||||
project.logger.info("Downloading dependency for Kotlin Native: $url (${currentBytes}/${totalBytes}). ")
|
||||
}
|
||||
) as KonanPropertiesLoader
|
||||
|
||||
requiredDependencies.addAll(konanPropertiesLoader.dependencies)
|
||||
konanPropertiesLoader.downloadDependencies()
|
||||
}
|
||||
}
|
||||
}
|
||||
requiredDependencies
|
||||
}
|
||||
|
||||
// Gradle tries to evaluate this val during configuration cache,
|
||||
// which lead to resolving configuration, even if k/n bundle is in konan home directory.
|
||||
@Transient
|
||||
|
||||
Reference in New Issue
Block a user