[JS TEST] Refactor test runner a bit
Build IC cache for library right after its compilation
This commit is contained in:
committed by
teamcityserver
parent
0310f7cb0b
commit
f768d5b453
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.idea.KotlinFileType
|
|||||||
import org.jetbrains.kotlin.incremental.js.IncrementalDataProviderImpl
|
import org.jetbrains.kotlin.incremental.js.IncrementalDataProviderImpl
|
||||||
import org.jetbrains.kotlin.incremental.js.IncrementalResultsConsumerImpl
|
import org.jetbrains.kotlin.incremental.js.IncrementalResultsConsumerImpl
|
||||||
import org.jetbrains.kotlin.incremental.js.TranslationResultValue
|
import org.jetbrains.kotlin.incremental.js.TranslationResultValue
|
||||||
|
import org.jetbrains.kotlin.ir.backend.js.ic.SerializedIcData
|
||||||
import org.jetbrains.kotlin.js.JavaScript
|
import org.jetbrains.kotlin.js.JavaScript
|
||||||
import org.jetbrains.kotlin.js.backend.JsToStringGenerationVisitor
|
import org.jetbrains.kotlin.js.backend.JsToStringGenerationVisitor
|
||||||
import org.jetbrains.kotlin.js.backend.ast.*
|
import org.jetbrains.kotlin.js.backend.ast.*
|
||||||
@@ -190,6 +191,7 @@ abstract class BasicBoxTest(
|
|||||||
}
|
}
|
||||||
val testModuleName = if (runPlainBoxFunction) null else mainModuleName
|
val testModuleName = if (runPlainBoxFunction) null else mainModuleName
|
||||||
val mainModule = modules[mainModuleName] ?: error("No module with name \"$mainModuleName\"")
|
val mainModule = modules[mainModuleName] ?: error("No module with name \"$mainModuleName\"")
|
||||||
|
val icCache = mutableMapOf<String, SerializedIcData>()
|
||||||
|
|
||||||
val generatedJsFiles = orderedModules.asReversed().mapNotNull { module ->
|
val generatedJsFiles = orderedModules.asReversed().mapNotNull { module ->
|
||||||
val dependencies = module.dependenciesSymbols.map { modules[it]?.outputFileName(outputDir) + ".meta.js" }
|
val dependencies = module.dependenciesSymbols.map { modules[it]?.outputFileName(outputDir) + ".meta.js" }
|
||||||
@@ -230,7 +232,8 @@ abstract class BasicBoxTest(
|
|||||||
safeExternalBoolean,
|
safeExternalBoolean,
|
||||||
safeExternalBooleanDiagnostic,
|
safeExternalBooleanDiagnostic,
|
||||||
skipMangleVerification,
|
skipMangleVerification,
|
||||||
abiVersion
|
abiVersion,
|
||||||
|
icCache
|
||||||
)
|
)
|
||||||
|
|
||||||
when {
|
when {
|
||||||
@@ -487,7 +490,8 @@ abstract class BasicBoxTest(
|
|||||||
safeExternalBoolean: Boolean,
|
safeExternalBoolean: Boolean,
|
||||||
safeExternalBooleanDiagnostic: RuntimeDiagnostic?,
|
safeExternalBooleanDiagnostic: RuntimeDiagnostic?,
|
||||||
skipMangleVerification: Boolean,
|
skipMangleVerification: Boolean,
|
||||||
abiVersion: KotlinAbiVersion
|
abiVersion: KotlinAbiVersion,
|
||||||
|
icCache: MutableMap<String, SerializedIcData>
|
||||||
) {
|
) {
|
||||||
val kotlinFiles = module.files.filter { it.fileName.endsWith(".kt") }
|
val kotlinFiles = module.files.filter { it.fileName.endsWith(".kt") }
|
||||||
val testFiles = kotlinFiles.map { it.fileName }
|
val testFiles = kotlinFiles.map { it.fileName }
|
||||||
@@ -541,7 +545,8 @@ abstract class BasicBoxTest(
|
|||||||
safeExternalBoolean,
|
safeExternalBoolean,
|
||||||
safeExternalBooleanDiagnostic,
|
safeExternalBooleanDiagnostic,
|
||||||
skipMangleVerification,
|
skipMangleVerification,
|
||||||
abiVersion
|
abiVersion,
|
||||||
|
icCache
|
||||||
)
|
)
|
||||||
|
|
||||||
if (incrementalCompilationChecksEnabled && module.hasFilesToRecompile) {
|
if (incrementalCompilationChecksEnabled && module.hasFilesToRecompile) {
|
||||||
@@ -639,7 +644,8 @@ abstract class BasicBoxTest(
|
|||||||
safeExternalBoolean = false,
|
safeExternalBoolean = false,
|
||||||
safeExternalBooleanDiagnostic = null,
|
safeExternalBooleanDiagnostic = null,
|
||||||
skipMangleVerification = false,
|
skipMangleVerification = false,
|
||||||
abiVersion = KotlinAbiVersion.CURRENT
|
abiVersion = KotlinAbiVersion.CURRENT,
|
||||||
|
mutableMapOf()
|
||||||
)
|
)
|
||||||
|
|
||||||
val originalOutput = FileUtil.loadFile(outputFile)
|
val originalOutput = FileUtil.loadFile(outputFile)
|
||||||
@@ -722,7 +728,8 @@ abstract class BasicBoxTest(
|
|||||||
safeExternalBoolean: Boolean,
|
safeExternalBoolean: Boolean,
|
||||||
safeExternalBooleanDiagnostic: RuntimeDiagnostic?,
|
safeExternalBooleanDiagnostic: RuntimeDiagnostic?,
|
||||||
skipMangleVerification: Boolean,
|
skipMangleVerification: Boolean,
|
||||||
abiVersion: KotlinAbiVersion
|
abiVersion: KotlinAbiVersion,
|
||||||
|
icCache: MutableMap<String, SerializedIcData>
|
||||||
) {
|
) {
|
||||||
val translator = K2JSTranslator(config, false)
|
val translator = K2JSTranslator(config, false)
|
||||||
val translationResult = translator.translateUnits(ExceptionThrowingReporter, units, mainCallParameters)
|
val translationResult = translator.translateUnits(ExceptionThrowingReporter, units, mainCallParameters)
|
||||||
|
|||||||
@@ -89,7 +89,6 @@ abstract class BasicIrBoxTest(
|
|||||||
|
|
||||||
override val testChecker get() = if (runTestInNashorn) NashornIrJsTestChecker() else V8IrJsTestChecker
|
override val testChecker get() = if (runTestInNashorn) NashornIrJsTestChecker() else V8IrJsTestChecker
|
||||||
|
|
||||||
@Suppress("ConstantConditionIf")
|
|
||||||
override fun translateFiles(
|
override fun translateFiles(
|
||||||
units: List<TranslationUnit>,
|
units: List<TranslationUnit>,
|
||||||
outputFile: File,
|
outputFile: File,
|
||||||
@@ -111,7 +110,8 @@ abstract class BasicIrBoxTest(
|
|||||||
safeExternalBoolean: Boolean,
|
safeExternalBoolean: Boolean,
|
||||||
safeExternalBooleanDiagnostic: RuntimeDiagnostic?,
|
safeExternalBooleanDiagnostic: RuntimeDiagnostic?,
|
||||||
skipMangleVerification: Boolean,
|
skipMangleVerification: Boolean,
|
||||||
abiVersion: KotlinAbiVersion
|
abiVersion: KotlinAbiVersion,
|
||||||
|
icCache: MutableMap<String, SerializedIcData>
|
||||||
) {
|
) {
|
||||||
val filesToCompile = units.map { (it as TranslationUnit.SourceFile).file }
|
val filesToCompile = units.map { (it as TranslationUnit.SourceFile).file }
|
||||||
|
|
||||||
@@ -125,6 +125,8 @@ abstract class BasicIrBoxTest(
|
|||||||
|
|
||||||
val klibPath = outputFile.absolutePath.replace("_v5.js", "/")
|
val klibPath = outputFile.absolutePath.replace("_v5.js", "/")
|
||||||
|
|
||||||
|
prepareRuntimePirCaches(config, icCache)
|
||||||
|
|
||||||
if (isMainModule && klibMainModule) {
|
if (isMainModule && klibMainModule) {
|
||||||
generateKLib(
|
generateKLib(
|
||||||
project = config.project,
|
project = config.project,
|
||||||
@@ -173,29 +175,6 @@ abstract class BasicIrBoxTest(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!skipRegularMode) {
|
if (!skipRegularMode) {
|
||||||
val icCache: Map<String, SerializedIcData> = if (!runIcMode) emptyMap() else {
|
|
||||||
val map = mutableMapOf<String, SerializedIcData>()
|
|
||||||
for (path in allKlibPaths) {
|
|
||||||
val icData = predefinedKlibHasIcCache[path] ?: prepareSingleLibraryIcCache(
|
|
||||||
project = project,
|
|
||||||
analyzer = AnalyzerWithCompilerReport(config.configuration),
|
|
||||||
configuration = config.configuration,
|
|
||||||
libPath = path,
|
|
||||||
dependencies = allKlibPaths,
|
|
||||||
icCache = map
|
|
||||||
)
|
|
||||||
|
|
||||||
if (path in predefinedKlibHasIcCache) {
|
|
||||||
predefinedKlibHasIcCache[path] = icData
|
|
||||||
}
|
|
||||||
|
|
||||||
map[path] = icData
|
|
||||||
}
|
|
||||||
|
|
||||||
map
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
val irFactory = if (lowerPerModule) PersistentIrFactory() else IrFactoryImpl
|
val irFactory = if (lowerPerModule) PersistentIrFactory() else IrFactoryImpl
|
||||||
val compiledModule = compile(
|
val compiledModule = compile(
|
||||||
project = config.project,
|
project = config.project,
|
||||||
@@ -269,12 +248,47 @@ abstract class BasicIrBoxTest(
|
|||||||
null
|
null
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (runIcMode) {
|
||||||
|
icCache[actualOutputFile] = createPirCache(actualOutputFile, allKlibPaths + actualOutputFile, config, icCache)
|
||||||
|
}
|
||||||
|
|
||||||
logger.logFile("Output klib", File(actualOutputFile))
|
logger.logFile("Output klib", File(actualOutputFile))
|
||||||
|
|
||||||
compilationCache[outputFile.name.replace(".js", ".meta.js")] = actualOutputFile
|
compilationCache[outputFile.name.replace(".js", ".meta.js")] = actualOutputFile
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun createPirCache(path: String, allKlibPaths: Collection<String>, config: JsConfig, icCache: Map<String, SerializedIcData>): SerializedIcData {
|
||||||
|
val icData = predefinedKlibHasIcCache[path] ?: prepareSingleLibraryIcCache(
|
||||||
|
project = project,
|
||||||
|
analyzer = AnalyzerWithCompilerReport(config.configuration),
|
||||||
|
configuration = config.configuration,
|
||||||
|
libPath = path,
|
||||||
|
dependencies = allKlibPaths,
|
||||||
|
icCache = icCache
|
||||||
|
)
|
||||||
|
|
||||||
|
if (path in predefinedKlibHasIcCache) {
|
||||||
|
predefinedKlibHasIcCache[path] = icData
|
||||||
|
}
|
||||||
|
|
||||||
|
return icData
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun prepareRuntimePirCaches(config: JsConfig, icCache: MutableMap<String, SerializedIcData>) {
|
||||||
|
if (!runIcMode) return
|
||||||
|
|
||||||
|
val defaultRuntimePath = File(defaultRuntimeKlib).canonicalPath
|
||||||
|
icCache[defaultRuntimePath] = createPirCache(defaultRuntimePath, listOf(defaultRuntimePath), config, icCache)
|
||||||
|
|
||||||
|
val fullRuntimePath = File(fullRuntimeKlib).canonicalPath
|
||||||
|
icCache[fullRuntimePath] = createPirCache(fullRuntimePath, listOf(fullRuntimePath), config, icCache)
|
||||||
|
|
||||||
|
val testKlibPath = File(kotlinTestKLib).canonicalPath
|
||||||
|
icCache[testKlibPath] = createPirCache(testKlibPath, listOf(fullRuntimePath, testKlibPath), config, icCache)
|
||||||
|
}
|
||||||
|
|
||||||
private fun fromSysPropertyOrAll(key: String, all: Set<AnyNamedPhase>): Set<AnyNamedPhase> {
|
private fun fromSysPropertyOrAll(key: String, all: Set<AnyNamedPhase>): Set<AnyNamedPhase> {
|
||||||
val phases = System.getProperty(key)?.split(',')?.toSet() ?: emptySet()
|
val phases = System.getProperty(key)?.split(',')?.toSet() ?: emptySet()
|
||||||
if (phases.isEmpty()) return all
|
if (phases.isEmpty()) return all
|
||||||
@@ -290,10 +304,10 @@ abstract class BasicIrBoxTest(
|
|||||||
val dependencyPaths = mutableListOf<String>()
|
val dependencyPaths = mutableListOf<String>()
|
||||||
|
|
||||||
dependencies.forEach { (moduleId, outputs) ->
|
dependencies.forEach { (moduleId, outputs) ->
|
||||||
val wrappedCode = wrapWithModuleEmulationMarkers(outputs.jsCode, config.moduleKind, moduleId)
|
val moduleWrappedCode = wrapWithModuleEmulationMarkers(outputs.jsCode, config.moduleKind, moduleId)
|
||||||
val dependencyPath = outputFile.absolutePath.replace("_v5.js", "-${moduleId}_v5.js")
|
val dependencyPath = outputFile.absolutePath.replace("_v5.js", "-${moduleId}_v5.js")
|
||||||
dependencyPaths += dependencyPath
|
dependencyPaths += dependencyPath
|
||||||
File(dependencyPath).write(wrappedCode)
|
File(dependencyPath).write(moduleWrappedCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
cachedDependencies[outputFile.absolutePath] = dependencyPaths
|
cachedDependencies[outputFile.absolutePath] = dependencyPaths
|
||||||
|
|||||||
Reference in New Issue
Block a user