-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ir-code-gen' of github.com:xebia-functional/AsFuture in…
…to ir-code-gen
- Loading branch information
Showing
22 changed files
with
487 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
compiler-plugin/src/test-gen/com/xebia/runners/BoxTestGenerated.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
|
||
package com.xebia.runners; | ||
|
||
import com.intellij.testFramework.TestDataPath; | ||
import org.jetbrains.kotlin.test.util.KtTestUtil; | ||
import org.jetbrains.kotlin.test.TargetBackend; | ||
import org.jetbrains.kotlin.test.TestMetadata; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.File; | ||
import java.util.regex.Pattern; | ||
|
||
/** This class is generated by {@link com.xebia.GenerateKotlinCompilerTestKt}. DO NOT MODIFY MANUALLY */ | ||
@SuppressWarnings("all") | ||
@TestMetadata("src/testData/box") | ||
@TestDataPath("$PROJECT_ROOT") | ||
public class BoxTestGenerated extends AbstractBoxTest { | ||
@Test | ||
public void testAllFilesPresentInBox() throws Exception { | ||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("src/testData/box"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); | ||
} | ||
|
||
@Test | ||
@TestMetadata("simple.kt") | ||
public void testSimple() throws Exception { | ||
runTest("src/testData/box/simple.kt"); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
compiler-plugin/src/test-gen/com/xebia/runners/DiagnosticTestGenerated.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
|
||
package com.xebia.runners; | ||
|
||
import com.intellij.testFramework.TestDataPath; | ||
import org.jetbrains.kotlin.test.util.KtTestUtil; | ||
import org.jetbrains.kotlin.test.TestMetadata; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.File; | ||
import java.util.regex.Pattern; | ||
|
||
/** This class is generated by {@link com.xebia.GenerateKotlinCompilerTestKt}. DO NOT MODIFY MANUALLY */ | ||
@SuppressWarnings("all") | ||
@TestMetadata("src/testData/diagnostics") | ||
@TestDataPath("$PROJECT_ROOT") | ||
public class DiagnosticTestGenerated extends AbstractDiagnosticTest { | ||
@Test | ||
public void testAllFilesPresentInDiagnostics() throws Exception { | ||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("src/testData/diagnostics"), Pattern.compile("^(.+)\\.kt$"), null, true); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
compiler-plugin/src/test/kotlin/com/xebia/generateKotlinCompilerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.xebia | ||
|
||
import com.xebia.runners.AbstractBoxTest | ||
import com.xebia.runners.AbstractDiagnosticTest | ||
import org.jetbrains.kotlin.generators.generateTestGroupSuiteWithJUnit5 | ||
|
||
fun main() { | ||
generateTestGroupSuiteWithJUnit5 { | ||
testGroup(testDataRoot = "src/testData", testsRoot = "src/test-gen") { | ||
testClass<AbstractDiagnosticTest> { | ||
model("diagnostics") | ||
} | ||
|
||
testClass<AbstractBoxTest> { | ||
model("box") | ||
} | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
compiler-plugin/src/test/kotlin/com/xebia/runners/AbstractBoxTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.xebia.runners | ||
|
||
import org.jetbrains.kotlin.test.TargetBackend | ||
import org.jetbrains.kotlin.test.backend.BlackBoxCodegenSuppressor | ||
import org.jetbrains.kotlin.test.backend.handlers.IrTextDumpHandler | ||
import org.jetbrains.kotlin.test.backend.handlers.IrTreeVerifierHandler | ||
import org.jetbrains.kotlin.test.backend.handlers.JvmBoxRunner | ||
import org.jetbrains.kotlin.test.backend.ir.JvmIrBackendFacade | ||
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder | ||
import org.jetbrains.kotlin.test.builders.fir2IrStep | ||
import org.jetbrains.kotlin.test.builders.irHandlersStep | ||
import org.jetbrains.kotlin.test.builders.jvmArtifactsHandlersStep | ||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.DUMP_IR | ||
import org.jetbrains.kotlin.test.runners.RunnerWithTargetBackendForTestGeneratorMarker | ||
|
||
open class AbstractBoxTest : BaseTestRunner(), RunnerWithTargetBackendForTestGeneratorMarker { | ||
override val targetBackend: TargetBackend = TargetBackend.JVM_IR | ||
|
||
override fun TestConfigurationBuilder.configuration() { | ||
defaultDirectives { +DUMP_IR } | ||
|
||
commonFirWithPluginFrontendConfiguration() | ||
fir2IrStep() | ||
irHandlersStep { | ||
useHandlers( | ||
::IrTextDumpHandler, | ||
::IrTreeVerifierHandler, | ||
) | ||
} | ||
facadeStep(::JvmIrBackendFacade) | ||
jvmArtifactsHandlersStep { useHandlers(::JvmBoxRunner) } | ||
|
||
useAfterAnalysisCheckers(::BlackBoxCodegenSuppressor) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
compiler-plugin/src/test/kotlin/com/xebia/runners/AbstractDiagnosticTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.xebia.runners | ||
|
||
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder | ||
import org.jetbrains.kotlin.test.services.EnvironmentBasedStandardLibrariesPathProvider | ||
import org.jetbrains.kotlin.test.services.KotlinStandardLibrariesPathProvider | ||
|
||
abstract class AbstractDiagnosticTest : BaseTestRunner() { | ||
override fun TestConfigurationBuilder.configuration() { | ||
commonFirWithPluginFrontendConfiguration() | ||
} | ||
|
||
override fun createKotlinStandardLibrariesPathProvider(): KotlinStandardLibrariesPathProvider { | ||
return EnvironmentBasedStandardLibrariesPathProvider | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
compiler-plugin/src/test/kotlin/com/xebia/runners/BaseTestRunner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.xebia.runners | ||
|
||
import com.xebia.services.ExtensionRegistrarConfigurator | ||
import com.xebia.services.PluginAnnotationsConfigurator | ||
import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoot | ||
import org.jetbrains.kotlin.cli.jvm.config.addJvmSdkRoots | ||
import org.jetbrains.kotlin.config.CompilerConfiguration | ||
import org.jetbrains.kotlin.config.JVMConfigurationKeys | ||
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms | ||
import org.jetbrains.kotlin.test.TargetBackend | ||
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder | ||
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives | ||
import org.jetbrains.kotlin.test.impl.testConfiguration | ||
import org.jetbrains.kotlin.test.initIdeaConfiguration | ||
import org.jetbrains.kotlin.test.model.DependencyKind | ||
import org.jetbrains.kotlin.test.model.TestModule | ||
import org.jetbrains.kotlin.test.runners.AbstractKotlinCompilerTest | ||
import org.jetbrains.kotlin.test.runners.baseFirDiagnosticTestConfiguration | ||
import org.jetbrains.kotlin.test.services.* | ||
import org.jetbrains.kotlin.utils.PathUtil | ||
import org.junit.jupiter.api.BeforeAll | ||
import java.io.File | ||
import java.util.concurrent.CompletableFuture | ||
import java.util.concurrent.Future | ||
|
||
abstract class BaseTestRunner : AbstractKotlinCompilerTest() { | ||
companion object { | ||
@BeforeAll | ||
@JvmStatic | ||
fun setUp() { | ||
initIdeaConfiguration() | ||
} | ||
} | ||
|
||
override fun createKotlinStandardLibrariesPathProvider(): KotlinStandardLibrariesPathProvider { | ||
return EnvironmentBasedStandardLibrariesPathProvider | ||
} | ||
} | ||
|
||
fun TestConfigurationBuilder.commonFirWithPluginFrontendConfiguration() { | ||
baseFirDiagnosticTestConfiguration() | ||
|
||
useCustomRuntimeClasspathProviders( | ||
::CustomClassPathProvider | ||
) | ||
|
||
defaultDirectives { | ||
+FirDiagnosticsDirectives.ENABLE_PLUGIN_PHASES | ||
+FirDiagnosticsDirectives.FIR_DUMP | ||
// +PreludeAdditionalFilesDirectives.ANNOTATION_DIRECTIVE | ||
// +PreludeAdditionalFilesDirectives.IDENTITY_DIRECTIVE | ||
} | ||
|
||
globalDefaults { | ||
targetBackend = TargetBackend.JVM_IR | ||
targetPlatform = JvmPlatforms.defaultJvmPlatform | ||
dependencyKind = DependencyKind.Binary | ||
} | ||
|
||
useConfigurators( | ||
::PluginAnnotationsConfigurator, | ||
::ExtensionRegistrarConfigurator, | ||
::CustomClassPathConfigurator | ||
) | ||
|
||
|
||
//useAdditionalSourceProviders(::PreludeProvider) | ||
} | ||
|
||
fun CustomClassPathConfigurator(testServices: TestServices): EnvironmentConfigurator = | ||
object : EnvironmentConfigurator(testServices) { | ||
override fun configureCompilerConfiguration(configuration: CompilerConfiguration, module: TestModule) { | ||
configuration.put(JVMConfigurationKeys.NO_JDK, false) | ||
configuration.put(JVMConfigurationKeys.JDK_HOME, File(System.getProperty("java.home"))) | ||
configuration.addJvmSdkRoots(PathUtil.getJdkClassesRootsFromCurrentJre()) | ||
configuration.addJvmClasspathRoot(File(System.getProperty("coroutines.lib"))) | ||
super.configureCompilerConfiguration(configuration, module) | ||
} | ||
} | ||
|
||
fun CustomClassPathProvider(testServices: TestServices): RuntimeClasspathProvider = | ||
object : RuntimeClasspathProvider(testServices) { | ||
override fun runtimeClassPaths(module: TestModule): List<File> { | ||
val jrt = PathUtil.getJdkClassesRootsFromCurrentJre() | ||
println("Adding JRE classpath roots: $jrt") | ||
return listOf(PluginAnnotationsConfigurator.jar(testServices)) + | ||
listOfNotNull(File(System.getProperty("coroutines.lib"))) + | ||
jrt | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
compiler-plugin/src/test/kotlin/com/xebia/services/ExtensionRegistrarConfigurator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.xebia.services | ||
|
||
import com.xebia.registerExtensionsCommon | ||
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar | ||
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi | ||
import org.jetbrains.kotlin.config.CompilerConfiguration | ||
import org.jetbrains.kotlin.test.model.TestModule | ||
import org.jetbrains.kotlin.test.services.EnvironmentConfigurator | ||
import org.jetbrains.kotlin.test.services.TestServices | ||
|
||
class ExtensionRegistrarConfigurator( | ||
testServices: TestServices, | ||
) : EnvironmentConfigurator(testServices) { | ||
@OptIn(ExperimentalCompilerApi::class) | ||
override fun CompilerPluginRegistrar.ExtensionStorage.registerCompilerExtensions( | ||
module: TestModule, | ||
configuration: CompilerConfiguration | ||
) { | ||
registerExtensionsCommon(configuration) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
compiler-plugin/src/test/kotlin/com/xebia/services/PluginAnnotationsConfigurator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.xebia.services | ||
|
||
import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoot | ||
import org.jetbrains.kotlin.config.CompilerConfiguration | ||
import org.jetbrains.kotlin.test.model.TestModule | ||
import org.jetbrains.kotlin.test.services.EnvironmentConfigurator | ||
import org.jetbrains.kotlin.test.services.TestServices | ||
import org.jetbrains.kotlin.test.services.assertions | ||
import java.io.FilenameFilter | ||
import java.io.File | ||
|
||
class PluginAnnotationsConfigurator(testServices: TestServices) : | ||
EnvironmentConfigurator(testServices) { | ||
|
||
companion object { | ||
private const val ANNOTATIONS_JAR_DIR = "../annotation/build/libs/" | ||
private val ANNOTATIONS_JAR_FILTER = FilenameFilter { _, name -> | ||
name.startsWith("annotation-jvm") && name.endsWith(".jar") | ||
} | ||
private val failMessage = { | ||
"Jar with annotations does not exist. Please run :annotation:jar" | ||
} | ||
fun jar(testServices: TestServices) = | ||
File(ANNOTATIONS_JAR_DIR).listFiles(ANNOTATIONS_JAR_FILTER)?.firstOrNull() | ||
?: testServices.assertions.fail(failMessage) | ||
} | ||
|
||
override fun configureCompilerConfiguration( | ||
configuration: CompilerConfiguration, | ||
module: TestModule | ||
) { | ||
val libDir = File(ANNOTATIONS_JAR_DIR) | ||
testServices.assertions.assertTrue(libDir.exists() && libDir.isDirectory, failMessage) | ||
val jar = jar(testServices) | ||
configuration.addJvmClasspathRoot(jar) | ||
} | ||
|
||
} |
Oops, something went wrong.