[Gradle] Add AddKotlinPlatformIntegersSupportLibrary
Move code from KotlinNativePlatformDependencies.kt ^KT-61559
This commit is contained in:
committed by
Space Team
parent
1604ab1e0b
commit
4a0bfcd842
+1
-1
@@ -16,9 +16,9 @@ import org.gradle.api.tasks.*
|
|||||||
import org.gradle.work.DisableCachingByDefault
|
import org.gradle.work.DisableCachingByDefault
|
||||||
import org.jetbrains.kotlin.commonizer.toolsDir
|
import org.jetbrains.kotlin.commonizer.toolsDir
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinProjectSetupCoroutine
|
import org.jetbrains.kotlin.gradle.plugin.KotlinProjectSetupCoroutine
|
||||||
import org.jetbrains.kotlin.gradle.targets.native.internal.konanDistribution
|
|
||||||
import org.jetbrains.kotlin.gradle.tasks.locateOrRegisterTask
|
import org.jetbrains.kotlin.gradle.tasks.locateOrRegisterTask
|
||||||
import org.jetbrains.kotlin.gradle.utils.getFile
|
import org.jetbrains.kotlin.gradle.utils.getFile
|
||||||
|
import org.jetbrains.kotlin.gradle.utils.konanDistribution
|
||||||
import org.jetbrains.kotlin.gradle.utils.property
|
import org.jetbrains.kotlin.gradle.utils.property
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|||||||
+2
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.gradle.targets.native.ConfigureFrameworkExportSideEf
|
|||||||
import org.jetbrains.kotlin.gradle.targets.native.CreateFatFrameworksSetupAction
|
import org.jetbrains.kotlin.gradle.targets.native.CreateFatFrameworksSetupAction
|
||||||
import org.jetbrains.kotlin.gradle.targets.native.KotlinNativeConfigureBinariesSideEffect
|
import org.jetbrains.kotlin.gradle.targets.native.KotlinNativeConfigureBinariesSideEffect
|
||||||
import org.jetbrains.kotlin.gradle.targets.native.SetupEmbedAndSignAppleFrameworkTaskSideEffect
|
import org.jetbrains.kotlin.gradle.targets.native.SetupEmbedAndSignAppleFrameworkTaskSideEffect
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.native.internal.AddKotlinPlatformIntegersSupportLibrary
|
||||||
import org.jetbrains.kotlin.gradle.targets.native.internal.CInteropCommonizedCInteropApiElementsConfigurationsSetupAction
|
import org.jetbrains.kotlin.gradle.targets.native.internal.CInteropCommonizedCInteropApiElementsConfigurationsSetupAction
|
||||||
import org.jetbrains.kotlin.gradle.targets.native.internal.SetupCInteropApiElementsConfigurationSideEffect
|
import org.jetbrains.kotlin.gradle.targets.native.internal.SetupCInteropApiElementsConfigurationSideEffect
|
||||||
import org.jetbrains.kotlin.gradle.targets.native.internal.SetupKotlinNativePlatformDependenciesAndStdlib
|
import org.jetbrains.kotlin.gradle.targets.native.internal.SetupKotlinNativePlatformDependenciesAndStdlib
|
||||||
@@ -47,6 +48,7 @@ internal fun Project.registerKotlinPluginExtensions() {
|
|||||||
register(project, SyncLanguageSettingsWithKotlinExtensionSetupAction)
|
register(project, SyncLanguageSettingsWithKotlinExtensionSetupAction)
|
||||||
register(project, UserDefinedAttributesSetupAction)
|
register(project, UserDefinedAttributesSetupAction)
|
||||||
register(project, CustomizeKotlinDependenciesSetupAction)
|
register(project, CustomizeKotlinDependenciesSetupAction)
|
||||||
|
register(project, AddKotlinPlatformIntegersSupportLibrary)
|
||||||
|
|
||||||
|
|
||||||
if (isJvm || isMultiplatform) {
|
if (isJvm || isMultiplatform) {
|
||||||
|
|||||||
-6
@@ -61,12 +61,6 @@ abstract class AbstractKotlinNativeTargetPreset<T : KotlinNativeTarget>(
|
|||||||
|
|
||||||
createTargetConfigurator().configureTarget(result)
|
createTargetConfigurator().configureTarget(result)
|
||||||
|
|
||||||
SingleActionPerProject.run(project, "setUpKotlinNativePlatformDependencies") {
|
|
||||||
project.whenEvaluated {
|
|
||||||
project.setupKotlinNativePlatformDependencies()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SingleActionPerProject.run(project, "setupCInteropDependencies") {
|
SingleActionPerProject.run(project, "setupCInteropDependencies") {
|
||||||
project.setupCInteropCommonizerDependencies()
|
project.setupCInteropCommonizerDependencies()
|
||||||
project.setupCInteropPropagatedDependencies()
|
project.setupCInteropPropagatedDependencies()
|
||||||
|
|||||||
+51
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* 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.targets.native.internal
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
|
||||||
|
import org.jetbrains.kotlin.gradle.internal.KOTLIN_MODULE_GROUP
|
||||||
|
import org.jetbrains.kotlin.gradle.internal.PLATFORM_INTEGERS_SUPPORT_LIBRARY
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinProjectSetupCoroutine
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.sources.getVisibleSourceSetsFromAssociateCompilations
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.sources.internal
|
||||||
|
|
||||||
|
internal val AddKotlinPlatformIntegersSupportLibrary = KotlinProjectSetupCoroutine {
|
||||||
|
if (!isPlatformIntegerCommonizationEnabled) return@KotlinProjectSetupCoroutine
|
||||||
|
val kotlin = multiplatformExtensionOrNull ?: return@KotlinProjectSetupCoroutine
|
||||||
|
val sourceSets = kotlin.awaitSourceSets()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate roots of native source sets
|
||||||
|
* Imagine following structure:
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* common
|
||||||
|
* / | \
|
||||||
|
* jvm linux ios
|
||||||
|
* / | | \
|
||||||
|
* lX64 lArm64 iosX64 iosArm64
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* In the structure above following source sets are native: linux, ios, lX64, lArm64, iosX64, iosArm64
|
||||||
|
* But roots of the native source set hierarchies are only linux and ios. I.e. they don't depend on any other
|
||||||
|
* native source set. The code below calculates exactly that:
|
||||||
|
*/
|
||||||
|
val nativeSourceSets = sourceSets.filter { sourceSet -> sourceSet.internal.commonizerTarget.await() != null }
|
||||||
|
val nativeSourceSetsRoots = nativeSourceSets.filter { sourceSet ->
|
||||||
|
val allVisibleSourceSets = sourceSet.dependsOn + getVisibleSourceSetsFromAssociateCompilations(sourceSet)
|
||||||
|
allVisibleSourceSets.none { dependency ->
|
||||||
|
dependency in nativeSourceSets
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nativeSourceSetsRoots.forEach { sourceSet ->
|
||||||
|
dependencies.add(
|
||||||
|
sourceSet.implementationConfigurationName,
|
||||||
|
"$KOTLIN_MODULE_GROUP:$PLATFORM_INTEGERS_SUPPORT_LIBRARY:${getKotlinPluginVersion()}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
-25
@@ -27,31 +27,6 @@ import org.jetbrains.kotlin.gradle.utils.filesProvider
|
|||||||
import org.jetbrains.kotlin.gradle.utils.konanDistribution
|
import org.jetbrains.kotlin.gradle.utils.konanDistribution
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
internal fun Project.setupKotlinNativePlatformDependencies() {
|
|
||||||
val kotlin = multiplatformExtensionOrNull ?: return
|
|
||||||
|
|
||||||
launch {
|
|
||||||
if (isPlatformIntegerCommonizationEnabled) {
|
|
||||||
kotlin.nativeRootSourceSets().forEach { sourceSet ->
|
|
||||||
dependencies.add(
|
|
||||||
sourceSet.implementationConfigurationName,
|
|
||||||
"$KOTLIN_MODULE_GROUP:$PLATFORM_INTEGERS_SUPPORT_LIBRARY:${getKotlinPluginVersion()}"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal suspend fun KotlinMultiplatformExtension.nativeRootSourceSets(): Collection<KotlinSourceSet> {
|
|
||||||
val nativeSourceSets = sourceSets.filter { sourceSet -> sourceSet.internal.commonizerTarget.await() != null }
|
|
||||||
return nativeSourceSets.filter { sourceSet ->
|
|
||||||
val allVisibleSourceSets = sourceSet.dependsOn + getVisibleSourceSetsFromAssociateCompilations(sourceSet)
|
|
||||||
allVisibleSourceSets.none { dependency ->
|
|
||||||
dependency in nativeSourceSets
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function signature needs to be kept stable since this is used during import
|
* Function signature needs to be kept stable since this is used during import
|
||||||
* in IDEs (KotlinCommonizerModelBuilder) < 222
|
* in IDEs (KotlinCommonizerModelBuilder) < 222
|
||||||
|
|||||||
+1
-8
@@ -5,9 +5,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.utils
|
package org.jetbrains.kotlin.gradle.utils
|
||||||
|
|
||||||
import org.gradle.api.Project
|
|
||||||
import org.jetbrains.kotlin.commonizer.KonanDistribution
|
|
||||||
import org.jetbrains.kotlin.compilerRunner.konanHome
|
|
||||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||||
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
|
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
|
||||||
import org.jetbrains.kotlin.gradle.dsl.KotlinSingleTargetExtension
|
import org.jetbrains.kotlin.gradle.dsl.KotlinSingleTargetExtension
|
||||||
@@ -29,8 +26,4 @@ internal fun KotlinProjectExtension.forAllTargets(action: (target: KotlinTarget)
|
|||||||
is KotlinMultiplatformExtension -> targets.all(action)
|
is KotlinMultiplatformExtension -> targets.all(action)
|
||||||
else -> error("Unexpected 'kotlin' extension $this")
|
else -> error("Unexpected 'kotlin' extension $this")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal val Project.konanDistribution: KonanDistribution
|
|
||||||
get() = KonanDistribution(project.file(konanHome))
|
|
||||||
|
|
||||||
+5
@@ -6,6 +6,8 @@
|
|||||||
package org.jetbrains.kotlin.gradle.utils
|
package org.jetbrains.kotlin.gradle.utils
|
||||||
|
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
|
import org.jetbrains.kotlin.commonizer.KonanDistribution
|
||||||
|
import org.jetbrains.kotlin.compilerRunner.konanHome
|
||||||
import org.jetbrains.kotlin.gradle.plugin.internal.BasePluginConfiguration
|
import org.jetbrains.kotlin.gradle.plugin.internal.BasePluginConfiguration
|
||||||
import org.jetbrains.kotlin.gradle.plugin.variantImplementationFactory
|
import org.jetbrains.kotlin.gradle.plugin.variantImplementationFactory
|
||||||
|
|
||||||
@@ -38,3 +40,6 @@ internal val Project.distsDirectory
|
|||||||
get() = variantImplementationFactory<BasePluginConfiguration.BasePluginConfigurationVariantFactory>()
|
get() = variantImplementationFactory<BasePluginConfiguration.BasePluginConfigurationVariantFactory>()
|
||||||
.getInstance(this)
|
.getInstance(this)
|
||||||
.distsDirectory
|
.distsDirectory
|
||||||
|
|
||||||
|
internal val Project.konanDistribution: KonanDistribution
|
||||||
|
get() = KonanDistribution(project.file(konanHome))
|
||||||
|
|||||||
Reference in New Issue
Block a user