[Test] Unify work with KLIB artifact paths and dependencies
Unify functions from `JsEnvironmentConfigurator` and `WasmEnvironmentConfigurator` that do the same logic. Make this logic also be available for `NativeEnvironmentConfigurator`: - get*ArtifactSimpleName() - get*KlibArtifactPath() - get*KlibOutputDir() - getAllRecursiveLibrariesFor() - getAllRecursiveDependenciesFor() - getAllDependenciesMappingFor() - getKlibDependencies() This would allow to have the same logic in one place, and also reuse it in `IrBackendFacade`s to be implemented for Native. ^KT-65117
This commit is contained in:
committed by
Space Team
parent
7e9e064748
commit
f204293e4d
+2
-52
@@ -13,12 +13,9 @@ import org.jetbrains.kotlin.config.AnalysisFlags.allowFullyQualifiedNameInKClass
|
||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.LanguageVersion
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.TranslationMode
|
||||
import org.jetbrains.kotlin.js.config.*
|
||||
import org.jetbrains.kotlin.js.facade.MainCallParameters
|
||||
import org.jetbrains.kotlin.library.KotlinLibrary
|
||||
import org.jetbrains.kotlin.platform.js.JsPlatforms
|
||||
import org.jetbrains.kotlin.resolve.CompilerEnvironment
|
||||
import org.jetbrains.kotlin.resolve.TargetEnvironment
|
||||
@@ -37,11 +34,9 @@ import org.jetbrains.kotlin.test.directives.JsEnvironmentConfigurationDirectives
|
||||
import org.jetbrains.kotlin.test.directives.JsEnvironmentConfigurationDirectives.TYPED_ARRAYS
|
||||
import org.jetbrains.kotlin.test.directives.model.DirectivesContainer
|
||||
import org.jetbrains.kotlin.test.directives.model.RegisteredDirectives
|
||||
import org.jetbrains.kotlin.test.frontend.classic.moduleDescriptorProvider
|
||||
import org.jetbrains.kotlin.test.model.*
|
||||
import org.jetbrains.kotlin.test.services.*
|
||||
import org.jetbrains.kotlin.test.util.joinToArrayString
|
||||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.decapitalizeAsciiOnly
|
||||
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils
|
||||
import java.io.File
|
||||
|
||||
@@ -49,7 +44,7 @@ class JsEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfigu
|
||||
override val directiveContainers: List<DirectivesContainer>
|
||||
get() = listOf(JsEnvironmentConfigurationDirectives)
|
||||
|
||||
companion object {
|
||||
companion object : KlibBasedEnvironmentConfiguratorUtils {
|
||||
const val TEST_DATA_DIR_PATH = "js/js.translator/testData"
|
||||
const val OLD_MODULE_SUFFIX = "_old"
|
||||
|
||||
@@ -63,7 +58,6 @@ class JsEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfigu
|
||||
TranslationMode.PER_FILE_PROD_MINIMIZED_NAMES to "outPfMin"
|
||||
)
|
||||
|
||||
private const val OUTPUT_KLIB_DIR_NAME = "outputKlibDir"
|
||||
private const val MINIFICATION_OUTPUT_DIR_NAME = "minOutputDir"
|
||||
|
||||
object ExceptionThrowingReporter : JsConfig.Reporter() {
|
||||
@@ -81,12 +75,6 @@ class JsEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfigu
|
||||
}
|
||||
}
|
||||
|
||||
fun getJsArtifactSimpleName(testServices: TestServices, moduleName: String): String {
|
||||
val testName = testServices.testInfo.methodName.removePrefix("test").decapitalizeAsciiOnly()
|
||||
val outputFileSuffix = if (moduleName == ModuleStructureExtractor.DEFAULT_MODULE_NAME) "" else "-$moduleName"
|
||||
return testName + outputFileSuffix
|
||||
}
|
||||
|
||||
fun getJsModuleArtifactPath(testServices: TestServices, moduleName: String, translationMode: TranslationMode = TranslationMode.FULL_DEV): String {
|
||||
return getJsArtifactsOutputDir(testServices, translationMode).absolutePath + File.separator + getJsModuleArtifactName(testServices, moduleName)
|
||||
}
|
||||
@@ -96,11 +84,7 @@ class JsEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfigu
|
||||
}
|
||||
|
||||
fun getJsModuleArtifactName(testServices: TestServices, moduleName: String): String {
|
||||
return getJsArtifactSimpleName(testServices, moduleName) + "_v5"
|
||||
}
|
||||
|
||||
fun getJsKlibArtifactPath(testServices: TestServices, moduleName: String): String {
|
||||
return getJsKlibOutputDir(testServices).absolutePath + File.separator + getJsArtifactSimpleName(testServices, moduleName)
|
||||
return getKlibArtifactSimpleName(testServices, moduleName) + "_v5"
|
||||
}
|
||||
|
||||
fun getJsArtifactsOutputDir(testServices: TestServices, translationMode: TranslationMode = TranslationMode.FULL_DEV): File {
|
||||
@@ -111,10 +95,6 @@ class JsEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfigu
|
||||
return testServices.temporaryDirectoryManager.getOrCreateTempDirectory(outputDirByMode[translationMode]!! + "-recompiled")
|
||||
}
|
||||
|
||||
fun getJsKlibOutputDir(testServices: TestServices): File {
|
||||
return testServices.temporaryDirectoryManager.getOrCreateTempDirectory(OUTPUT_KLIB_DIR_NAME)
|
||||
}
|
||||
|
||||
fun getMinificationJsArtifactsOutputDir(testServices: TestServices): File {
|
||||
return testServices.temporaryDirectoryManager.getOrCreateTempDirectory(MINIFICATION_OUTPUT_DIR_NAME)
|
||||
}
|
||||
@@ -182,36 +162,6 @@ class JsEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfigu
|
||||
}
|
||||
}
|
||||
|
||||
fun getAllRecursiveDependenciesFor(module: TestModule, testServices: TestServices): Set<ModuleDescriptorImpl> {
|
||||
val visited = mutableSetOf<ModuleDescriptorImpl>()
|
||||
fun getRecursive(descriptor: ModuleDescriptor) {
|
||||
descriptor.allDependencyModules.forEach {
|
||||
if (it is ModuleDescriptorImpl && it !in visited) {
|
||||
visited += it
|
||||
getRecursive(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getRecursive(testServices.moduleDescriptorProvider.getModuleDescriptor(module))
|
||||
return visited
|
||||
}
|
||||
|
||||
fun getAllRecursiveLibrariesFor(module: TestModule, testServices: TestServices): Map<KotlinLibrary, ModuleDescriptorImpl> {
|
||||
val dependencies = getAllRecursiveDependenciesFor(module, testServices)
|
||||
return dependencies.associateBy { testServices.libraryProvider.getCompiledLibraryByDescriptor(it) }
|
||||
}
|
||||
|
||||
fun getAllDependenciesMappingFor(module: TestModule, testServices: TestServices): Map<KotlinLibrary, List<KotlinLibrary>> {
|
||||
val allRecursiveLibraries: Map<KotlinLibrary, ModuleDescriptor> = getAllRecursiveLibrariesFor(module, testServices)
|
||||
val m2l = allRecursiveLibraries.map { it.value to it.key }.toMap()
|
||||
|
||||
return allRecursiveLibraries.keys.associateWith { m ->
|
||||
val descriptor = allRecursiveLibraries[m] ?: error("No descriptor found for library ${m.libraryName}")
|
||||
descriptor.allDependencyModules.filter { it != descriptor }.map { m2l.getValue(it) }
|
||||
}
|
||||
}
|
||||
|
||||
fun TestModule.hasFilesToRecompile(): Boolean {
|
||||
return files.any { JsEnvironmentConfigurationDirectives.RECOMPILE in it.directives }
|
||||
}
|
||||
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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.test.services.configuration
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||
import org.jetbrains.kotlin.library.KotlinLibrary
|
||||
import org.jetbrains.kotlin.test.frontend.classic.moduleDescriptorProvider
|
||||
import org.jetbrains.kotlin.test.model.ArtifactKinds
|
||||
import org.jetbrains.kotlin.test.model.DependencyKind
|
||||
import org.jetbrains.kotlin.test.model.DependencyRelation
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.services.*
|
||||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.decapitalizeAsciiOnly
|
||||
import java.io.File
|
||||
|
||||
interface KlibBasedEnvironmentConfiguratorUtils {
|
||||
fun getKlibArtifactSimpleName(testServices: TestServices, moduleName: String): String {
|
||||
val testName = testServices.testInfo.methodName.removePrefix("test").decapitalizeAsciiOnly()
|
||||
val outputFileSuffix = if (moduleName == ModuleStructureExtractor.DEFAULT_MODULE_NAME) "" else "-$moduleName"
|
||||
return testName + outputFileSuffix
|
||||
}
|
||||
|
||||
fun getKlibArtifactFile(testServices: TestServices, moduleName: String): File {
|
||||
return getKlibOutputDir(testServices).resolve(getKlibArtifactSimpleName(testServices, moduleName))
|
||||
}
|
||||
|
||||
fun getKlibOutputDir(testServices: TestServices): File {
|
||||
return testServices.temporaryDirectoryManager.getOrCreateTempDirectory(OUTPUT_KLIB_DIR_NAME)
|
||||
}
|
||||
|
||||
fun getAllRecursiveLibrariesFor(module: TestModule, testServices: TestServices): Map<KotlinLibrary, ModuleDescriptorImpl> {
|
||||
val dependencies = getAllRecursiveDependenciesFor(module, testServices)
|
||||
return dependencies.associateBy { testServices.libraryProvider.getCompiledLibraryByDescriptor(it) }
|
||||
}
|
||||
|
||||
fun getAllRecursiveDependenciesFor(module: TestModule, testServices: TestServices): Set<ModuleDescriptorImpl> {
|
||||
val visited = mutableSetOf<ModuleDescriptorImpl>()
|
||||
fun getRecursive(descriptor: ModuleDescriptor) {
|
||||
descriptor.allDependencyModules.forEach {
|
||||
if (it is ModuleDescriptorImpl && it !in visited) {
|
||||
visited += it
|
||||
getRecursive(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getRecursive(testServices.moduleDescriptorProvider.getModuleDescriptor(module))
|
||||
return visited
|
||||
}
|
||||
|
||||
fun getAllDependenciesMappingFor(module: TestModule, testServices: TestServices): Map<KotlinLibrary, List<KotlinLibrary>> {
|
||||
val allRecursiveLibraries: Map<KotlinLibrary, ModuleDescriptor> = getAllRecursiveLibrariesFor(module, testServices)
|
||||
val m2l = allRecursiveLibraries.map { it.value to it.key }.toMap()
|
||||
|
||||
return allRecursiveLibraries.keys.associateWith { m ->
|
||||
val descriptor = allRecursiveLibraries[m] ?: error("No descriptor found for library ${m.libraryName}")
|
||||
descriptor.allDependencyModules.filter { it != descriptor }.map { m2l.getValue(it) }
|
||||
}
|
||||
}
|
||||
|
||||
fun getKlibDependencies(module: TestModule, testServices: TestServices, kind: DependencyRelation): List<File> {
|
||||
val visited = mutableSetOf<TestModule>()
|
||||
fun getRecursive(module: TestModule, relation: DependencyRelation) {
|
||||
val dependencies = if (relation == DependencyRelation.FriendDependency) {
|
||||
module.friendDependencies
|
||||
} else {
|
||||
module.regularDependencies
|
||||
}
|
||||
dependencies
|
||||
.filter { it.kind != DependencyKind.Source }
|
||||
.map { testServices.dependencyProvider.getTestModule(it.moduleName) }.forEach {
|
||||
if (it !in visited) {
|
||||
visited += it
|
||||
getRecursive(it, relation)
|
||||
}
|
||||
}
|
||||
}
|
||||
getRecursive(module, kind)
|
||||
return visited.map { testServices.dependencyProvider.getArtifact(it, ArtifactKinds.KLib).outputFile }
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val OUTPUT_KLIB_DIR_NAME = "outputKlibDir"
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.test.services.runtimeClasspathProviders
|
||||
import java.io.File
|
||||
|
||||
class NativeEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfigurator(testServices) {
|
||||
companion object {
|
||||
companion object : KlibBasedEnvironmentConfiguratorUtils {
|
||||
private val nativeHome
|
||||
get() = System.getProperty("kotlin.internal.native.test.nativeHome")
|
||||
?: error("No nativeHome provided. Are you sure the test are executed within :native:native.tests?")
|
||||
|
||||
+1
-75
@@ -11,11 +11,9 @@ import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.LanguageVersion
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||
import org.jetbrains.kotlin.js.config.JSConfigurationKeys
|
||||
import org.jetbrains.kotlin.js.config.SourceMapSourceEmbedding
|
||||
import org.jetbrains.kotlin.js.config.WasmTarget
|
||||
import org.jetbrains.kotlin.library.KotlinLibrary
|
||||
import org.jetbrains.kotlin.serialization.js.ModuleKind
|
||||
import org.jetbrains.kotlin.test.directives.JsEnvironmentConfigurationDirectives.INFER_MAIN_MODULE
|
||||
import org.jetbrains.kotlin.test.directives.JsEnvironmentConfigurationDirectives.PROPERTY_LAZY_INITIALIZATION
|
||||
@@ -24,7 +22,6 @@ import org.jetbrains.kotlin.test.directives.WasmEnvironmentConfigurationDirectiv
|
||||
import org.jetbrains.kotlin.test.directives.WasmEnvironmentConfigurationDirectives.DISABLE_WASM_EXCEPTION_HANDLING
|
||||
import org.jetbrains.kotlin.test.directives.model.DirectivesContainer
|
||||
import org.jetbrains.kotlin.test.directives.model.RegisteredDirectives
|
||||
import org.jetbrains.kotlin.test.frontend.classic.moduleDescriptorProvider
|
||||
import org.jetbrains.kotlin.test.model.ArtifactKinds
|
||||
import org.jetbrains.kotlin.test.model.DependencyKind
|
||||
import org.jetbrains.kotlin.test.model.DependencyRelation
|
||||
@@ -50,9 +47,7 @@ abstract class WasmEnvironmentConfigurator(testServices: TestServices) : Environ
|
||||
override val directiveContainers: List<DirectivesContainer>
|
||||
get() = listOf(WasmEnvironmentConfigurationDirectives)
|
||||
|
||||
companion object {
|
||||
private const val OUTPUT_KLIB_DIR_NAME = "outputKlibDir"
|
||||
|
||||
companion object : KlibBasedEnvironmentConfiguratorUtils {
|
||||
fun getRuntimePathsForModule(target: WasmTarget): List<String> {
|
||||
val suffix = when (target) {
|
||||
WasmTarget.JS -> "-js"
|
||||
@@ -62,75 +57,6 @@ abstract class WasmEnvironmentConfigurator(testServices: TestServices) : Environ
|
||||
return listOf(System.getProperty("kotlin.wasm$suffix.stdlib.path")!!, System.getProperty("kotlin.wasm$suffix.kotlin.test.path")!!)
|
||||
}
|
||||
|
||||
fun getKlibDependencies(module: TestModule, testServices: TestServices, kind: DependencyRelation): List<File> {
|
||||
val visited = mutableSetOf<TestModule>()
|
||||
fun getRecursive(module: TestModule, relation: DependencyRelation) {
|
||||
val dependencies = if (relation == DependencyRelation.FriendDependency) {
|
||||
module.friendDependencies
|
||||
} else {
|
||||
module.regularDependencies
|
||||
}
|
||||
dependencies
|
||||
.filter { it.kind != DependencyKind.Source }
|
||||
.map { testServices.dependencyProvider.getTestModule(it.moduleName) }.forEach {
|
||||
if (it !in visited) {
|
||||
visited += it
|
||||
getRecursive(it, relation)
|
||||
}
|
||||
}
|
||||
}
|
||||
getRecursive(module, kind)
|
||||
return visited.map { testServices.dependencyProvider.getArtifact(it, ArtifactKinds.KLib).outputFile }
|
||||
}
|
||||
|
||||
fun getDependencies(module: TestModule, testServices: TestServices, kind: DependencyRelation): List<ModuleDescriptor> {
|
||||
return getKlibDependencies(module, testServices, kind)
|
||||
.map { testServices.libraryProvider.getDescriptorByPath(it.absolutePath) }
|
||||
}
|
||||
|
||||
|
||||
fun getWasmKlibArtifactPath(testServices: TestServices, moduleName: String): String {
|
||||
return getWasmKlibOutputDir(testServices).absolutePath + File.separator + JsEnvironmentConfigurator.getJsArtifactSimpleName(
|
||||
testServices,
|
||||
moduleName
|
||||
)
|
||||
}
|
||||
|
||||
fun getWasmKlibOutputDir(testServices: TestServices): File {
|
||||
return testServices.temporaryDirectoryManager.getOrCreateTempDirectory(OUTPUT_KLIB_DIR_NAME)
|
||||
}
|
||||
|
||||
fun getAllRecursiveDependenciesFor(module: TestModule, testServices: TestServices): Set<ModuleDescriptorImpl> {
|
||||
val visited = mutableSetOf<ModuleDescriptorImpl>()
|
||||
fun getRecursive(descriptor: ModuleDescriptor) {
|
||||
descriptor.allDependencyModules.forEach {
|
||||
if (it is ModuleDescriptorImpl && it !in visited) {
|
||||
visited += it
|
||||
getRecursive(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getRecursive(testServices.moduleDescriptorProvider.getModuleDescriptor(module))
|
||||
return visited
|
||||
}
|
||||
|
||||
fun getAllRecursiveLibrariesFor(module: TestModule, testServices: TestServices): Map<KotlinLibrary, ModuleDescriptorImpl> {
|
||||
val dependencies = getAllRecursiveDependenciesFor(module, testServices)
|
||||
return dependencies.associateBy { testServices.libraryProvider.getCompiledLibraryByDescriptor(it) }
|
||||
}
|
||||
|
||||
fun getAllDependenciesMappingFor(module: TestModule, testServices: TestServices): Map<KotlinLibrary, List<KotlinLibrary>> {
|
||||
val allRecursiveLibraries: Map<KotlinLibrary, ModuleDescriptor> =
|
||||
getAllRecursiveLibrariesFor(module, testServices)
|
||||
val m2l = allRecursiveLibraries.map { it.value to it.key }.toMap()
|
||||
|
||||
return allRecursiveLibraries.keys.associateWith { m ->
|
||||
val descriptor = allRecursiveLibraries[m] ?: error("No descriptor found for library ${m.libraryName}")
|
||||
descriptor.allDependencyModules.filter { it != descriptor }.map { m2l.getValue(it) }
|
||||
}
|
||||
}
|
||||
|
||||
fun getMainModule(testServices: TestServices): TestModule {
|
||||
val modules = testServices.moduleStructure.modules
|
||||
val inferMainModule = INFER_MAIN_MODULE in testServices.moduleStructure.allDirectives
|
||||
|
||||
Reference in New Issue
Block a user