[CLI] Restore K2JVMCompilerArguments.classpath and javaModulePath

to support IDEs < 2023.2

Reverts:
- 9dcd40d7b7
- fb66764c4d

KTIJ-25227
This commit is contained in:
Sebastian Sellmair
2023-04-17 08:25:29 +02:00
committed by Space Team
parent 7fe3c5c423
commit 5d0bf2de24
15 changed files with 29 additions and 38 deletions
@@ -17,7 +17,7 @@ fun copyK2JVMCompilerArguments(from: K2JVMCompilerArguments, to: K2JVMCompilerAr
to.assertionsMode = from.assertionsMode
to.backendThreads = from.backendThreads
to.buildFile = from.buildFile
to.classpath = from.classpath?.copyOf()
to.classpath = from.classpath
to.compileJava = from.compileJava
to.declarationsOutputPath = from.declarationsOutputPath
to.defaultScriptExtension = from.defaultScriptExtension
@@ -33,7 +33,7 @@ fun copyK2JVMCompilerArguments(from: K2JVMCompilerArguments, to: K2JVMCompilerAr
to.friendPaths = from.friendPaths?.copyOf()
to.includeRuntime = from.includeRuntime
to.inheritMultifileParts = from.inheritMultifileParts
to.javaModulePath = from.javaModulePath?.copyOf()
to.javaModulePath = from.javaModulePath
to.javaPackagePrefix = from.javaPackagePrefix
to.javaParameters = from.javaParameters
to.javaSourceRoots = from.javaSourceRoots?.copyOf()
@@ -26,10 +26,9 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
value = "-classpath",
shortName = "-cp",
valueDescription = "<path>",
description = "List of directories and JAR/ZIP archives to search for user class files",
delimiter = Argument.Delimiters.pathSeparator
description = "List of directories and JAR/ZIP archives to search for user class files"
)
var classpath: Array<String>? = null
var classpath: String? = null
set(value) {
checkFrozen()
field = if (value.isNullOrEmpty()) null else value
@@ -210,13 +209,8 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
field = value
}
@Argument(
value = "-Xmodule-path",
valueDescription = "<path>",
description = "Paths where to find Java 9+ modules",
delimiter = Argument.Delimiters.pathSeparator
)
var javaModulePath: Array<String>? = null
@Argument(value = "-Xmodule-path", valueDescription = "<path>", description = "Paths where to find Java 9+ modules")
var javaModulePath: String? = null
set(value) {
checkFrozen()
field = if (value.isNullOrEmpty()) null else value
@@ -174,7 +174,7 @@ fun writeOutputsIfNeeded(
fun ModuleBuilder.configureFromArgs(args: K2JVMCompilerArguments) {
args.friendPaths?.forEach { addFriendDir(it) }
args.classpath?.forEach { addClasspathEntry(it) }
args.classpath?.split(File.pathSeparator)?.forEach { addClasspathEntry(it) }
args.javaSourceRoots?.forEach {
addJavaSourceRoot(JavaRootPath(it, args.javaPackagePrefix))
}
@@ -177,13 +177,13 @@ fun CompilerConfiguration.configureJdkHomeFromSystemProperty() {
}
fun CompilerConfiguration.configureJavaModulesContentRoots(arguments: K2JVMCompilerArguments) {
for (modularRoot in arguments.javaModulePath.orEmpty()) {
for (modularRoot in arguments.javaModulePath?.split(File.pathSeparatorChar).orEmpty()) {
add(CLIConfigurationKeys.CONTENT_ROOTS, JvmModulePathRoot(File(modularRoot)))
}
}
fun CompilerConfiguration.configureContentRootsFromClassPath(arguments: K2JVMCompilerArguments) {
for (path in arguments.classpath.orEmpty()) {
for (path in arguments.classpath?.split(File.pathSeparatorChar).orEmpty()) {
add(CLIConfigurationKeys.CONTENT_ROOTS, JvmClasspathRoot(File(path)))
}
}
@@ -77,7 +77,7 @@ abstract class AbstractFrontendModularizedTest : AbstractModularizedTest() {
if (originalArguments != null) {
configuration.put(JVMConfigurationKeys.NO_JDK, originalArguments.noJdk)
for (modularRoot in originalArguments.javaModulePath.orEmpty()) {
for (modularRoot in originalArguments.javaModulePath?.split(File.pathSeparatorChar).orEmpty()) {
configuration.add(CLIConfigurationKeys.CONTENT_ROOTS, JvmModulePathRoot(modularRoot.fixPath()))
}
@@ -342,7 +342,7 @@ fun CompilerConfiguration.configureBaseRoots(args: K2JVMCompilerArguments) {
}
}
args.classpath?.forEach { classpathRoot ->
args.classpath?.split(File.pathSeparator)?.forEach { classpathRoot ->
add(
CLIConfigurationKeys.CONTENT_ROOTS,
if (isJava9Module) JvmModulePathRoot(File(classpathRoot)) else JvmClasspathRoot(File(classpathRoot))
@@ -550,7 +550,7 @@ var K2JVMCompilerArguments.destinationAsFile: File
}
var K2JVMCompilerArguments.classpathAsList: List<File>
get() = classpath.orEmpty().map(::File)
get() = classpath.orEmpty().split(File.pathSeparator).map(::File)
set(value) {
classpath = value.map { it.path }.toTypedArray()
classpath = value.joinToString(separator = File.pathSeparator, transform = { it.path })
}
@@ -48,14 +48,14 @@ abstract class AbstractIncrementalJvmCompilerRunnerTest : AbstractIncrementalCom
}
if (javaSources.isEmpty()) return TestCompilationResult(ExitCode.OK, emptyList(), emptyList())
val javaClasspath = compileClasspath + kotlinClassesPath
val javaClasspath = compileClasspath + File.pathSeparator + kotlinClassesPath
val javaDestinationDir = File(workingDir, "java-classes").apply {
if (exists()) {
deleteRecursively()
}
mkdirs()
}
val args = arrayOf("-cp", javaClasspath.joinToString(File.pathSeparator),
val args = arrayOf("-cp", javaClasspath,
"-d", javaDestinationDir.canonicalPath,
*javaSources.map { it.canonicalPath }.toTypedArray()
)
@@ -73,12 +73,12 @@ abstract class AbstractIncrementalJvmCompilerRunnerTest : AbstractIncrementalCom
K2JVMCompilerArguments().apply {
moduleName = testDir.name
destination = destinationDir.path
classpath = compileClasspath.toTypedArray()
classpath = compileClasspath
}
private val compileClasspath =
listOf(
kotlinStdlibJvm,
KtTestUtil.getAnnotationsJar()
).map { it.canonicalPath }
).joinToString(File.pathSeparator) { it.canonicalPath }
}