MPP: Allow 'implements' relation only within the same Gradle project

Also allow COMMON modules on the "implementer" side
This commit is contained in:
Alexey Sedunov
2018-09-14 17:24:40 +03:00
parent 9e6637dced
commit 619e2bc0db
6 changed files with 18 additions and 2 deletions
@@ -28,6 +28,9 @@ import org.jetbrains.kotlin.resolve.TargetPlatform
val Module.isNewMPPModule: Boolean val Module.isNewMPPModule: Boolean
get() = KotlinFacet.get(this)?.configuration?.settings?.kind?.isNewMPP ?: false get() = KotlinFacet.get(this)?.configuration?.settings?.kind?.isNewMPP ?: false
val Module.externalProjectId: String
get() = KotlinFacet.get(this)?.configuration?.settings?.externalProjectId ?: ""
val Module.isMPPModule: Boolean val Module.isMPPModule: Boolean
get() { get() {
val settings = KotlinFacet.get(this)?.configuration?.settings ?: return false val settings = KotlinFacet.get(this)?.configuration?.settings ?: return false
@@ -42,7 +45,7 @@ val Module.implementingModules: List<Module>
CachedValueProvider.Result( CachedValueProvider.Result(
if (isNewMPPModule) { if (isNewMPPModule) {
moduleManager.getModuleDependentModules(this).filter { moduleManager.getModuleDependentModules(this).filter {
it.isNewMPPModule && it.platform !is CommonIdePlatformKind.Platform it.isNewMPPModule && it.externalProjectId == externalProjectId
} }
} else { } else {
moduleManager.modules.filter { name in it.findOldFashionedImplementedModuleNames() } moduleManager.modules.filter { name in it.findOldFashionedImplementedModuleNames() }
@@ -56,7 +59,9 @@ val Module.implementedModules: List<Module>
CachedValueProvider { CachedValueProvider {
CachedValueProvider.Result( CachedValueProvider.Result(
if (isNewMPPModule) { if (isNewMPPModule) {
rootManager.dependencies.filter { it.isNewMPPModule && it.platform is CommonIdePlatformKind.Platform } rootManager.dependencies.filter {
it.isNewMPPModule && it.platform is CommonIdePlatformKind.Platform && it.externalProjectId == externalProjectId
}
} else { } else {
val modelsProvider = IdeModelsProviderImpl(project) val modelsProvider = IdeModelsProviderImpl(project)
findOldFashionedImplementedModuleNames().mapNotNull { modelsProvider.findIdeModule(it) } findOldFashionedImplementedModuleNames().mapNotNull { modelsProvider.findIdeModule(it) }
@@ -29,6 +29,7 @@ var DataNode<ModuleData>.kotlinAndroidSourceSets: List<KotlinSourceSetInfo>?
class KotlinSourceSetInfo(val kotlinModule: KotlinModule) { class KotlinSourceSetInfo(val kotlinModule: KotlinModule) {
var moduleId: String? = null var moduleId: String? = null
var gradleModuleId: String = ""
var platform: KotlinPlatform = KotlinPlatform.COMMON var platform: KotlinPlatform = KotlinPlatform.COMMON
var defaultCompilerArguments: CommonCompilerArguments? = null var defaultCompilerArguments: CommonCompilerArguments? = null
var compilerArguments: CommonCompilerArguments? = null var compilerArguments: CommonCompilerArguments? = null
@@ -619,6 +619,7 @@ open class KotlinMPPGradleProjectResolver : AbstractProjectResolverExtension() {
return KotlinSourceSetInfo(sourceSet).also { info -> return KotlinSourceSetInfo(sourceSet).also { info ->
val languageSettings = sourceSet.languageSettings val languageSettings = sourceSet.languageSettings
info.moduleId = getKotlinModuleId(gradleModule, sourceSet, resolverCtx) info.moduleId = getKotlinModuleId(gradleModule, sourceSet, resolverCtx)
info.gradleModuleId = getModuleId(resolverCtx, gradleModule)
info.platform = sourceSet.platform info.platform = sourceSet.platform
info.isTestModule = sourceSet.isTestModule info.isTestModule = sourceSet.isTestModule
info.compilerArguments = createCompilerArguments(emptyList(), sourceSet.platform).also { info.compilerArguments = createCompilerArguments(emptyList(), sourceSet.platform).also {
@@ -642,6 +643,7 @@ open class KotlinMPPGradleProjectResolver : AbstractProjectResolverExtension() {
): KotlinSourceSetInfo { ): KotlinSourceSetInfo {
return KotlinSourceSetInfo(compilation).also { sourceSetInfo -> return KotlinSourceSetInfo(compilation).also { sourceSetInfo ->
sourceSetInfo.moduleId = getKotlinModuleId(gradleModule, compilation, resolverCtx) sourceSetInfo.moduleId = getKotlinModuleId(gradleModule, compilation, resolverCtx)
sourceSetInfo.gradleModuleId = getModuleId(resolverCtx, gradleModule)
sourceSetInfo.platform = compilation.platform sourceSetInfo.platform = compilation.platform
sourceSetInfo.isTestModule = compilation.isTestModule sourceSetInfo.isTestModule = compilation.isTestModule
sourceSetInfo.compilerArguments = createCompilerArguments(compilation.arguments.currentArguments, compilation.platform).also { sourceSetInfo.compilerArguments = createCompilerArguments(compilation.arguments.currentArguments, compilation.platform).also {
@@ -119,6 +119,8 @@ class KotlinSourceSetDataService : AbstractProjectDataService<GradleSourceSetDat
isTestModule = kotlinSourceSet.isTestModule isTestModule = kotlinSourceSet.isTestModule
externalProjectId = kotlinSourceSet.gradleModuleId
sourceSetNames = kotlinSourceSet.sourceSetIdsByName.values.mapNotNull { sourceSetId -> sourceSetNames = kotlinSourceSet.sourceSetIdsByName.values.mapNotNull { sourceSetId ->
val node = mainModuleNode.findChildModuleById(sourceSetId) ?: return@mapNotNull null val node = mainModuleNode.findChildModuleById(sourceSetId) ?: return@mapNotNull null
val data = node.data as? ModuleData ?: return@mapNotNull null val data = node.data as? ModuleData ?: return@mapNotNull null
@@ -216,6 +216,8 @@ class KotlinFacetSettings {
var kind: KotlinModuleKind = KotlinModuleKind.DEFAULT var kind: KotlinModuleKind = KotlinModuleKind.DEFAULT
var sourceSetNames: List<String> = emptyList() var sourceSetNames: List<String> = emptyList()
var isTestModule: Boolean = false var isTestModule: Boolean = false
var externalProjectId: String = ""
} }
interface KotlinFacetSettingsProvider { interface KotlinFacetSettingsProvider {
@@ -132,6 +132,7 @@ private fun readV2AndLaterConfig(element: Element): KotlinFacetSettings {
} else null } else null
} ?: KotlinModuleKind.DEFAULT } ?: KotlinModuleKind.DEFAULT
isTestModule = element.getAttributeValue("isTestModule")?.toBoolean() ?: false isTestModule = element.getAttributeValue("isTestModule")?.toBoolean() ?: false
externalProjectId = element.getAttributeValue("externalProjectId") ?: ""
element.getChild("compilerSettings")?.let { element.getChild("compilerSettings")?.let {
compilerSettings = CompilerSettings() compilerSettings = CompilerSettings()
XmlSerializer.deserializeInto(compilerSettings!!, it) XmlSerializer.deserializeInto(compilerSettings!!, it)
@@ -292,6 +293,9 @@ private fun KotlinFacetSettings.writeLatestConfig(element: Element) {
element.addContent(Element("newMppModelJpsModuleKind").apply { addContent(kind.name) }) element.addContent(Element("newMppModelJpsModuleKind").apply { addContent(kind.name) })
element.setAttribute("isTestModule", isTestModule.toString()) element.setAttribute("isTestModule", isTestModule.toString())
} }
if (externalProjectId.isNotEmpty()) {
element.setAttribute("externalProjectId", externalProjectId)
}
productionOutputPath?.let { productionOutputPath?.let {
if (it != (compilerArguments as? K2JSCompilerArguments)?.outputFile) { if (it != (compilerArguments as? K2JSCompilerArguments)?.outputFile) {
element.addContent(Element("productionOutputPath").apply { addContent(PathUtil.toSystemIndependentName(it)) }) element.addContent(Element("productionOutputPath").apply { addContent(PathUtil.toSystemIndependentName(it)) })