[Test] Fix extracting path to standard libraries from incorrect places for external users
This commit is contained in:
committed by
teamcity
parent
09c9641e23
commit
7fa459044f
@@ -63,9 +63,9 @@ fun checkKotlinPackageUsage(configuration: CompilerConfiguration, files: Collect
|
|||||||
fun checkKotlinPackageUsage(configuration: CompilerConfiguration, files: Collection<KtFile>): Boolean =
|
fun checkKotlinPackageUsage(configuration: CompilerConfiguration, files: Collection<KtFile>): Boolean =
|
||||||
checkKotlinPackageUsage(configuration, files, configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE))
|
checkKotlinPackageUsage(configuration, files, configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE))
|
||||||
|
|
||||||
fun getLibraryFromHome(
|
fun <PathProvider : Any> getLibraryFromHome(
|
||||||
paths: KotlinPaths?,
|
paths: PathProvider?,
|
||||||
getLibrary: (KotlinPaths) -> File,
|
getLibrary: (PathProvider) -> File,
|
||||||
libraryName: String,
|
libraryName: String,
|
||||||
messageCollector: MessageCollector,
|
messageCollector: MessageCollector,
|
||||||
noLibraryArgument: String
|
noLibraryArgument: String
|
||||||
|
|||||||
@@ -178,10 +178,26 @@ fun CompilerConfiguration.configureContentRootsFromClassPath(arguments: K2JVMCom
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun CompilerConfiguration.configureStandardLibs(paths: KotlinPaths?, arguments: K2JVMCompilerArguments) {
|
fun CompilerConfiguration.configureStandardLibs(paths: KotlinPaths?, arguments: K2JVMCompilerArguments) {
|
||||||
|
configureStandardLibs(
|
||||||
|
paths,
|
||||||
|
KotlinPaths::stdlibPath,
|
||||||
|
KotlinPaths::scriptRuntimePath,
|
||||||
|
KotlinPaths::reflectPath,
|
||||||
|
arguments
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <PathProvider : Any> CompilerConfiguration.configureStandardLibs(
|
||||||
|
paths: PathProvider?,
|
||||||
|
stdlibPath: (PathProvider) -> File,
|
||||||
|
scriptRuntimePath: (PathProvider) -> File,
|
||||||
|
reflectPath: (PathProvider) -> File,
|
||||||
|
arguments: K2JVMCompilerArguments
|
||||||
|
) {
|
||||||
val jdkRelease = get(JVMConfigurationKeys.JDK_RELEASE)
|
val jdkRelease = get(JVMConfigurationKeys.JDK_RELEASE)
|
||||||
val isModularJava = isModularJava() && (jdkRelease == null || jdkRelease >= 9)
|
val isModularJava = isModularJava() && (jdkRelease == null || jdkRelease >= 9)
|
||||||
|
|
||||||
fun addRoot(moduleName: String, libraryName: String, getLibrary: (KotlinPaths) -> File, noLibraryArgument: String) {
|
fun addRoot(moduleName: String, libraryName: String, getLibrary: (PathProvider) -> File, noLibraryArgument: String) {
|
||||||
addModularRootIfNotNull(
|
addModularRootIfNotNull(
|
||||||
isModularJava, moduleName,
|
isModularJava, moduleName,
|
||||||
getLibraryFromHome(paths, getLibrary, libraryName, messageCollector, noLibraryArgument)
|
getLibraryFromHome(paths, getLibrary, libraryName, messageCollector, noLibraryArgument)
|
||||||
@@ -189,13 +205,13 @@ fun CompilerConfiguration.configureStandardLibs(paths: KotlinPaths?, arguments:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!arguments.noStdlib) {
|
if (!arguments.noStdlib) {
|
||||||
addRoot("kotlin.stdlib", PathUtil.KOTLIN_JAVA_STDLIB_JAR, KotlinPaths::stdlibPath, "'-no-stdlib'")
|
addRoot("kotlin.stdlib", PathUtil.KOTLIN_JAVA_STDLIB_JAR, stdlibPath, "'-no-stdlib'")
|
||||||
addRoot("kotlin.script.runtime", PathUtil.KOTLIN_JAVA_SCRIPT_RUNTIME_JAR, KotlinPaths::scriptRuntimePath, "'-no-stdlib'")
|
addRoot("kotlin.script.runtime", PathUtil.KOTLIN_JAVA_SCRIPT_RUNTIME_JAR, scriptRuntimePath, "'-no-stdlib'")
|
||||||
}
|
}
|
||||||
// "-no-stdlib" implies "-no-reflect": otherwise we would be able to transitively read stdlib classes through kotlin-reflect,
|
// "-no-stdlib" implies "-no-reflect": otherwise we would be able to transitively read stdlib classes through kotlin-reflect,
|
||||||
// which is likely not what user wants since s/he manually provided "-no-stdlib"
|
// which is likely not what user wants since s/he manually provided "-no-stdlib"
|
||||||
if (!arguments.noReflect && !arguments.noStdlib) {
|
if (!arguments.noReflect && !arguments.noStdlib) {
|
||||||
addRoot("kotlin.reflect", PathUtil.KOTLIN_JAVA_REFLECT_JAR, { it.reflectPath }, "'-no-reflect' or '-no-stdlib'")
|
addRoot("kotlin.reflect", PathUtil.KOTLIN_JAVA_REFLECT_JAR, reflectPath, "'-no-reflect' or '-no-stdlib'")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+16
@@ -5,7 +5,10 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.test.services
|
package org.jetbrains.kotlin.test.services
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
||||||
|
import org.jetbrains.kotlin.cli.jvm.configureStandardLibs
|
||||||
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
||||||
|
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.lang.ref.SoftReference
|
import java.lang.ref.SoftReference
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
@@ -125,3 +128,16 @@ object EnvironmentBasedStandardLibrariesPathProvider : KotlinStandardLibrariesPa
|
|||||||
}
|
}
|
||||||
|
|
||||||
val TestServices.standardLibrariesPathProvider: KotlinStandardLibrariesPathProvider by TestServices.testServiceAccessor()
|
val TestServices.standardLibrariesPathProvider: KotlinStandardLibrariesPathProvider by TestServices.testServiceAccessor()
|
||||||
|
|
||||||
|
fun CompilerConfiguration.configureStandardLibs(
|
||||||
|
pathProvider: KotlinStandardLibrariesPathProvider,
|
||||||
|
arguments: K2JVMCompilerArguments
|
||||||
|
) {
|
||||||
|
configureStandardLibs(
|
||||||
|
pathProvider,
|
||||||
|
KotlinStandardLibrariesPathProvider::runtimeJarForTests,
|
||||||
|
KotlinStandardLibrariesPathProvider::scriptRuntimeJarForTests,
|
||||||
|
KotlinStandardLibrariesPathProvider::reflectJarForTests,
|
||||||
|
arguments
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
+4
-5
@@ -14,7 +14,6 @@ import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
|||||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
||||||
import org.jetbrains.kotlin.cli.jvm.addModularRootIfNotNull
|
import org.jetbrains.kotlin.cli.jvm.addModularRootIfNotNull
|
||||||
import org.jetbrains.kotlin.cli.jvm.config.*
|
import org.jetbrains.kotlin.cli.jvm.config.*
|
||||||
import org.jetbrains.kotlin.cli.jvm.configureStandardLibs
|
|
||||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||||
import org.jetbrains.kotlin.config.CompilerConfigurationKey
|
import org.jetbrains.kotlin.config.CompilerConfigurationKey
|
||||||
import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
||||||
@@ -60,9 +59,7 @@ import org.jetbrains.kotlin.test.services.jvm.CompiledClassesManager
|
|||||||
import org.jetbrains.kotlin.test.services.jvm.compiledClassesManager
|
import org.jetbrains.kotlin.test.services.jvm.compiledClassesManager
|
||||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||||
import org.jetbrains.kotlin.test.util.joinToArrayString
|
import org.jetbrains.kotlin.test.util.joinToArrayString
|
||||||
import org.jetbrains.kotlin.utils.PathUtil
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import kotlin.io.path.ExperimentalPathApi
|
|
||||||
|
|
||||||
class JvmEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfigurator(testServices) {
|
class JvmEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfigurator(testServices) {
|
||||||
companion object {
|
companion object {
|
||||||
@@ -176,7 +173,6 @@ class JvmEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfig
|
|||||||
register(USE_TYPE_TABLE, JVMConfigurationKeys.USE_TYPE_TABLE)
|
register(USE_TYPE_TABLE, JVMConfigurationKeys.USE_TYPE_TABLE)
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalPathApi::class, ExperimentalStdlibApi::class)
|
|
||||||
override fun configureCompilerConfiguration(configuration: CompilerConfiguration, module: TestModule) {
|
override fun configureCompilerConfiguration(configuration: CompilerConfiguration, module: TestModule) {
|
||||||
if (module.targetPlatform !in JvmPlatforms.allJvmPlatforms) return
|
if (module.targetPlatform !in JvmPlatforms.allJvmPlatforms) return
|
||||||
configureDefaultJvmTarget(configuration)
|
configureDefaultJvmTarget(configuration)
|
||||||
@@ -209,7 +205,10 @@ class JvmEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfig
|
|||||||
val useJava11ToCompileIncludedJavaFiles = javaVersionToCompile == TestJavacVersion.JAVAC_11
|
val useJava11ToCompileIncludedJavaFiles = javaVersionToCompile == TestJavacVersion.JAVAC_11
|
||||||
|
|
||||||
if (configurationKind.withRuntime) {
|
if (configurationKind.withRuntime) {
|
||||||
configuration.configureStandardLibs(PathUtil.kotlinPathsForDistDirectory, K2JVMCompilerArguments().also { it.noReflect = true })
|
configuration.configureStandardLibs(
|
||||||
|
testServices.standardLibrariesPathProvider,
|
||||||
|
K2JVMCompilerArguments().also { it.noReflect = true }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
configuration.addJvmClasspathRoots(getLibraryFilesExceptRealRuntime(testServices, configurationKind, module.directives))
|
configuration.addJvmClasspathRoots(getLibraryFilesExceptRealRuntime(testServices, configurationKind, module.directives))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user