From 6ffd3ed9709dc85035c00fc199eb78d7801e01c8 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Thu, 9 Feb 2023 01:01:18 +0100 Subject: [PATCH] Modularized tests. Support configuring known compiler plugins in FP test Construct compiler plugins classpath based on original compiler arguments Support of plugins in full pipeline test allows us to test projects where some common compiler plugins are used without excluding modules ^KT-56075 --- .../fir/modularized-tests/build.gradle.kts | 3 +++ .../AbstractFullPipelineModularizedTest.kt | 27 +++++++++++++++++++ .../kotlin/fir/FullPipelineModularizedTest.kt | 1 + 3 files changed, 31 insertions(+) diff --git a/compiler/fir/modularized-tests/build.gradle.kts b/compiler/fir/modularized-tests/build.gradle.kts index 6076556734b..7aa4bdca3fb 100644 --- a/compiler/fir/modularized-tests/build.gradle.kts +++ b/compiler/fir/modularized-tests/build.gradle.kts @@ -30,6 +30,8 @@ dependencies { testApi(project(":compiler:fir:semantics")) testApi(project(":compiler:fir:dump")) + testRuntimeOnly(project(":compiler:fir:plugin-utils")) + val asyncProfilerClasspath = project.findProperty("fir.bench.async.profiler.classpath") as? String if (asyncProfilerClasspath != null) { testRuntimeOnly(files(*asyncProfilerClasspath.split(File.pathSeparatorChar).toTypedArray())) @@ -42,6 +44,7 @@ sourceSets { } projectTest(minHeapSizeMb = 8192, maxHeapSizeMb = 8192, reservedCodeCacheSizeMb = 512) { + dependsOn(":dist") systemProperties(project.properties.filterKeys { it.startsWith("fir.") }) workingDir = rootDir diff --git a/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/AbstractFullPipelineModularizedTest.kt b/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/AbstractFullPipelineModularizedTest.kt index 8f73805ded8..bdc519f63a5 100644 --- a/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/AbstractFullPipelineModularizedTest.kt +++ b/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/AbstractFullPipelineModularizedTest.kt @@ -16,7 +16,11 @@ import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler import org.jetbrains.kotlin.config.Services import org.jetbrains.kotlin.fir.scopes.ProcessorAction import org.jetbrains.kotlin.modules.KotlinModuleXmlBuilder +import org.jetbrains.kotlin.test.kotlinPathsForDistDirectoryForTests import org.jetbrains.kotlin.util.PerformanceCounter +import org.jetbrains.kotlin.utils.KotlinPaths +import org.jetbrains.kotlin.utils.PathUtil +import java.io.File import java.io.FileOutputStream import java.io.PrintStream import java.nio.file.Files @@ -143,6 +147,12 @@ abstract class AbstractFullPipelineModularizedTest : AbstractModularizedTest() { args.progressiveMode = originalArguments.progressiveMode args.optIn = (moduleData.optInAnnotations + (originalArguments.optIn ?: emptyArray())).toTypedArray() args.allowKotlinPackage = originalArguments.allowKotlinPackage + + args.pluginOptions = originalArguments.pluginOptions + args.pluginClasspaths = originalArguments.pluginClasspaths?.mapNotNull { + substituteCompilerPluginPathForKnownPlugins(it)?.absolutePath + }?.toTypedArray() + } else { args.jvmTarget = JVM_TARGET args.allowKotlinPackage = true @@ -365,3 +375,20 @@ abstract class AbstractFullPipelineModularizedTest : AbstractModularizedTest() { } + + + +fun substituteCompilerPluginPathForKnownPlugins(path: String): File? { + val file = File(path) + val paths = PathUtil.kotlinPathsForDistDirectoryForTests + return when { + file.name.startsWith("kotlinx-serialization") || file.name.startsWith("kotlin-serialization") -> + paths.jar(KotlinPaths.Jar.SerializationPlugin) + file.name.startsWith("kotlin-sam-with-receiver") -> paths.jar(KotlinPaths.Jar.SamWithReceiver) + file.name.startsWith("kotlin-allopen") -> paths.jar(KotlinPaths.Jar.AllOpenPlugin) + file.name.startsWith("kotlin-noarg") -> paths.jar(KotlinPaths.Jar.NoArgPlugin) + file.name.startsWith("kotlin-lombok") -> paths.jar(KotlinPaths.Jar.LombokPlugin) + else -> null + } + +} \ No newline at end of file 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 39f1874c807..37ec77efd37 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 @@ -20,6 +20,7 @@ class FullPipelineModularizedTest : AbstractFullPipelineModularizedTest() { args.useK2 = true args.useIR = true args.languageVersion = LANGUAGE_VERSION_K2 + // TODO: Remove when support for old modularized tests is removed if (moduleData.arguments == null) { args.apiVersion = API_VERSION