[JS IR BE] Some preparation for IrSerialization

This commit is contained in:
Roman Artemev
2019-01-16 20:35:42 +03:00
committed by romanart
parent d4b97d33ef
commit 3718edb6bc
5 changed files with 106 additions and 30 deletions
+4 -1
View File
@@ -15,6 +15,8 @@ node {
val antLauncherJar by configurations.creating
val testJsRuntime by configurations.creating
val generateIrRuntimeKlib by generator("org.jetbrains.kotlin.generators.tests.GenerateIrRuntimeKt")
dependencies {
testRuntime(intellijDep())
@@ -53,6 +55,7 @@ sourceSets {
projectTest {
dependsOn(":dist")
dependsOn(testJsRuntime)
dependsOn(generateIrRuntimeKlib)
jvmArgs("-da:jdk.nashorn.internal.runtime.RecompilableScriptFunctionData") // Disable assertion which fails due to a bug in nashorn (KT-23637)
workingDir = rootDir
if (findProperty("kotlin.compiler.js.ir.tests.skip")?.toString()?.toBoolean() == true) {
@@ -66,7 +69,7 @@ projectTest {
val prefixForPpropertiesToForward = "fd."
for ((key, value) in properties) {
if (key.startsWith(prefixForPpropertiesToForward)) {
systemProperty(key.substring(prefixForPpropertiesToForward.length), value)
systemProperty(key.substring(prefixForPpropertiesToForward.length), value!!)
}
}
}
@@ -0,0 +1,65 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.generators.tests
import com.intellij.openapi.Disposable
import com.intellij.openapi.vfs.StandardFileSystems
import com.intellij.openapi.vfs.VirtualFileManager
import com.intellij.psi.PsiManager
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.ir.backend.js.compile
import org.jetbrains.kotlin.js.test.runtimeSources
import org.jetbrains.kotlin.psi.KtFile
import java.io.File
fun buildConfiguration(environment: KotlinCoreEnvironment): CompilerConfiguration {
val runtimeConfiguration = environment.configuration.copy()
runtimeConfiguration.put(CommonConfigurationKeys.MODULE_NAME, "JS_IR_RUNTIME")
runtimeConfiguration.languageVersionSettings = LanguageVersionSettingsImpl(
LanguageVersion.LATEST_STABLE, ApiVersion.LATEST_STABLE,
specificFeatures = mapOf(
LanguageFeature.AllowContractsForCustomFunctions to LanguageFeature.State.ENABLED,
LanguageFeature.MultiPlatformProjects to LanguageFeature.State.ENABLED
),
analysisFlags = mapOf(
AnalysisFlags.useExperimental to listOf("kotlin.contracts.ExperimentalContracts", "kotlin.Experimental"),
AnalysisFlags.allowResultReturnType to true
)
)
return runtimeConfiguration
}
private val stdKlibFile = File("js/js.translator/testData/out/klibs/stdlib.klib")
fun main() {
val environment = KotlinCoreEnvironment.createForTests(Disposable { }, CompilerConfiguration(), EnvironmentConfigFiles.JS_CONFIG_FILES)
fun createPsiFile(fileName: String): KtFile {
val psiManager = PsiManager.getInstance(environment.project)
val fileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL)
val file = fileSystem.findFileByPath(fileName) ?: error("File not found: $fileName")
return psiManager.findFile(file) as KtFile
}
val result = compile(
environment.project,
runtimeSources.map(::createPsiFile),
buildConfiguration(environment),
null,
true,
emptyList(),
emptyList()
)
TODO("Write library into $stdKlibFile")
}
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.js.config.JsConfig
import org.jetbrains.kotlin.js.facade.MainCallParameters
import org.jetbrains.kotlin.js.facade.TranslationUnit
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.test.TargetBackend
import java.io.File
@@ -116,6 +117,7 @@ abstract class BasicIrBoxTest(
filesToCompile,
config.configuration,
listOf(FqName((testPackage?.let { "$it." } ?: "") + testFunction)),
false,
dependencies,
runtimeResult,
moduleType = if (isMainModule) ModuleType.MAIN else ModuleType.SECONDARY