Add logging into ideaModelDependencies

This commit is contained in:
Dmitry Savvinov
2020-07-09 12:13:43 +07:00
parent 010e530ac4
commit 21026001db
@@ -62,6 +62,7 @@ import org.jetbrains.kotlin.resolve.PlatformDependentAnalyzerServices
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformAnalyzerServices
import org.jetbrains.kotlin.types.typeUtil.closure
import org.jetbrains.kotlin.utils.addIfNotNull
import java.lang.StringBuilder
import java.util.*
internal val LOG = Logger.getInstance(IdeaModuleInfo::class.java)
@@ -139,19 +140,39 @@ private fun ideaModelDependencies(
forProduction: Boolean,
platform: TargetPlatform
): List<IdeaModuleInfo> {
// Use StringBuilder so that all lines are written into the log atomically (otherwise
// logs of call to ideaModelDependencies for several different modules interleave, leading
// to unreadable mess)
val debugString: StringBuilder? = if (LOG.isDebugEnabled) StringBuilder() else null
debugString?.appendLine("Building idea model dependencies for module $module, platform=${platform}, forProduction=$forProduction")
//NOTE: lib dependencies can be processed several times during recursive traversal
val result = LinkedHashSet<IdeaModuleInfo>()
val dependencyEnumerator = ModuleRootManager.getInstance(module).orderEntries().compileOnly().recursively().exportedOnly()
if (forProduction && module.getBuildSystemType() == BuildSystemType.JPS) {
dependencyEnumerator.productionOnly()
}
debugString?.append(" IDEA dependencies: [")
dependencyEnumerator.forEach { orderEntry ->
debugString?.append("${orderEntry.presentableName} ")
if (orderEntry.acceptAsDependency(forProduction)) {
result.addAll(orderEntryToModuleInfo(module.project, orderEntry!!, forProduction))
debugString?.append("OK; ")
} else {
debugString?.append("SKIP; ")
}
true
}
return result.filterNot { it is LibraryInfo && !platform.canDependOn(it.platform, module.isHMPPEnabled) }
debugString?.appendLine("]")
// Some dependencies prohibited (e.g. common can not depend on a platform)
val correctedResult = result.filterNot { it is LibraryInfo && !platform.canDependOn(it.platform, module.isHMPPEnabled) }
debugString?.appendLine(" Corrected result: ${correctedResult.joinToString(prefix = "[", postfix = "]", separator = ";") { it.displayedName }}")
LOG.debug(debugString?.toString())
return correctedResult
}
private fun TargetPlatform.canDependOn(other: TargetPlatform, isHmppEnabled: Boolean): Boolean {