Dont coerce platforms of source-sets in HMPP to set of available targets in project
This commit is contained in:
committed by
Yaroslav Chernyshev
parent
9c000000cf
commit
7ddcdca6bb
+13
-72
@@ -30,15 +30,10 @@ import org.jetbrains.kotlin.idea.inspections.gradle.findKotlinPluginVersion
|
||||
import org.jetbrains.kotlin.idea.platform.IdePlatformKindTooling
|
||||
import org.jetbrains.kotlin.idea.roots.migrateNonJvmSourceFolders
|
||||
import org.jetbrains.kotlin.idea.roots.populateNonJvmSourceRootTypes
|
||||
import org.jetbrains.kotlin.platform.IdePlatformKind
|
||||
import org.jetbrains.kotlin.platform.SimplePlatform
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
|
||||
import org.jetbrains.kotlin.platform.impl.NativeIdePlatformKind
|
||||
import org.jetbrains.kotlin.platform.js.JsPlatform
|
||||
import org.jetbrains.kotlin.platform.jvm.JvmPlatform
|
||||
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
|
||||
import org.jetbrains.kotlin.platform.konan.NativePlatform
|
||||
import org.jetbrains.kotlin.platform.konan.NativePlatforms
|
||||
import org.jetbrains.plugins.gradle.model.data.BuildScriptClasspathData
|
||||
import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData
|
||||
@@ -47,30 +42,12 @@ import org.jetbrains.plugins.gradle.util.GradleConstants
|
||||
class KotlinSourceSetDataService : AbstractProjectDataService<GradleSourceSetData, Void>() {
|
||||
override fun getTargetDataKey() = GradleSourceSetData.KEY
|
||||
|
||||
private fun getProjectPlatforms(toImport: MutableCollection<DataNode<GradleSourceSetData>>): List<KotlinPlatform> {
|
||||
val platforms = HashSet<KotlinPlatform>()
|
||||
|
||||
for (nodeToImport in toImport) {
|
||||
nodeToImport.kotlinSourceSet?.also {
|
||||
platforms += it.actualPlatforms.platforms
|
||||
}
|
||||
|
||||
if (nodeToImport.parent?.children?.any { it.key.dataType.contains("Android") } == true) {
|
||||
platforms += KotlinPlatform.ANDROID
|
||||
}
|
||||
}
|
||||
|
||||
return platforms.toList()
|
||||
}
|
||||
|
||||
override fun postProcess(
|
||||
toImport: MutableCollection<DataNode<GradleSourceSetData>>,
|
||||
projectData: ProjectData?,
|
||||
project: Project,
|
||||
modelsProvider: IdeModifiableModelsProvider
|
||||
) {
|
||||
val projectPlatforms = getProjectPlatforms(toImport)
|
||||
|
||||
for (nodeToImport in toImport) {
|
||||
val mainModuleData = ExternalSystemApiUtil.findParent(
|
||||
nodeToImport,
|
||||
@@ -87,7 +64,7 @@ class KotlinSourceSetDataService : AbstractProjectDataService<GradleSourceSetDat
|
||||
populateNonJvmSourceRootTypes(nodeToImport, ideModule)
|
||||
}
|
||||
|
||||
configureFacet(sourceSetData, kotlinSourceSet, mainModuleData, ideModule, modelsProvider, projectPlatforms)?.let { facet ->
|
||||
configureFacet(sourceSetData, kotlinSourceSet, mainModuleData, ideModule, modelsProvider)?.let { facet ->
|
||||
GradleProjectImportHandler.getInstances(project).forEach { it.importBySourceSet(facet, nodeToImport) }
|
||||
}
|
||||
|
||||
@@ -114,59 +91,12 @@ class KotlinSourceSetDataService : AbstractProjectDataService<GradleSourceSetDat
|
||||
else -> KotlinModuleKind.DEFAULT
|
||||
}
|
||||
|
||||
private fun SimplePlatform.isRelevantFor(projectPlatforms: List<KotlinPlatform>): Boolean {
|
||||
val jvmPlatforms = listOf(KotlinPlatform.ANDROID, KotlinPlatform.JVM, KotlinPlatform.COMMON)
|
||||
return when (this) {
|
||||
is JvmPlatform -> projectPlatforms.intersect(jvmPlatforms).isNotEmpty()
|
||||
is JsPlatform -> KotlinPlatform.JS in projectPlatforms
|
||||
is NativePlatform -> KotlinPlatform.NATIVE in projectPlatforms
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
|
||||
private fun IdePlatformKind<*>.toSimplePlatforms(
|
||||
moduleData: ModuleData,
|
||||
isHmppModule: Boolean,
|
||||
projectPlatforms: List<KotlinPlatform>
|
||||
): Collection<SimplePlatform> {
|
||||
if (this is JvmIdePlatformKind) {
|
||||
val jvmTarget = JvmTarget.fromString(moduleData.targetCompatibility ?: "") ?: JvmTarget.DEFAULT
|
||||
return JvmPlatforms.jvmPlatformByTargetVersion(jvmTarget)
|
||||
}
|
||||
|
||||
if (this is NativeIdePlatformKind) {
|
||||
return NativePlatforms.nativePlatformByTargetNames(moduleData.konanTargets)
|
||||
}
|
||||
|
||||
return if (isHmppModule) {
|
||||
this.defaultPlatform.filter { it.isRelevantFor(projectPlatforms) }
|
||||
} else {
|
||||
this.defaultPlatform
|
||||
}
|
||||
}
|
||||
|
||||
fun configureFacet(
|
||||
moduleData: ModuleData,
|
||||
kotlinSourceSet: KotlinSourceSetInfo,
|
||||
mainModuleNode: DataNode<ModuleData>,
|
||||
ideModule: Module,
|
||||
modelsProvider: IdeModifiableModelsProvider
|
||||
) = configureFacet(
|
||||
moduleData,
|
||||
kotlinSourceSet,
|
||||
mainModuleNode,
|
||||
ideModule,
|
||||
modelsProvider,
|
||||
enumValues<KotlinPlatform>().toList()
|
||||
)
|
||||
|
||||
fun configureFacet(
|
||||
moduleData: ModuleData,
|
||||
kotlinSourceSet: KotlinSourceSetInfo,
|
||||
mainModuleNode: DataNode<ModuleData>,
|
||||
ideModule: Module,
|
||||
modelsProvider: IdeModifiableModelsProvider,
|
||||
projectPlatforms: List<KotlinPlatform>
|
||||
): KotlinFacet? {
|
||||
val compilerVersion = mainModuleNode
|
||||
.findAll(BuildScriptClasspathData.KEY)
|
||||
@@ -176,7 +106,18 @@ class KotlinSourceSetDataService : AbstractProjectDataService<GradleSourceSetDat
|
||||
|
||||
val platformKinds = kotlinSourceSet.actualPlatforms.platforms //TODO(auskov): fix calculation of jvm target
|
||||
.map { IdePlatformKindTooling.getTooling(it).kind }
|
||||
.flatMap { it.toSimplePlatforms(moduleData, mainModuleNode.isHmpp, projectPlatforms) }
|
||||
.flatMap { platformKind ->
|
||||
when (platformKind) {
|
||||
is JvmIdePlatformKind -> {
|
||||
val jvmTarget = JvmTarget.fromString(moduleData.targetCompatibility ?: "") ?: JvmTarget.DEFAULT
|
||||
JvmPlatforms.jvmPlatformByTargetVersion(jvmTarget)
|
||||
}
|
||||
is NativeIdePlatformKind -> {
|
||||
NativePlatforms.nativePlatformByTargetNames(moduleData.konanTargets)
|
||||
}
|
||||
else -> platformKind.defaultPlatform
|
||||
}
|
||||
}
|
||||
.distinct()
|
||||
.toSet()
|
||||
|
||||
|
||||
+12
-11
@@ -353,13 +353,14 @@ class HierarchicalMultiplatformProjectImportingTest : MultiplePluginVersionGradl
|
||||
val anyNative = NativePlatforms.unspecifiedNativePlatform
|
||||
val linux = NativePlatforms.nativePlatformBySingleTarget(KonanTarget.LINUX_X64)
|
||||
val macos = NativePlatforms.nativePlatformBySingleTarget(KonanTarget.MACOS_X64)
|
||||
val js = JsPlatforms.defaultJsPlatform
|
||||
|
||||
checkProjectStructure(exhaustiveModuleList = true, exhaustiveSourceSourceRootList = false, exhaustiveDependencyList = false) {
|
||||
module("my-app") {
|
||||
targetPlatform(jvm)
|
||||
}
|
||||
|
||||
module("my-app.commonMain") { targetPlatform(jvm, anyNative) }
|
||||
module("my-app.commonMain") { targetPlatform(jvm, anyNative, js) }
|
||||
module("my-app.commonTest") { targetPlatform(jvm, anyNative) }
|
||||
|
||||
module("my-app.jvmAndLinuxMain") { targetPlatform(jvm, anyNative) }
|
||||
@@ -395,7 +396,7 @@ class HierarchicalMultiplatformProjectImportingTest : MultiplePluginVersionGradl
|
||||
}
|
||||
|
||||
module("my-app.commonMain") { targetPlatform(jvm, anyNative, js) } // :( should be (jvm, anyNative)
|
||||
module("my-app.commonTest") { targetPlatform(jvm, anyNative, js) } // :( should be (jvm, anyNative)
|
||||
module("my-app.commonTest") { targetPlatform(jvm, anyNative) }
|
||||
|
||||
module("my-app.jvmAndLinuxMain") { targetPlatform(jvm, anyNative) }
|
||||
module("my-app.jvmAndLinuxTest") { targetPlatform(jvm, anyNative) }
|
||||
@@ -414,7 +415,7 @@ class HierarchicalMultiplatformProjectImportingTest : MultiplePluginVersionGradl
|
||||
module("my-app.submodule") { targetPlatform(jvm) }
|
||||
|
||||
module("my-app.submodule.commonMain") { targetPlatform(js, jvm, anyNative) } // :( should be (js, jvm)
|
||||
module("my-app.submodule.commonTest") { targetPlatform(js, jvm, anyNative) } // :( should be (js, jvm)
|
||||
module("my-app.submodule.commonTest") { targetPlatform(js, jvm) }
|
||||
|
||||
module("my-app.submodule.jvmMain") { targetPlatform(jvm) }
|
||||
module("my-app.submodule.jvmTest") { targetPlatform(jvm) }
|
||||
@@ -437,11 +438,11 @@ class HierarchicalMultiplatformProjectImportingTest : MultiplePluginVersionGradl
|
||||
checkProjectStructure(exhaustiveModuleList = false, exhaustiveSourceSourceRootList = false, exhaustiveDependencyList = false) {
|
||||
module("my-app.commonMain") {
|
||||
// must not be (jvm, js, native)
|
||||
targetPlatform(jvm, js)
|
||||
targetPlatform(jvm, js, native)
|
||||
}
|
||||
|
||||
module("my-app.orphan") {
|
||||
targetPlatform(jvm, js)
|
||||
targetPlatform(jvm, js, native)
|
||||
}
|
||||
module("my-app") {
|
||||
assertDiagnosticsCount<OrphanSourceSetsImportingDiagnostic>(1)
|
||||
@@ -461,7 +462,7 @@ class HierarchicalMultiplatformProjectImportingTest : MultiplePluginVersionGradl
|
||||
|
||||
checkProjectStructure(exhaustiveModuleList = false, exhaustiveSourceSourceRootList = false, exhaustiveDependencyList = false) {
|
||||
module("my-app.commonMain") {
|
||||
targetPlatform(jvm, js) // must not be (jvm, js, native)
|
||||
targetPlatform(jvm, js, native) // must not be (jvm, js, native)
|
||||
}
|
||||
|
||||
module("my-app.includedIntoJvm") {
|
||||
@@ -486,7 +487,7 @@ class HierarchicalMultiplatformProjectImportingTest : MultiplePluginVersionGradl
|
||||
|
||||
checkProjectStructure(exhaustiveModuleList = false, exhaustiveSourceSourceRootList = false, exhaustiveDependencyList = false) {
|
||||
module("my-app.commonMain") {
|
||||
targetPlatform(jvm, js) // must not be (jvm, js, native)
|
||||
targetPlatform(jvm, js, native) // must not be (jvm, js, native)
|
||||
}
|
||||
|
||||
module("my-app.intermediateBetweenJsAndCommon") {
|
||||
@@ -541,19 +542,19 @@ class HierarchicalMultiplatformProjectImportingTest : MultiplePluginVersionGradl
|
||||
|
||||
// (jvm, js, native) is highly undesirable
|
||||
module("my-app.danglingOnJvm") {
|
||||
targetPlatform(jvm, js)
|
||||
targetPlatform(jvm, js, native)
|
||||
}
|
||||
|
||||
module("my-app.commonMain") {
|
||||
targetPlatform(jvm, js)
|
||||
targetPlatform(jvm, js, native)
|
||||
}
|
||||
|
||||
module("my-app.danglingOnCommon") {
|
||||
targetPlatform(jvm, js)
|
||||
targetPlatform(jvm, js, native)
|
||||
}
|
||||
|
||||
module("my-app.danglingOnJvmAndJs") {
|
||||
targetPlatform(jvm, js)
|
||||
targetPlatform(jvm, js, native)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user