[analysis api fir] put every library into a separate KtModule in tests
This commit is contained in:
+9
@@ -55,3 +55,12 @@ class MultipleModuleDataProvider(private val moduleDataWithFilters: Map<FirModul
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
class EmptyModuleDataProvider(
|
||||
override val platform: TargetPlatform,
|
||||
override val analyzerServices: PlatformDependentAnalyzerServices
|
||||
) : ModuleDataProvider() {
|
||||
override val allModuleData: Collection<FirModuleData> get() = emptyList()
|
||||
|
||||
override fun getModuleData(path: Path?): FirModuleData? = null
|
||||
}
|
||||
|
||||
+6
@@ -25,6 +25,12 @@ abstract class AbstractEnvironmentConfigurator : ServicesAndDirectivesContainer
|
||||
abstract fun registerCompilerExtensions(project: Project, module: TestModule, configuration: CompilerConfiguration)
|
||||
}
|
||||
|
||||
class EnvironmentConfiguratorsProvider(internal val environmentConfigurators: List<AbstractEnvironmentConfigurator>) : TestService
|
||||
|
||||
internal val TestServices.environmentConfiguratorsProvider: EnvironmentConfiguratorsProvider by TestServices.testServiceAccessor()
|
||||
val TestServices.environmentConfigurators: List<AbstractEnvironmentConfigurator>
|
||||
get() = environmentConfiguratorsProvider.environmentConfigurators
|
||||
|
||||
abstract class EnvironmentConfigurator(protected val testServices: TestServices) : AbstractEnvironmentConfigurator() {
|
||||
protected val moduleStructure: TestModuleStructure
|
||||
get() = testServices.moduleStructure
|
||||
|
||||
+1
@@ -97,6 +97,7 @@ class TestConfigurationImpl(
|
||||
|
||||
init {
|
||||
testServices.apply {
|
||||
register(EnvironmentConfiguratorsProvider::class, EnvironmentConfiguratorsProvider(this@TestConfigurationImpl.environmentConfigurators))
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
val sourceFilePreprocessors = sourcePreprocessors.map { it.invoke(this@apply) }
|
||||
val sourceFileProvider = SourceFileProviderImpl(this, sourceFilePreprocessors)
|
||||
|
||||
+57
-46
@@ -103,6 +103,51 @@ class JvmEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfig
|
||||
else -> error("Too many jdk kinds passed: ${jdkKinds.joinToArrayString()}")
|
||||
}
|
||||
}
|
||||
|
||||
fun getLibraryFilesExceptRealRuntime(
|
||||
testServices: TestServices,
|
||||
configurationKind: ConfigurationKind,
|
||||
directives: RegisteredDirectives
|
||||
): List<File> {
|
||||
val provider = testServices.standardLibrariesPathProvider
|
||||
val files = mutableListOf<File>()
|
||||
if (configurationKind.withRuntime) {
|
||||
files.add(provider.kotlinTestJarForTests())
|
||||
} else if (configurationKind.withMockRuntime) {
|
||||
files.add(provider.minimalRuntimeJarForTests())
|
||||
files.add(provider.scriptRuntimeJarForTests())
|
||||
}
|
||||
if (configurationKind.withReflection) {
|
||||
files.add(provider.reflectJarForTests())
|
||||
}
|
||||
files.add(KtTestUtil.getAnnotationsJar())
|
||||
|
||||
if (JvmEnvironmentConfigurationDirectives.STDLIB_JDK8 in directives) {
|
||||
files.add(provider.runtimeJarForTestsWithJdk8())
|
||||
}
|
||||
files.add(KtTestUtil.getAnnotationsJar())
|
||||
return files
|
||||
}
|
||||
|
||||
fun getJdkHome(jdkKindTestJdkKind: TestJdkKind): File? = when (jdkKindTestJdkKind) {
|
||||
TestJdkKind.MOCK_JDK -> null
|
||||
TestJdkKind.MODIFIED_MOCK_JDK -> null
|
||||
TestJdkKind.FULL_JDK_6 -> File(System.getenv("JDK_16") ?: error("Environment variable JDK_16 is not set"))
|
||||
TestJdkKind.FULL_JDK_11 -> KtTestUtil.getJdk11Home()
|
||||
TestJdkKind.FULL_JDK_17 -> KtTestUtil.getJdk17Home()
|
||||
TestJdkKind.FULL_JDK -> if (SystemInfo.IS_AT_LEAST_JAVA9) File(System.getProperty("java.home")) else null
|
||||
TestJdkKind.ANDROID_API -> null
|
||||
}
|
||||
|
||||
fun getJdkClasspathRoot(jdkKind: TestJdkKind): File? = when (jdkKind) {
|
||||
TestJdkKind.MOCK_JDK -> KtTestUtil.findMockJdkRtJar()
|
||||
TestJdkKind.MODIFIED_MOCK_JDK -> KtTestUtil.findMockJdkRtModified()
|
||||
TestJdkKind.ANDROID_API -> KtTestUtil.findAndroidApiJar()
|
||||
TestJdkKind.FULL_JDK_6 -> null
|
||||
TestJdkKind.FULL_JDK_11 -> null
|
||||
TestJdkKind.FULL_JDK_17 -> null
|
||||
TestJdkKind.FULL_JDK -> null
|
||||
}
|
||||
}
|
||||
|
||||
override val directiveContainers: List<DirectivesContainer>
|
||||
@@ -136,34 +181,19 @@ class JvmEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfig
|
||||
configureDefaultJvmTarget(configuration)
|
||||
val registeredDirectives = module.directives
|
||||
|
||||
when (extractJdkKind(registeredDirectives)) {
|
||||
TestJdkKind.MOCK_JDK -> {
|
||||
configuration.addJvmClasspathRoot(KtTestUtil.findMockJdkRtJar())
|
||||
configuration.put(JVMConfigurationKeys.NO_JDK, true)
|
||||
}
|
||||
TestJdkKind.MODIFIED_MOCK_JDK -> {
|
||||
configuration.addJvmClasspathRoot(KtTestUtil.findMockJdkRtModified())
|
||||
configuration.put(JVMConfigurationKeys.NO_JDK, true)
|
||||
}
|
||||
TestJdkKind.FULL_JDK_6 -> {
|
||||
val jdk6 = System.getenv("JDK_16") ?: error("Environment variable JDK_16 is not set")
|
||||
configuration.put(JVMConfigurationKeys.JDK_HOME, File(jdk6))
|
||||
}
|
||||
TestJdkKind.FULL_JDK_11 -> {
|
||||
configuration.put(JVMConfigurationKeys.JDK_HOME, KtTestUtil.getJdk11Home())
|
||||
}
|
||||
TestJdkKind.FULL_JDK_17 -> {
|
||||
configuration.put(JVMConfigurationKeys.JDK_HOME, KtTestUtil.getJdk17Home())
|
||||
}
|
||||
TestJdkKind.FULL_JDK -> {
|
||||
if (SystemInfo.IS_AT_LEAST_JAVA9) {
|
||||
configuration.put(JVMConfigurationKeys.JDK_HOME, File(System.getProperty("java.home")))
|
||||
}
|
||||
}
|
||||
TestJdkKind.ANDROID_API -> {
|
||||
configuration.addJvmClasspathRoot(KtTestUtil.findAndroidApiJar())
|
||||
val jdkKind = extractJdkKind(registeredDirectives)
|
||||
getJdkHome(jdkKind)?.let { configuration.put(JVMConfigurationKeys.JDK_HOME, it) }
|
||||
getJdkClasspathRoot(jdkKind)?.let { configuration.addJvmClasspathRoot(it) }
|
||||
|
||||
when (jdkKind) {
|
||||
TestJdkKind.MOCK_JDK, TestJdkKind.MODIFIED_MOCK_JDK, TestJdkKind.ANDROID_API -> {
|
||||
configuration.put(JVMConfigurationKeys.NO_JDK, true)
|
||||
}
|
||||
|
||||
TestJdkKind.FULL_JDK_6 -> {}
|
||||
TestJdkKind.FULL_JDK_11 -> {}
|
||||
TestJdkKind.FULL_JDK_17 -> {}
|
||||
TestJdkKind.FULL_JDK -> {}
|
||||
}
|
||||
|
||||
val configurationKind = extractConfigurationKind(registeredDirectives).also {
|
||||
@@ -180,7 +210,7 @@ class JvmEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfig
|
||||
if (configurationKind.withRuntime) {
|
||||
configuration.configureStandardLibs(PathUtil.kotlinPathsForDistDirectory, K2JVMCompilerArguments().also { it.noReflect = true })
|
||||
}
|
||||
configuration.addJvmClasspathRoots(getLibraryFilesExceptRealRuntime(configurationKind, module.directives))
|
||||
configuration.addJvmClasspathRoots(getLibraryFilesExceptRealRuntime(testServices, configurationKind, module.directives))
|
||||
|
||||
val isIr = module.targetBackend?.isIR == true
|
||||
configuration.put(JVMConfigurationKeys.IR, isIr)
|
||||
@@ -373,25 +403,6 @@ class JvmEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfig
|
||||
)
|
||||
}
|
||||
|
||||
private fun getLibraryFilesExceptRealRuntime(configurationKind: ConfigurationKind, directives: RegisteredDirectives): List<File> {
|
||||
val provider = testServices.standardLibrariesPathProvider
|
||||
val files = mutableListOf<File>()
|
||||
if (configurationKind.withRuntime) {
|
||||
files.add(provider.kotlinTestJarForTests())
|
||||
} else if (configurationKind.withMockRuntime) {
|
||||
files.add(provider.minimalRuntimeJarForTests())
|
||||
files.add(provider.scriptRuntimeJarForTests())
|
||||
}
|
||||
if (configurationKind.withReflection) {
|
||||
files.add(provider.reflectJarForTests())
|
||||
}
|
||||
files.add(KtTestUtil.getAnnotationsJar())
|
||||
|
||||
if (JvmEnvironmentConfigurationDirectives.STDLIB_JDK8 in directives) {
|
||||
files.add(provider.runtimeJarForTestsWithJdk8())
|
||||
}
|
||||
files.add(KtTestUtil.getAnnotationsJar())
|
||||
return files
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user