HMPP: Propagate K/N flavor into each imported K/N module
This commit is contained in:
+24
-7
@@ -272,8 +272,6 @@ open class KotlinMPPGradleProjectResolver : AbstractProjectResolverExtensionComp
|
|||||||
val mppModel = resolverCtx.getMppModel(gradleModule)
|
val mppModel = resolverCtx.getMppModel(gradleModule)
|
||||||
if (mppModel == null || externalProject == null) return
|
if (mppModel == null || externalProject == null) return
|
||||||
|
|
||||||
mainModuleNode.kotlinNativeHome = mppModel.kotlinNativeHome
|
|
||||||
|
|
||||||
val jdkName = gradleModule.jdkNameIfAny
|
val jdkName = gradleModule.jdkNameIfAny
|
||||||
|
|
||||||
// save artefacts locations.
|
// save artefacts locations.
|
||||||
@@ -306,7 +304,7 @@ open class KotlinMPPGradleProjectResolver : AbstractProjectResolverExtensionComp
|
|||||||
|
|
||||||
val sourceSetToRunTasks = calculateRunTasks(mppModel, gradleModule, resolverCtx)
|
val sourceSetToRunTasks = calculateRunTasks(mppModel, gradleModule, resolverCtx)
|
||||||
|
|
||||||
val sourceSetToCompilationData = LinkedHashMap<KotlinSourceSet, MutableSet<GradleSourceSetData>>()
|
val sourceSetToCompilationData = LinkedHashMap<String, MutableSet<GradleSourceSetData>>()
|
||||||
for (target in mppModel.targets) {
|
for (target in mppModel.targets) {
|
||||||
if (delegateToAndroidPlugin(target)) continue
|
if (delegateToAndroidPlugin(target)) continue
|
||||||
if (target.name == KotlinTarget.METADATA_TARGET_NAME) continue
|
if (target.name == KotlinTarget.METADATA_TARGET_NAME) continue
|
||||||
@@ -362,10 +360,19 @@ open class KotlinMPPGradleProjectResolver : AbstractProjectResolverExtensionComp
|
|||||||
|
|
||||||
if (compilation.platform == KotlinPlatform.JVM || compilation.platform == KotlinPlatform.ANDROID) {
|
if (compilation.platform == KotlinPlatform.JVM || compilation.platform == KotlinPlatform.ANDROID) {
|
||||||
compilationData.targetCompatibility = (kotlinSourceSet.compilerArguments as? K2JVMCompilerArguments)?.jvmTarget
|
compilationData.targetCompatibility = (kotlinSourceSet.compilerArguments as? K2JVMCompilerArguments)?.jvmTarget
|
||||||
|
} else if (compilation.platform == KotlinPlatform.NATIVE) {
|
||||||
|
// Kotlin/Native target has been added to KotlinNativeCompilation only in 1.3.60,
|
||||||
|
// so 'nativeExtensions' may be null in 1.3.5x or earlier versions
|
||||||
|
compilation.nativeExtensions?.konanTarget?.let { konanTarget ->
|
||||||
|
compilationData.konanTargets = setOf(konanTarget)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (sourceSet in compilation.sourceSets) {
|
for (sourceSet in compilation.sourceSets) {
|
||||||
sourceSetToCompilationData.getOrPut(sourceSet) { LinkedHashSet() } += compilationData
|
sourceSetToCompilationData.getOrPut(sourceSet.name) { LinkedHashSet() } += compilationData
|
||||||
|
for (dependentSourceSetName in sourceSet.dependsOnSourceSets) {
|
||||||
|
sourceSetToCompilationData.getOrPut(dependentSourceSetName) { LinkedHashSet() } += compilationData
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val compilationDataNode =
|
val compilationDataNode =
|
||||||
@@ -415,9 +422,18 @@ open class KotlinMPPGradleProjectResolver : AbstractProjectResolverExtensionComp
|
|||||||
|
|
||||||
it.ideModuleGroup = moduleGroup
|
it.ideModuleGroup = moduleGroup
|
||||||
it.sdkName = jdkName
|
it.sdkName = jdkName
|
||||||
it.targetCompatibility = sourceSetToCompilationData[sourceSet]
|
|
||||||
?.mapNotNull { it.targetCompatibility }
|
sourceSetToCompilationData[sourceSet.name]?.let { compilationDataRecords ->
|
||||||
?.minWith(VersionComparatorUtil.COMPARATOR)
|
it.targetCompatibility = compilationDataRecords
|
||||||
|
.mapNotNull { compilationData -> compilationData.targetCompatibility }
|
||||||
|
.minWith(VersionComparatorUtil.COMPARATOR)
|
||||||
|
|
||||||
|
if (sourceSet.actualPlatforms.getSinglePlatform() == KotlinPlatform.NATIVE) {
|
||||||
|
it.konanTargets = compilationDataRecords
|
||||||
|
.flatMap { compilationData -> compilationData.konanTargets }
|
||||||
|
.toSet()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val kotlinSourceSet = createSourceSetInfo(sourceSet, gradleModule, resolverCtx) ?: continue
|
val kotlinSourceSet = createSourceSetInfo(sourceSet, gradleModule, resolverCtx) ?: continue
|
||||||
@@ -439,6 +455,7 @@ open class KotlinMPPGradleProjectResolver : AbstractProjectResolverExtensionComp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mainModuleNode.kotlinNativeHome = mppModel.kotlinNativeHome
|
||||||
mainModuleNode.coroutines = mppModel.extraFeatures.coroutinesState
|
mainModuleNode.coroutines = mppModel.extraFeatures.coroutinesState
|
||||||
mainModuleNode.isHmpp = mppModel.extraFeatures.isHMPPEnabled
|
mainModuleNode.isHmpp = mppModel.extraFeatures.isHMPPEnabled
|
||||||
//TODO improve passing version of used multiplatform
|
//TODO improve passing version of used multiplatform
|
||||||
|
|||||||
+22
-6
@@ -30,9 +30,12 @@ import org.jetbrains.kotlin.idea.inspections.gradle.findAll
|
|||||||
import org.jetbrains.kotlin.idea.inspections.gradle.findKotlinPluginVersion
|
import org.jetbrains.kotlin.idea.inspections.gradle.findKotlinPluginVersion
|
||||||
import org.jetbrains.kotlin.idea.platform.IdePlatformKindTooling
|
import org.jetbrains.kotlin.idea.platform.IdePlatformKindTooling
|
||||||
import org.jetbrains.kotlin.idea.roots.migrateNonJvmSourceFolders
|
import org.jetbrains.kotlin.idea.roots.migrateNonJvmSourceFolders
|
||||||
|
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||||
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
|
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
|
||||||
|
import org.jetbrains.kotlin.platform.impl.NativeIdePlatformKind
|
||||||
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
|
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
|
||||||
|
import org.jetbrains.kotlin.platform.konan.NativePlatforms
|
||||||
import org.jetbrains.plugins.gradle.model.data.BuildScriptClasspathData
|
import org.jetbrains.plugins.gradle.model.data.BuildScriptClasspathData
|
||||||
import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData
|
import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData
|
||||||
|
|
||||||
@@ -102,13 +105,17 @@ class KotlinSourceSetDataService : AbstractProjectDataService<GradleSourceSetDat
|
|||||||
|
|
||||||
val platformKinds = kotlinSourceSet.actualPlatforms.platforms //TODO(auskov): fix calculation of jvm target
|
val platformKinds = kotlinSourceSet.actualPlatforms.platforms //TODO(auskov): fix calculation of jvm target
|
||||||
.map { IdePlatformKindTooling.getTooling(it).kind }
|
.map { IdePlatformKindTooling.getTooling(it).kind }
|
||||||
.flatMap {
|
.flatMap { platformKind ->
|
||||||
when (it) {
|
when (platformKind) {
|
||||||
is JvmIdePlatformKind -> {
|
is JvmIdePlatformKind -> {
|
||||||
val target = JvmTarget.fromString(moduleData.targetCompatibility ?: "") ?: JvmTarget.DEFAULT
|
val jvmTarget = JvmTarget.fromString(moduleData.targetCompatibility ?: "") ?: JvmTarget.DEFAULT
|
||||||
JvmPlatforms.jvmPlatformByTargetVersion(target).componentPlatforms
|
JvmPlatforms.jvmPlatformByTargetVersion(jvmTarget).componentPlatforms
|
||||||
}
|
}
|
||||||
else -> it.defaultPlatform.componentPlatforms
|
is NativeIdePlatformKind -> {
|
||||||
|
val nativeTargets = moduleData.konanTargets.mapNotNull { KonanTarget.predefinedTargets[it] }
|
||||||
|
NativePlatforms.nativePlatformByTargets(nativeTargets)
|
||||||
|
}
|
||||||
|
else -> platformKind.defaultPlatform.componentPlatforms
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.distinct()
|
.distinct()
|
||||||
@@ -174,4 +181,13 @@ class KotlinSourceSetDataService : AbstractProjectDataService<GradleSourceSetDat
|
|||||||
return kotlinFacet
|
return kotlinFacet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private const val KOTLIN_NATIVE_TARGETS_PROPERTY = "konanTargets"
|
||||||
|
|
||||||
|
var ModuleData.konanTargets: Set<String>
|
||||||
|
get() {
|
||||||
|
val value = getProperty(KOTLIN_NATIVE_TARGETS_PROPERTY) ?: return emptySet()
|
||||||
|
return if (value.isNotEmpty()) value.split(',').toSet() else emptySet()
|
||||||
|
}
|
||||||
|
set(value) = setProperty(KOTLIN_NATIVE_TARGETS_PROPERTY, value.takeIf { it.isNotEmpty() }?.joinToString(","))
|
||||||
|
|||||||
Reference in New Issue
Block a user