From b3f6b78fbe287334bc87fc01de563ad74e5c9a31 Mon Sep 17 00:00:00 2001 From: "Aleksei.Cherepanov" Date: Mon, 29 Nov 2021 16:42:57 +0300 Subject: [PATCH] [CHERRY PICKED FROM IJ] Fix debug of incremental JPS tests in intellij repo Create extension of "load classes by parent classloader" logic to bypass clash of the same classes with different versions, loaded by different classloaders in case of running in-process compilation in debug configuration. #KT-49786 Fixed GitOrigin-RevId: 173749ef1a36fdb1df44e98f3d373941e00f29ad Original commit: https://github.com/JetBrains/intellij-community/commit/16e76333d4163c3772fa6e6ef3c1c7667a4c12f9 --- .../jps/build/AbstractIncrementalJpsTest.kt | 6 +++- .../kotlin/jps/build/KotlinBuilder.kt | 33 ++++++++++++++----- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt index ee8f831d880..3574f8e9df4 100644 --- a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt +++ b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/AbstractIncrementalJpsTest.kt @@ -15,6 +15,7 @@ */ package org.jetbrains.kotlin.jps.build + import com.intellij.openapi.Disposable import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.io.FileUtil @@ -101,6 +102,7 @@ abstract class AbstractIncrementalJpsTest( protected lateinit var workDir: File protected lateinit var projectDescriptor: ProjectDescriptor protected lateinit var additionalCommandLineArguments: List + // is used to compare lookup dumps in a human readable way (lookup symbols are hashed in an actual lookup storage) protected lateinit var lookupsDuringTest: MutableSet private var isJvmICEnabledBackup: Boolean = false @@ -150,6 +152,8 @@ abstract class AbstractIncrementalJpsTest( if (DEBUG_LOGGING_ENABLED) { enableDebugLogging() } + System.getProperties() + .setProperty("kotlin.jps.classPrefixesToLoadByParent", "kotlin.") // for debugging tests with in-process compiler } override fun tearDown() { @@ -402,7 +406,7 @@ abstract class AbstractIncrementalJpsTest( // null means one module private fun configureModules(): ModulesTxt? { JpsJavaExtensionService.getInstance().getOrCreateProjectExtension(myProject).outputUrl = - JpsPathUtil.pathToUrl(getAbsolutePath("out")) + JpsPathUtil.pathToUrl(getAbsolutePath("out")) val jdk = addJdk("my jdk") val modulesTxt = readModulesTxt() diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt index ee26bf8d919..3c3e8399041 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt @@ -71,17 +71,32 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) { const val SKIP_CACHE_VERSION_CHECK_PROPERTY = "kotlin.jps.skip.cache.version.check" const val JPS_KOTLIN_HOME_PROPERTY = "jps.kotlin.home" + private val classesToLoadByParentFromRegistry = + System.getProperty("kotlin.jps.classesToLoadByParent")?.split(',')?.map { it.trim() } ?: emptyList() + private val classPrefixesToLoadByParentFromRegistry = + System.getProperty("kotlin.jps.classPrefixesToLoadByParent")?.split(',')?.map { it.trim() } ?: emptyList() + val classesToLoadByParent: ClassCondition get() = ClassCondition { className -> - className.startsWith("org.jetbrains.kotlin.load.kotlin.incremental.components.") - || className.startsWith("org.jetbrains.kotlin.incremental.components.") - || className.startsWith("org.jetbrains.kotlin.incremental.js") - || className == "org.jetbrains.kotlin.config.Services" - || className.startsWith("org.apache.log4j.") // For logging from compiler - || className == "org.jetbrains.kotlin.progress.CompilationCanceledStatus" - || className == "org.jetbrains.kotlin.progress.CompilationCanceledException" - || className == "org.jetbrains.kotlin.modules.TargetId" - || className == "org.jetbrains.kotlin.cli.common.ExitCode" + val prefixes = listOf( + "org.apache.log4j.", // For logging from compiler + "org.jetbrains.kotlin.incremental.components.", + "org.jetbrains.kotlin.incremental.js", + "org.jetbrains.kotlin.load.kotlin.incremental.components." + ) + classPrefixesToLoadByParentFromRegistry + + val classes = listOf( + "org.jetbrains.kotlin.config.Services", + "org.jetbrains.kotlin.progress.CompilationCanceledStatus", + "org.jetbrains.kotlin.progress.CompilationCanceledException", + "org.jetbrains.kotlin.modules.TargetId", + "org.jetbrains.kotlin.cli.common.ExitCode" + ) + classesToLoadByParentFromRegistry + + prefixes.forEach { if (className.startsWith(it)) return@ClassCondition true } + classes.forEach { if (className == it) return@ClassCondition true } + + return@ClassCondition false } }