From 01e8019c4c06201c67d02f8a1c9cc510e1f40a92 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Fri, 5 Mar 2021 13:37:47 +0300 Subject: [PATCH] [FIR] Properly handle friend modules in modularized and full-pipeline tests --- .../kotlin/fir/AbstractModularizedTest.kt | 51 ++++++++++--------- .../FirResolveModularizedTotalKotlinTest.kt | 8 ++- .../kotlin/fir/FullPipelineModularizedTest.kt | 1 + 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/AbstractModularizedTest.kt b/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/AbstractModularizedTest.kt index dd1ce8dd24b..3df9dfe621d 100644 --- a/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/AbstractModularizedTest.kt +++ b/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/AbstractModularizedTest.kt @@ -28,20 +28,24 @@ data class ModuleData( val rawClasspath: List, val rawSources: List, val rawJavaSourceRoots: List, + val rawFriendDirs: List, val isCommon: Boolean ) { val qualifiedName get() = if (name in qualifier) qualifier else "$name.$qualifier" - val outputDir = File(ROOT_PATH_PREFIX, rawOutputDir.removePrefix("/")) - val classpath = rawClasspath.map { File(ROOT_PATH_PREFIX, it.removePrefix("/")) } - val sources = rawSources.map { File(ROOT_PATH_PREFIX, it.removePrefix("/")) } - val javaSourceRoots = rawJavaSourceRoots.map { File(ROOT_PATH_PREFIX, it.removePrefix("/")) } + val outputDir = rawOutputDir.fixPath() + val classpath = rawClasspath.map { it.fixPath() } + val sources = rawSources.map { it.fixPath() } + val javaSourceRoots = rawJavaSourceRoots.map { it.fixPath() } + val friendDirs = rawFriendDirs.map { it.fixPath() } lateinit var targetInfo: String var compilationError: String? = null var jvmInternalError: String? = null var exceptionMessage: String = "NO MESSAGE" } +private fun String.fixPath(): File = File(ROOT_PATH_PREFIX, this.removePrefix("/")) + private fun NodeList.toList(): List { val list = mutableListOf() for (index in 0 until this.length) { @@ -110,29 +114,30 @@ abstract class AbstractModularizedTest : KtUsefulTestCase() { val javaSourceRoots = mutableListOf() val classpath = mutableListOf() val sources = mutableListOf() + val friendDirs = mutableListOf() var isCommon = false for (index in 0 until moduleElement.childNodes.length) { val item = moduleElement.childNodes.item(index) - if (item.nodeName == "classpath") { - val path = item.attributes.getNamedItem("path").nodeValue - if (path != outputDir) { - classpath += path + when (item.nodeName) { + "classpath" -> { + val path = item.attributes.getNamedItem("path").nodeValue + if (path != outputDir) { + classpath += path + } } - } - if (item.nodeName == "javaSourceRoots") { - javaSourceRoots += item.attributes.getNamedItem("path").nodeValue - } - if (item.nodeName == "sources") { - sources += item.attributes.getNamedItem("path").nodeValue - } - if (item.nodeName == "commonSources") { - isCommon = true + "friendDir" -> { + val path = item.attributes.getNamedItem("path").nodeValue + friendDirs += path + } + "javaSourceRoots" -> javaSourceRoots += item.attributes.getNamedItem("path").nodeValue + "sources" -> sources += item.attributes.getNamedItem("path").nodeValue + "commonSources" -> isCommon = true } } - return ModuleData(moduleName, outputDir, moduleNameQualifier, classpath, sources, javaSourceRoots, isCommon) + return ModuleData(moduleName, outputDir, moduleNameQualifier, classpath, sources, javaSourceRoots, friendDirs, isCommon) } @@ -149,11 +154,11 @@ abstract class AbstractModularizedTest : KtUsefulTestCase() { println("BASE PATH: ${root.absolutePath}") val filterRegex = (System.getProperty("fir.bench.filter") ?: ".*").toRegex() - val modules = - root.listFiles().filter { it.extension == "xml" } - .sortedBy { it.lastModified() }.map { loadModule(it) } - .filter { it.rawOutputDir.matches(filterRegex) } - .filter { !it.isCommon } + val files = root.listFiles() ?: emptyArray() + val modules = files.filter { it.extension == "xml" } + .sortedBy { it.lastModified() }.map { loadModule(it) } + .filter { it.rawOutputDir.matches(filterRegex) } + .filter { !it.isCommon } for (module in modules.progress(step = 0.0) { "Analyzing ${it.qualifiedName}" }) { diff --git a/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/FirResolveModularizedTotalKotlinTest.kt b/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/FirResolveModularizedTotalKotlinTest.kt index 34bdda3aff0..161f58fda80 100644 --- a/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/FirResolveModularizedTotalKotlinTest.kt +++ b/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/FirResolveModularizedTotalKotlinTest.kt @@ -156,7 +156,13 @@ class FirResolveModularizedTotalKotlinTest : AbstractModularizedTest() { val scope = GlobalSearchScope.filesScope(project, ktFiles.map { it.virtualFile }) .uniteWith(TopDownAnalyzerFacadeForJVM.AllJavaSourcesInProjectScope(project)) val librariesScope = ProjectScope.getLibrariesScope(project) - val session = createSessionForTests(environment, scope, librariesScope, moduleData.qualifiedName) + val session = createSessionForTests( + environment, + scope, + librariesScope, + moduleData.qualifiedName, + moduleData.friendDirs.map { it.canonicalPath } + ) val scopeSession = ScopeSession() val processors = createAllCompilerResolveProcessors(session, scopeSession).let { if (RUN_CHECKERS) { diff --git a/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/FullPipelineModularizedTest.kt b/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/FullPipelineModularizedTest.kt index 4d2d061d344..685ea6301f2 100644 --- a/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/FullPipelineModularizedTest.kt +++ b/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/FullPipelineModularizedTest.kt @@ -208,6 +208,7 @@ class FullPipelineModularizedTest : AbstractModularizedTest() { args.freeArgs = moduleData.sources.map { it.absolutePath } val tmp = Files.createTempDirectory("compile-output") args.destination = tmp.toAbsolutePath().toFile().toString() + args.friendPaths = moduleData.friendDirs.map { it.canonicalPath }.toTypedArray() val manager = CompilerPerformanceManager() val services = Services.Builder().register(CommonCompilerPerformanceManager::class.java, manager).build() val collector = TestMessageCollector()