[FIR] Properly setup dependant module data for metadata compilation

^KT-57377 Fixed
This commit is contained in:
Dmitriy Novozhilov
2023-03-28 21:20:58 +03:00
committed by Space Team
parent b2e03035a9
commit b9c61bbc60
5 changed files with 28 additions and 16 deletions
@@ -65,7 +65,7 @@ fun <F> prepareJvmSessions(
return prepareSessions( return prepareSessions(
files, configuration, rootModuleName, JvmPlatforms.unspecifiedJvmPlatform, files, configuration, rootModuleName, JvmPlatforms.unspecifiedJvmPlatform,
JvmPlatformAnalyzerServices, libraryList, isCommonSource, fileBelongsToModule, JvmPlatformAnalyzerServices, metadataCompilationMode = false, libraryList, isCommonSource, fileBelongsToModule,
createLibrarySession = { sessionProvider -> createLibrarySession = { sessionProvider ->
FirJvmSessionFactory.createLibrarySession( FirJvmSessionFactory.createLibrarySession(
rootModuleName, rootModuleName,
@@ -116,7 +116,7 @@ fun <F> prepareJsSessions(
): List<SessionWithSources<F>> { ): List<SessionWithSources<F>> {
return prepareSessions( return prepareSessions(
files, configuration, rootModuleName, JsPlatforms.defaultJsPlatform, JsPlatformAnalyzerServices, files, configuration, rootModuleName, JsPlatforms.defaultJsPlatform, JsPlatformAnalyzerServices,
libraryList, isCommonSource, fileBelongsToModule, metadataCompilationMode = false, libraryList, isCommonSource, fileBelongsToModule,
createLibrarySession = { sessionProvider -> createLibrarySession = { sessionProvider ->
FirJsSessionFactory.createLibrarySession( FirJsSessionFactory.createLibrarySession(
rootModuleName, rootModuleName,
@@ -161,7 +161,7 @@ fun <F> prepareNativeSessions(
): List<SessionWithSources<F>> { ): List<SessionWithSources<F>> {
return prepareSessions( return prepareSessions(
files, configuration, rootModuleName, NativePlatforms.unspecifiedNativePlatform, NativePlatformAnalyzerServices, files, configuration, rootModuleName, NativePlatforms.unspecifiedNativePlatform, NativePlatformAnalyzerServices,
libraryList, isCommonSource, fileBelongsToModule, createLibrarySession = { sessionProvider -> metadataCompilationMode = false, libraryList, isCommonSource, fileBelongsToModule, createLibrarySession = { sessionProvider ->
FirNativeSessionFactory.createLibrarySession( FirNativeSessionFactory.createLibrarySession(
rootModuleName, rootModuleName,
resolvedLibraries, resolvedLibraries,
@@ -186,10 +186,8 @@ fun <F> prepareNativeSessions(
/** /**
* Creates library session and sources session for Common platform (for metadata compilation) * Creates library session and sources session for Common platform (for metadata compilation)
* Number of created session depends on mode of MPP: * Number of created sessions is always one, in this mode modules are compiled against compiled
* - disabled * metadata of dependent modules
* - legacy (one platform and one common module)
* - HMPP (multiple number of modules)
*/ */
fun <F> prepareCommonSessions( fun <F> prepareCommonSessions(
files: List<F>, files: List<F>,
@@ -206,7 +204,7 @@ fun <F> prepareCommonSessions(
): List<SessionWithSources<F>> { ): List<SessionWithSources<F>> {
return prepareSessions( return prepareSessions(
files, configuration, rootModuleName, CommonPlatforms.defaultCommonPlatform, CommonPlatformAnalyzerServices, files, configuration, rootModuleName, CommonPlatforms.defaultCommonPlatform, CommonPlatformAnalyzerServices,
libraryList, isCommonSource, fileBelongsToModule, createLibrarySession = { sessionProvider -> metadataCompilationMode = true, libraryList, isCommonSource, fileBelongsToModule, createLibrarySession = { sessionProvider ->
FirCommonSessionFactory.createLibrarySession( FirCommonSessionFactory.createLibrarySession(
rootModuleName, rootModuleName,
sessionProvider, sessionProvider,
@@ -246,6 +244,7 @@ private inline fun <F> prepareSessions(
rootModuleName: Name, rootModuleName: Name,
targetPlatform: TargetPlatform, targetPlatform: TargetPlatform,
analyzerServices: PlatformDependentAnalyzerServices, analyzerServices: PlatformDependentAnalyzerServices,
metadataCompilationMode: Boolean,
libraryList: DependencyListForCliModule, libraryList: DependencyListForCliModule,
isCommonSource: (F) -> Boolean, isCommonSource: (F) -> Boolean,
fileBelongsToModule: (F, String) -> Boolean, fileBelongsToModule: (F, String) -> Boolean,
@@ -267,8 +266,8 @@ private inline fun <F> prepareSessions(
} }
return when { return when {
!isMppEnabled -> listOf( metadataCompilationMode || !isMppEnabled -> listOf(
createSessionForNonMppProject( createSingleSession(
files, rootModuleName, libraryList, targetPlatform, analyzerServices, files, rootModuleName, libraryList, targetPlatform, analyzerServices,
sessionProvider, sessionConfigurator, createSourceSession sessionProvider, sessionConfigurator, createSourceSession
) )
@@ -286,7 +285,7 @@ private inline fun <F> prepareSessions(
} }
} }
private inline fun <F> createSessionForNonMppProject( private inline fun <F> createSingleSession(
files: List<F>, files: List<F>,
rootModuleName: Name, rootModuleName: Name,
libraryList: DependencyListForCliModule, libraryList: DependencyListForCliModule,
@@ -299,7 +298,7 @@ private inline fun <F> createSessionForNonMppProject(
val platformModuleData = FirModuleDataImpl( val platformModuleData = FirModuleDataImpl(
rootModuleName, rootModuleName,
libraryList.regularDependencies, libraryList.regularDependencies,
dependsOnDependencies = emptyList(), libraryList.dependsOnDependencies,
libraryList.friendsDependencies, libraryList.friendsDependencies,
targetPlatform, targetPlatform,
analyzerServices analyzerServices
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.cli.jvm.compiler.pipeline.createContextForIncrementa
import org.jetbrains.kotlin.cli.jvm.compiler.pipeline.createIncrementalCompilationScope import org.jetbrains.kotlin.cli.jvm.compiler.pipeline.createIncrementalCompilationScope
import org.jetbrains.kotlin.cli.jvm.compiler.toAbstractProjectEnvironment import org.jetbrains.kotlin.cli.jvm.compiler.toAbstractProjectEnvironment
import org.jetbrains.kotlin.cli.jvm.config.JvmClasspathRoot import org.jetbrains.kotlin.cli.jvm.config.JvmClasspathRoot
import org.jetbrains.kotlin.cli.jvm.config.K2MetadataConfigurationKeys
import org.jetbrains.kotlin.cli.jvm.config.jvmClasspathRoots import org.jetbrains.kotlin.cli.jvm.config.jvmClasspathRoots
import org.jetbrains.kotlin.cli.jvm.config.jvmModularRoots import org.jetbrains.kotlin.cli.jvm.config.jvmModularRoots
import org.jetbrains.kotlin.config.CommonConfigurationKeys import org.jetbrains.kotlin.config.CommonConfigurationKeys
@@ -66,9 +67,11 @@ internal class FirMetadataSerializer(
CommonPlatformAnalyzerServices CommonPlatformAnalyzerServices
) )
val libraryList = DependencyListForCliModule.build(binaryModuleData) { val libraryList = DependencyListForCliModule.build(binaryModuleData) {
dependencies(configuration.jvmClasspathRoots.map { it.toPath() }) val refinedPaths = configuration.get(K2MetadataConfigurationKeys.REFINES_PATHS)?.map { File(it) }.orEmpty()
dependencies(configuration.jvmClasspathRoots.filter { it !in refinedPaths }.map { it.toPath() })
dependencies(configuration.jvmModularRoots.map { it.toPath() }) dependencies(configuration.jvmModularRoots.map { it.toPath() })
friendDependencies(configuration[JVMConfigurationKeys.FRIEND_PATHS] ?: emptyList()) friendDependencies(configuration[K2MetadataConfigurationKeys.FRIEND_PATHS] ?: emptyList())
dependsOnDependencies(refinedPaths.map { it.toPath() })
} }
val diagnosticsReporter = DiagnosticReporterFactory.createPendingReporter() val diagnosticsReporter = DiagnosticReporterFactory.createPendingReporter()
@@ -53,7 +53,7 @@ class CustomK2Tests : KGPBaseTest() {
} }
@GradleTest @GradleTest
@DisplayName("HMPP compilation without JS target. KT-57376, KT-57635") @DisplayName("HMPP compilation without JS target. KT-57376, KT-57377, KT-57635")
fun testHmppCompilationWithoutJsTarget(gradleVersion: GradleVersion) { fun testHmppCompilationWithoutJsTarget(gradleVersion: GradleVersion) {
with(project("k2-mpp-without-js", gradleVersion)) { with(project("k2-mpp-without-js", gradleVersion)) {
val taskToExecute = ":compileIntermediateMainKotlinMetadata" val taskToExecute = ":compileIntermediateMainKotlinMetadata"
@@ -0,0 +1,5 @@
// ISSUE: KT-57377
package kt57377
internal class StringBox(val value: String)
internal fun createBox(value: String): StringBox = StringBox(value)
@@ -0,0 +1,5 @@
// ISSUE: KT-57377
package kt57377
internal val testInternal1 = StringBox("foo")
internal val testInternal2 = createBox("foo")