diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/ConfigurationCacheIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/ConfigurationCacheIT.kt index 2c66d668fd02b..2558fb9f7c993 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/ConfigurationCacheIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/ConfigurationCacheIT.kt @@ -11,7 +11,6 @@ import org.jetbrains.kotlin.gradle.report.BuildReportType import org.jetbrains.kotlin.gradle.testbase.* import org.jetbrains.kotlin.gradle.util.replaceText import org.jetbrains.kotlin.test.TestMetadata -import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.condition.OS import org.junit.jupiter.api.io.TempDir @@ -353,7 +352,6 @@ class ConfigurationCacheIT : AbstractConfigurationCacheIT() { @NativeGradlePluginTests @GradleTest @GradleTestVersions(minVersion = TestVersions.Gradle.MAX_SUPPORTED) - @Disabled("[KT-66423](http://youtrack.jetbrains.com/issue/KT-66423): ignore test until source-value changes are made") fun testNativeBundleDownloadForConfigurationCache(gradleVersion: GradleVersion, @TempDir konanDirTemp: Path) { nativeProject( "native-simple-project", gradleVersion, buildOptions = defaultBuildOptions.copy( diff --git a/libraries/tools/kotlin-gradle-plugin/api/all/kotlin-gradle-plugin.api b/libraries/tools/kotlin-gradle-plugin/api/all/kotlin-gradle-plugin.api index 8fe11c4c5a3ae..35130f7991fc8 100644 --- a/libraries/tools/kotlin-gradle-plugin/api/all/kotlin-gradle-plugin.api +++ b/libraries/tools/kotlin-gradle-plugin/api/all/kotlin-gradle-plugin.api @@ -6831,7 +6831,6 @@ public abstract class org/jetbrains/kotlin/gradle/tasks/KotlinNativeCompile : or public final fun getLanguageVersion ()Ljava/lang/String; public final fun getModuleName ()Ljava/lang/String; public fun getMultiplatformStructure ()Lorg/jetbrains/kotlin/gradle/tasks/K2MultiplatformStructure; - public final fun getNativeDistributionDependencies ()Lorg/gradle/api/provider/Provider; public final fun getOptInAnnotationsInUse ()Ljava/util/Set; public fun getOptimized ()Z public fun getOutputKind ()Lorg/jetbrains/kotlin/konan/target/CompilerOutputKind; diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/apple/swiftexport/tasks/SwiftExportTask.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/apple/swiftexport/tasks/SwiftExportTask.kt index 882daeff0db49..229d76a657c0d 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/apple/swiftexport/tasks/SwiftExportTask.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/apple/swiftexport/tasks/SwiftExportTask.kt @@ -17,8 +17,8 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.apple.swiftexport.internal.SwiftEx import org.jetbrains.kotlin.gradle.plugin.mpp.apple.swiftexport.internal.SwiftExportTaskParameters import org.jetbrains.kotlin.gradle.plugin.mpp.apple.swiftexport.internal.createSwiftExportedModule import org.jetbrains.kotlin.gradle.targets.native.toolchain.KotlinNativeProvider +import org.jetbrains.kotlin.gradle.targets.native.toolchain.konanDistribution import org.jetbrains.kotlin.gradle.utils.getFile -import org.jetbrains.kotlin.konan.target.Distribution import javax.inject.Inject @DisableCachingByDefault(because = "Swift Export is experimental, so no caching for now") @@ -79,7 +79,7 @@ internal abstract class SwiftExportTask @Inject constructor( workParameters.stableDeclarationsOrder.set(parameters.stableDeclarationsOrder) workParameters.swiftModulesFile.set(parameters.swiftModulesFile) workParameters.swiftModules.set(swiftModules) - workParameters.konanDistribution.set(kotlinNativeProvider.flatMap { it.bundleDirectory }.map { Distribution(it) }) + workParameters.konanDistribution.set(kotlinNativeProvider.flatMap { it.konanDistribution }) } } diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/KotlinNativeCompilation.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/KotlinNativeCompilation.kt index 71d2ecabd7b9a..763ecea8a973f 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/KotlinNativeCompilation.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/KotlinNativeCompilation.kt @@ -8,7 +8,6 @@ package org.jetbrains.kotlin.gradle.plugin.mpp import org.gradle.api.Action import org.gradle.api.NamedDomainObjectContainer -import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.tasks.TaskProvider import org.jetbrains.kotlin.gradle.dsl.* import org.jetbrains.kotlin.gradle.internal.properties.nativeProperties @@ -16,19 +15,15 @@ import org.jetbrains.kotlin.gradle.plugin.* import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.kotlinPropertiesProvider import org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.KotlinCompilationImpl import org.jetbrains.kotlin.gradle.targets.native.NativeCompilerOptions -import org.jetbrains.kotlin.gradle.targets.native.internal.getNativeDistributionDependencies -import org.jetbrains.kotlin.gradle.targets.native.internal.getOriginalPlatformLibrariesFor -import org.jetbrains.kotlin.gradle.targets.native.internal.inferCommonizerTarget import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName import org.jetbrains.kotlin.konan.target.KonanTarget -import org.jetbrains.kotlin.tooling.core.UnsafeApi import javax.inject.Inject @Suppress("TYPEALIAS_EXPANSION_DEPRECATION", "DEPRECATION") abstract class AbstractKotlinNativeCompilation internal constructor( compilation: KotlinCompilationImpl, - val konanTarget: KonanTarget, + val konanTarget: KonanTarget ) : DeprecatedAbstractKotlinCompilation(compilation) { @Suppress("DEPRECATION") @@ -55,16 +50,6 @@ abstract class AbstractKotlinNativeCompilation internal constructor( internal val useGenericPluginArtifact: Boolean get() = project.nativeProperties.shouldUseEmbeddableCompilerJar.get() - - internal val nativeDependencies: ConfigurableFileCollection - get() = compilation.project.objects.fileCollection().from(compilation.project.getOriginalPlatformLibrariesFor(konanTarget)) - - @OptIn(UnsafeApi::class) - internal val nativeDistributionDependencies: ConfigurableFileCollection - get() = inferCommonizerTarget(compilation)?.let { - compilation.project.objects.fileCollection().from(compilation.project.getNativeDistributionDependencies(it)) - } ?: compilation.project.objects.fileCollection() - } open class KotlinNativeCompilation @Inject internal constructor( @@ -98,7 +83,7 @@ open class KotlinNativeCompilation @Inject internal constructor( @Suppress("DEPRECATION") open class KotlinSharedNativeCompilation @Inject internal constructor( val konanTargets: List, - compilation: KotlinCompilationImpl, + compilation: KotlinCompilationImpl ) : AbstractKotlinNativeCompilation( compilation, konanTargets.find { it.enabledOnCurrentHostForKlibCompilation(compilation.project.kotlinPropertiesProvider) } ?: konanTargets.first() diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/internal/SetupKotlinNativePlatformDependenciesAndStdlib.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/internal/SetupKotlinNativePlatformDependenciesAndStdlib.kt index 8c710019ba957..9350e389c8a72 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/internal/SetupKotlinNativePlatformDependenciesAndStdlib.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/internal/SetupKotlinNativePlatformDependenciesAndStdlib.kt @@ -20,6 +20,9 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.resolvableMetadataConfiguration import org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet import org.jetbrains.kotlin.gradle.plugin.sources.internal import org.jetbrains.kotlin.gradle.targets.metadata.isNativeSourceSet +import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile +import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink +import org.jetbrains.kotlin.gradle.tasks.withType import org.jetbrains.kotlin.gradle.utils.filesProvider import org.jetbrains.kotlin.gradle.utils.konanDistribution import org.jetbrains.kotlin.konan.target.KonanTarget @@ -37,14 +40,20 @@ internal val SetupKotlinNativePlatformDependenciesAndStdlib = KotlinProjectSetup } } + excludeDefaultPlatformDependenciesFromKotlinNativeCompileTasks() launch { kotlin.excludeStdlibFromNativeSourceSetDependencies() } } -private fun AbstractKotlinNativeCompilation.configureStdlibAndPlatformDependencies( +private suspend fun AbstractKotlinNativeCompilation.configureStdlibAndPlatformDependencies( stdlib: FileCollection ) { + // Commonizer target must not be null for AbstractKotlinNativeCompilation, but we are graceful here and just return + val commonizerTarget = commonizerTarget.await() ?: return + val nativeDistributionDependencies = project.getNativeDistributionDependencies(commonizerTarget) + val updatedCompileDependencyFiles = project.files().from( stdlib, + nativeDistributionDependencies, compileDependencyFiles ) @@ -65,6 +74,28 @@ private suspend fun KotlinMultiplatformExtension.excludeStdlibFromNativeSourceSe } } +/** + * Platform dependencies are added to compilation "compile files" in [configureStdlibAndPlatformDependencies] + * So user code that integrates with Kotlin Native Compilations can safely rely on that classpath. + * However, for performance optimization reasons, Kotlin Native automatically loads Platform Dependencies from its distribution. + * And because of that KGP has to explicitly filter out these platform dependencies from tasks. + * + * NB: This is not applicable for Native Shared Metadata Compilation, they will receive commonized versions of platform libs. + */ +private fun Project.excludeDefaultPlatformDependenciesFromKotlinNativeCompileTasks() { + tasks.withType().configureEach { task -> + @Suppress("DEPRECATION") + val konanTarget = task.compilation.konanTarget + task.excludeOriginalPlatformLibraries = task.project.getOriginalPlatformLibrariesFor(konanTarget) + } + tasks.withType().configureEach { task -> + // metadata compilations should have commonized platform libraries in the classpath i.e. they are not "original" + if (task.isMetadataCompilation) return@configureEach + val konanTarget = task.konanTarget + task.excludeOriginalPlatformLibraries = task.project.getOriginalPlatformLibrariesFor(konanTarget) + } +} + internal val SetupKotlinNativeStdlibAndPlatformDependenciesImport = KotlinProjectSetupCoroutine { val multiplatform = multiplatformExtensionOrNull ?: return@KotlinProjectSetupCoroutine val sourceSets = multiplatform @@ -94,7 +125,7 @@ internal fun Project.getNativeDistributionDependencies(target: CommonizerTarget) private fun Project.getOriginalPlatformLibrariesFor(target: LeafCommonizerTarget): FileCollection = getOriginalPlatformLibrariesFor(target.konanTarget) -internal fun Project.getOriginalPlatformLibrariesFor(konanTarget: KonanTarget): FileCollection = project.filesProvider { +private fun Project.getOriginalPlatformLibrariesFor(konanTarget: KonanTarget): FileCollection = project.filesProvider { konanDistribution.platformLibsDir.resolve(konanTarget.name).listLibraryFiles().toSet() } diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeLink.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeLink.kt index 48ad559bd9d63..1d36822802370 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeLink.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeLink.kt @@ -38,7 +38,6 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.apple.useXcodeMessageStyle import org.jetbrains.kotlin.gradle.plugin.statistics.UsesBuildFusService import org.jetbrains.kotlin.gradle.report.UsesBuildMetricsService import org.jetbrains.kotlin.gradle.targets.native.UsesKonanPropertiesBuildService -import org.jetbrains.kotlin.gradle.targets.native.internal.* import org.jetbrains.kotlin.gradle.targets.native.tasks.CompilerPluginData import org.jetbrains.kotlin.gradle.targets.native.toolchain.NoopKotlinNativeProvider import org.jetbrains.kotlin.gradle.targets.native.toolchain.KotlinNativeProvider @@ -82,32 +81,21 @@ constructor( override val destinationDirectory: DirectoryProperty = binary.outputDirectoryProperty - @Suppress("DEPRECATION") - @get:Internal - internal val konanTarget = compilation.konanTarget - - // Avoid resolving these dependencies during task graph construction when we can't build the target: - @Suppress("DEPRECATION") - @get:Internal - internal val nativeDependencies = compilation.nativeDependencies - - @Suppress("DEPRECATION") - @get:Internal - internal val nativeDistributionDependencies = compilation.nativeDistributionDependencies - @get:Classpath override val libraries: ConfigurableFileCollection = objectFactory.fileCollection().from( { // Avoid resolving these dependencies during task graph construction when we can't build the target: @Suppress("DEPRECATION") - if (konanTarget.enabledOnCurrentHostForBinariesCompilation()) project.files().from( - compilation.nativeDistributionDependencies, - compilation.compileDependencyFiles - ) + if (konanTarget.enabledOnCurrentHostForBinariesCompilation()) compilation.compileDependencyFiles else objectFactory.fileCollection() } ) + @get:InputFiles + @get:Optional + @get:PathSensitive(PathSensitivity.RELATIVE) + internal var excludeOriginalPlatformLibraries: FileCollection? = null + @get:Input val outputKind: CompilerOutputKind by lazyConvention { binary.outputKind.compilerOutputKind } @@ -123,6 +111,10 @@ constructor( @get:Input internal val binaryName: String by lazyConvention { binary.name } + @Suppress("DEPRECATION") + @get:Internal + internal val konanTarget = compilation.konanTarget + @Suppress("DEPRECATION") @Deprecated("Use toolOptions to configure the task") @get:Internal @@ -221,7 +213,7 @@ constructor( private val cacheBuilderSettings get() = CacheBuilder.Settings( - konanHome = kotlinNativeProvider.flatMap { it.bundleDirectory }.map { File(it) }, + konanHome = kotlinNativeProvider.flatMap { it.bundleDirectory.asFile }, konanCacheKind = project.getKonanCacheKind(konanTarget), gradleUserHomeDir = project.gradle.gradleUserHomeDir, konanTarget = konanTarget, @@ -281,7 +273,7 @@ constructor( dependencyClasspath { args -> args.libraries = runSafe { - libraries.exclude(originalPlatformLibraries()).files.filterKlibsPassedToCompiler() + libraries.exclude(excludeOriginalPlatformLibraries).files.filterKlibsPassedToCompiler() }?.toPathsArray() args.exportedLibraries = runSafe { exportLibraries.files.filterKlibsPassedToCompiler() }?.toPathsArray() args.friendModules = runSafe { friendModule.files.toList().takeIf { it.isNotEmpty() } } @@ -293,8 +285,6 @@ constructor( } } - internal fun originalPlatformLibraries() = objectFactory.fileCollection().from(nativeDependencies) - private fun validatedExportedLibraries() { if (exportLibrariesResolvedConfiguration == null) return @@ -389,7 +379,7 @@ constructor( message = "This property will be removed in future releases. Don't use it in your code.", ) @get:Internal - val konanHome: Provider = kotlinNativeProvider.flatMap { it.bundleDirectory } + val konanHome: Provider = kotlinNativeProvider.map { it.bundleDirectory.get().asFile.absolutePath } @get:Internal internal abstract val kotlinCompilerArgumentsLogLevel: Property diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeTasks.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeTasks.kt index 850ae19bea277..2c0690fff911c 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeTasks.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeTasks.kt @@ -25,8 +25,6 @@ import org.gradle.work.DisableCachingByDefault import org.gradle.work.NormalizeLineEndings import org.jetbrains.kotlin.build.report.metrics.* import org.jetbrains.kotlin.cli.common.arguments.* -import org.jetbrains.kotlin.commonizer.KonanDistribution -import org.jetbrains.kotlin.commonizer.platformLibsDir import org.jetbrains.kotlin.compilerRunner.ArgumentUtils import org.jetbrains.kotlin.compilerRunner.KotlinCompilerArgumentsLogLevel import org.jetbrains.kotlin.compilerRunner.addBuildMetricsForTaskAction @@ -49,8 +47,6 @@ import org.jetbrains.kotlin.gradle.plugin.statistics.UsesBuildFusService import org.jetbrains.kotlin.gradle.report.* import org.jetbrains.kotlin.gradle.targets.native.KonanPropertiesBuildService import org.jetbrains.kotlin.gradle.targets.native.UsesKonanPropertiesBuildService -import org.jetbrains.kotlin.gradle.targets.native.internal.getNativeDistributionDependencies -import org.jetbrains.kotlin.gradle.targets.native.internal.inferCommonizerTarget import org.jetbrains.kotlin.gradle.targets.native.tasks.* import org.jetbrains.kotlin.gradle.targets.native.toolchain.NoopKotlinNativeProvider import org.jetbrains.kotlin.gradle.targets.native.toolchain.KotlinNativeProvider @@ -71,7 +67,6 @@ import org.jetbrains.kotlin.konan.target.buildDistribution import org.jetbrains.kotlin.konan.util.DefFile import org.jetbrains.kotlin.library.* import org.jetbrains.kotlin.project.model.LanguageSettings -import org.jetbrains.kotlin.tooling.core.UnsafeApi import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly import java.io.File import java.nio.file.Files @@ -181,9 +176,6 @@ abstract class AbstractKotlinNativeCompile< } } - @get:Internal - internal val konanDistribution = project.nativeProperties.actualNativeHomeDirectory - @get:Internal internal val enabledOnCurrentHostForKlibCompilationProperty: Property = project.objects.property().convention( // For KT-66452 we need to get rid of invocation of 'Task.project'. @@ -339,17 +331,6 @@ internal constructor( else "${project.name}_${compilation.compilationName}" } - @get:InputFiles - @get:PathSensitive(PathSensitivity.RELATIVE) - val nativeDistributionDependencies = project.provider { - when (val compilation = compilation) { - is KotlinCompilationInfo.TCS -> - @OptIn(UnsafeApi::class) - inferCommonizerTarget(compilation.compilation) - ?.let { compilation.project.getNativeDistributionDependencies(it).exclude(originalPlatformLibraries()) } - } - } - @Deprecated( message = "Please use 'compilerOptions.moduleName' to configure", replaceWith = ReplaceWith("compilerOptions.moduleName.get()") @@ -384,7 +365,7 @@ internal constructor( message = "This property will be removed in future releases. Don't use it in your code.", ) @get:Internal - val konanHome: Provider = kotlinNativeProvider.flatMap { it.bundleDirectory } + val konanHome: Provider = kotlinNativeProvider.map { it.bundleDirectory.get().asFile.absolutePath } @get:Nested override val multiplatformStructure: K2MultiplatformStructure = objectFactory.newInstance() @@ -470,6 +451,16 @@ internal constructor( override val klibOutput: Provider get() = outputFile + /** + * This is utility property that contains list of native platform dependencies that are present in [compileDependencyFiles] + * but should be excluded from actual classpath because they are included by default by Kotlin Native Compiler. + * this behaviour will be fixed as part of KT-65232 + */ + @get:InputFiles + @get:Optional + @get:PathSensitive(PathSensitivity.RELATIVE) + internal var excludeOriginalPlatformLibraries: FileCollection? = null + @Suppress("DeprecatedCallableAddReplaceWith") @Deprecated("KTIJ-25227: Necessary override for IDEs < 2023.2", level = DeprecationLevel.ERROR) override fun setupCompilerArgs(args: K2NativeCompilerArguments, defaultsOnly: Boolean, ignoreClasspathResolutionErrors: Boolean) { @@ -524,10 +515,7 @@ internal constructor( dependencyClasspath { args -> args.libraries = runSafe { - //filterKlibsPassedToCompiler call exists on files - val filteredLibraries = libraries.exclude(originalPlatformLibraries()).files.filterKlibsPassedToCompiler().toMutableList() - nativeDistributionDependencies.orNull?.files?.also { filteredLibraries.addAll(it) } - filteredLibraries.toPathsArray() + libraries.exclude(excludeOriginalPlatformLibraries).files.filterKlibsPassedToCompiler().toPathsArray() } args.friendModules = runSafe { friendModule.files.takeIf { it.isNotEmpty() }?.map { it.absolutePath }?.joinToString(File.pathSeparator) @@ -554,22 +542,6 @@ internal constructor( is KotlinCompilationInfo.TCS -> compilation.compilation is KotlinMetadataCompilation<*> } - /** - * Retuns list of native platform dependencies that are present in [compileDependencyFiles] - * but should be excluded from actual classpath because they are included by default by Kotlin Native Compiler. - * this behaviour will be fixed as part of KT-65232 - */ - internal fun originalPlatformLibraries() = - if (isMetadataCompilation) { - null - } else { - objectFactory.fileCollection() - .from(KonanDistribution(konanDistribution.get()).platformLibsDir.resolve(konanTarget.name).listLibraryFiles()) - } - - private fun File.listLibraryFiles(): List = listFiles().orEmpty() - .filter { it.isDirectory || it.extension == "klib" } - private fun createSharedCompilationDataOrNull(): SharedCompilationData? { if (!isMetadataCompilation) return null @@ -1182,7 +1154,7 @@ abstract class CInteropProcess @Inject internal constructor(params: Params) : message = "This property will be removed in future releases. Don't use it in your code.", ) @get:Internal - val konanHome: Provider = kotlinNativeProvider.flatMap { it.bundleDirectory } + val konanHome: Provider = kotlinNativeProvider.map { it.bundleDirectory.get().asFile.absolutePath } private val shouldUseEmbeddableCompilerJar = project.nativeProperties.shouldUseEmbeddableCompilerJar private val actualNativeHomeDirectory = project.nativeProperties.actualNativeHomeDirectory diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/artifact/KotlinNativeLinkArtifactTask.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/artifact/KotlinNativeLinkArtifactTask.kt index 4befbdbc65707..bb3f31a266398 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/artifact/KotlinNativeLinkArtifactTask.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/artifact/KotlinNativeLinkArtifactTask.kt @@ -200,7 +200,7 @@ abstract class KotlinNativeLinkArtifactTask @Inject constructor( message = "This property will be removed in future releases. Don't use it in your code.", ) @get:Internal - val konanHome: Provider = kotlinNativeProvider.flatMap { it.bundleDirectory } + val konanHome: Provider = kotlinNativeProvider.map { it.bundleDirectory.get().asFile.absolutePath } init { baseName.convention(project.name) diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/toolchain/KotlinNativeProvider.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/toolchain/KotlinNativeProvider.kt index 767a29cff3e66..4fae1e5104ddd 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/toolchain/KotlinNativeProvider.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/toolchain/KotlinNativeProvider.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.gradle.targets.native.toolchain import org.gradle.api.Project import org.gradle.api.file.ConfigurableFileCollection +import org.gradle.api.file.DirectoryProperty import org.gradle.api.provider.Property import org.gradle.api.provider.Provider import org.gradle.api.tasks.Input @@ -18,7 +19,6 @@ import org.jetbrains.kotlin.gradle.utils.NativeCompilerDownloader import org.jetbrains.kotlin.gradle.utils.property import org.jetbrains.kotlin.konan.target.Distribution import org.jetbrains.kotlin.konan.target.KonanTarget -import java.io.File internal sealed class KotlinNativeProvider(project: Project) { @get:Internal @@ -30,9 +30,11 @@ internal sealed class KotlinNativeProvider(project: Project) { @get:Internal val toolchainEnabled: Provider = project.nativeProperties.isToolchainEnabled - @get:Internal //Using DirectoryProperty causes the native directory to be included in the configuration cache input. - internal val bundleDirectory: Provider = project.nativeProperties.actualNativeHomeDirectory.map { it.absolutePath } + @get:Internal + val bundleDirectory: DirectoryProperty = project.objects.directoryProperty() + .fileProvider(project.nativeProperties.actualNativeHomeDirectory) + } /** @@ -76,7 +78,7 @@ internal class KotlinNativeFromToolchainProvider( project, kotlinNativeCompilerConfiguration, kotlinNativeVersion, - File(bundleDir), + bundleDir.asFile, reinstallFlag, konanTargets, overriddenKonanHome.orNull @@ -92,7 +94,7 @@ internal class KotlinNativeFromToolchainProvider( if (toolchainEnabled.get() && enableDependenciesDownloading) { kotlinNativeBundleBuildService.get() .downloadNativeDependencies( - File(bundleDir), + bundleDir.asFile, konanDataDir.orNull, konanTargets, project.logger @@ -130,5 +132,5 @@ internal fun UsesKotlinNativeBundleBuildService.chooseKotlinNativeProvider(enabl internal val KotlinNativeProvider.konanDistribution get() = bundleDirectory.map { - Distribution(it) + Distribution(it.asFile.canonicalPath) } \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/compilerArgumetns/KotlinNativeCompileArgumentsTest.kt b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/compilerArgumetns/KotlinNativeCompileArgumentsTest.kt index bcb4e4819ee54..3e2c90f52d71b 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/compilerArgumetns/KotlinNativeCompileArgumentsTest.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/compilerArgumetns/KotlinNativeCompileArgumentsTest.kt @@ -228,18 +228,13 @@ class KotlinNativeCompileArgumentsTest { "org.jetbrains.kotlin.native.platform.$it" }.toSet() - val actualNativeDependencies = nativeCompilation.nativeDependencies - .files - .map { it.name } - .toSet() - - assertEquals(expectedPlatformDependencies, actualNativeDependencies) + val expectedDependencies = expectedPlatformDependencies + listOf("stdlib") val actualDependencies = nativeCompilation.compileDependencyFiles .map { it.name } .toSet() - assertEquals(setOf("stdlib"), actualDependencies) + assertEquals(expectedDependencies, actualDependencies) } @Test @@ -269,14 +264,14 @@ class KotlinNativeCompileArgumentsTest { if (!file.path.contains("platform${File.separator}$target")) fail("File $file is expected to be a platform dependency of $target") } } - compileLinuxX64.originalPlatformLibraries().assertIsPlatformDependencies("linux_x64") - compileLinuxArm64.originalPlatformLibraries().assertIsPlatformDependencies("linux_arm64") - if (compileLinuxMainMetadata.originalPlatformLibraries() != null) fail( + compileLinuxX64.excludeOriginalPlatformLibraries.assertIsPlatformDependencies("linux_x64") + compileLinuxArm64.excludeOriginalPlatformLibraries.assertIsPlatformDependencies("linux_arm64") + if (compileLinuxMainMetadata.excludeOriginalPlatformLibraries != null) fail( "Native metadata compilation should not exclude platform libraries because they are coming from commonizer. " + "And is not included by default by Kotlin/Native compiler like default platform libraries." ) - linkLinuxX64.originalPlatformLibraries().assertIsPlatformDependencies("linux_x64") - linkLinuxArm64.originalPlatformLibraries().assertIsPlatformDependencies("linux_arm64") + linkLinuxX64.excludeOriginalPlatformLibraries.assertIsPlatformDependencies("linux_x64") + linkLinuxArm64.excludeOriginalPlatformLibraries.assertIsPlatformDependencies("linux_arm64") fun Array?.assertFilePathsDontContain(pathSubString: String) { if (this == null) return