[CLI] K2JVMCompilerArguments: Model classpath as Array<String>
to allow interning individual file-path arguments on the IDE KTIJ-24976
This commit is contained in:
committed by
Space Team
parent
7f91e94e7a
commit
9dcd40d7b7
+1
-1
@@ -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
|
||||
to.classpath = from.classpath?.copyOf()
|
||||
to.compileJava = from.compileJava
|
||||
to.declarationsOutputPath = from.declarationsOutputPath
|
||||
to.defaultScriptExtension = from.defaultScriptExtension
|
||||
|
||||
+3
-2
@@ -26,9 +26,10 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
|
||||
value = "-classpath",
|
||||
shortName = "-cp",
|
||||
valueDescription = "<path>",
|
||||
description = "List of directories and JAR/ZIP archives to search for user class files"
|
||||
description = "List of directories and JAR/ZIP archives to search for user class files",
|
||||
delimiter = Argument.Delimiters.pathSeparator
|
||||
)
|
||||
var classpath: String? = null
|
||||
var classpath: Array<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?.split(File.pathSeparator)?.forEach { addClasspathEntry(it) }
|
||||
args.classpath?.forEach { addClasspathEntry(it) }
|
||||
args.javaSourceRoots?.forEach {
|
||||
addJavaSourceRoot(JavaRootPath(it, args.javaPackagePrefix))
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ fun CompilerConfiguration.configureJavaModulesContentRoots(arguments: K2JVMCompi
|
||||
}
|
||||
|
||||
fun CompilerConfiguration.configureContentRootsFromClassPath(arguments: K2JVMCompilerArguments) {
|
||||
for (path in arguments.classpath?.split(File.pathSeparatorChar).orEmpty()) {
|
||||
for (path in arguments.classpath.orEmpty()) {
|
||||
add(CLIConfigurationKeys.CONTENT_ROOTS, JvmClasspathRoot(File(path)))
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -342,7 +342,7 @@ fun CompilerConfiguration.configureBaseRoots(args: K2JVMCompilerArguments) {
|
||||
}
|
||||
}
|
||||
|
||||
args.classpath?.split(File.pathSeparator)?.forEach { classpathRoot ->
|
||||
args.classpath?.forEach { classpathRoot ->
|
||||
add(
|
||||
CLIConfigurationKeys.CONTENT_ROOTS,
|
||||
if (isJava9Module) JvmModulePathRoot(File(classpathRoot)) else JvmClasspathRoot(File(classpathRoot))
|
||||
|
||||
+6
-4
@@ -174,7 +174,8 @@ open class IncrementalJvmCompilerRunner(
|
||||
private val psiFileFactory: PsiFileFactory by lazy {
|
||||
val rootDisposable = Disposer.newDisposable()
|
||||
val configuration = compilerConfiguration
|
||||
val environment = KotlinCoreEnvironment.createForProduction(rootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
||||
val environment =
|
||||
KotlinCoreEnvironment.createForProduction(rootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
||||
val project = environment.project
|
||||
PsiFileFactory.getInstance(project)
|
||||
}
|
||||
@@ -281,7 +282,8 @@ open class IncrementalJvmCompilerRunner(
|
||||
if (!lastBuildInfoFile.exists()) {
|
||||
return CompilationMode.Rebuild(BuildAttribute.NO_LAST_BUILD_INFO)
|
||||
}
|
||||
val lastBuildInfo = BuildInfo.read(lastBuildInfoFile, messageCollector) ?: return CompilationMode.Rebuild(BuildAttribute.INVALID_LAST_BUILD_INFO)
|
||||
val lastBuildInfo = BuildInfo.read(lastBuildInfoFile, messageCollector)
|
||||
?: return CompilationMode.Rebuild(BuildAttribute.INVALID_LAST_BUILD_INFO)
|
||||
reporter.debug { "Last Kotlin Build info -- $lastBuildInfo" }
|
||||
val scopes = caches.lookupCache.lookupSymbols.map { it.scope.ifBlank { it.name } }.distinct()
|
||||
|
||||
@@ -548,7 +550,7 @@ var K2JVMCompilerArguments.destinationAsFile: File
|
||||
}
|
||||
|
||||
var K2JVMCompilerArguments.classpathAsList: List<File>
|
||||
get() = classpath.orEmpty().split(File.pathSeparator).map(::File)
|
||||
get() = classpath.orEmpty().map(::File)
|
||||
set(value) {
|
||||
classpath = value.joinToString(separator = File.pathSeparator, transform = { it.path })
|
||||
classpath = value.map { it.path }.toTypedArray()
|
||||
}
|
||||
|
||||
+4
-4
@@ -48,14 +48,14 @@ abstract class AbstractIncrementalJvmCompilerRunnerTest : AbstractIncrementalCom
|
||||
}
|
||||
if (javaSources.isEmpty()) return TestCompilationResult(ExitCode.OK, emptyList(), emptyList())
|
||||
|
||||
val javaClasspath = compileClasspath + File.pathSeparator + kotlinClassesPath
|
||||
val javaClasspath = compileClasspath + kotlinClassesPath
|
||||
val javaDestinationDir = File(workingDir, "java-classes").apply {
|
||||
if (exists()) {
|
||||
deleteRecursively()
|
||||
}
|
||||
mkdirs()
|
||||
}
|
||||
val args = arrayOf("-cp", javaClasspath,
|
||||
val args = arrayOf("-cp", javaClasspath.joinToString(File.pathSeparator),
|
||||
"-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
|
||||
classpath = compileClasspath.toTypedArray()
|
||||
}
|
||||
|
||||
private val compileClasspath =
|
||||
listOf(
|
||||
kotlinStdlibJvm,
|
||||
KtTestUtil.getAnnotationsJar()
|
||||
).joinToString(File.pathSeparator) { it.canonicalPath }
|
||||
).map { it.canonicalPath }
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ class KotlinFacetSettings {
|
||||
if (compilerSettings != null) {
|
||||
parseCommandLineArguments(compilerSettings.additionalArgumentsAsList, this)
|
||||
}
|
||||
if (this is K2JVMCompilerArguments) this.classpath = ""
|
||||
if (this is K2JVMCompilerArguments) this.classpath = null
|
||||
}
|
||||
} else null
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ fun CommonCompilerArguments.convertPathsToSystemIndependent() {
|
||||
when (this) {
|
||||
is K2JVMCompilerArguments -> {
|
||||
destination = destination?.let(FileUtilRt::toSystemIndependentName)
|
||||
classpath = classpath?.let(FileUtilRt::toSystemIndependentName)
|
||||
classpath?.forEachIndexed { index, s -> classpath!![index] = FileUtilRt.toSystemIndependentName(s) }
|
||||
jdkHome = jdkHome?.let(FileUtilRt::toSystemIndependentName)
|
||||
kotlinHome = kotlinHome?.let(FileUtilRt::toSystemIndependentName)
|
||||
friendPaths?.forEachIndexed { index, s -> friendPaths!![index] = FileUtilRt.toSystemIndependentName(s) }
|
||||
@@ -334,7 +334,7 @@ private fun KotlinFacetSettings.writeConfig(element: Element) {
|
||||
element.addContent(
|
||||
Element("externalSystemTestTasks").apply {
|
||||
externalSystemRunTasks.forEach { task ->
|
||||
when(task) {
|
||||
when (task) {
|
||||
is ExternalSystemTestRunTask -> {
|
||||
addContent(
|
||||
Element("externalSystemTestTask").apply { addContent(task.toStringRepresentation()) }
|
||||
|
||||
@@ -34,7 +34,7 @@ class CompilerArgumentsSerializationTest {
|
||||
@Test
|
||||
fun testLongClasspathArgumentJVM() {
|
||||
doSerializeDeserializeAndCompareTest<K2JVMCompilerArguments> {
|
||||
classpath = generateSequence { generateRandomString(50) }.take(10).toList().joinToString(File.pathSeparator)
|
||||
classpath = generateSequence { generateRandomString(50) }.take(10).toList().toTypedArray()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -958,7 +958,7 @@ open class KotlinJpsBuildTest : KotlinJpsBuildTestBase() {
|
||||
Files.copy(libraryJar.toPath(), module1Lib.toPath(), StandardCopyOption.REPLACE_EXISTING)
|
||||
|
||||
assert(module1Lib.exists())
|
||||
(facet.compilerArguments as K2JVMCompilerArguments).classpath = module1Lib.path
|
||||
(facet.compilerArguments as K2JVMCompilerArguments).classpath = arrayOf(module1Lib.path)
|
||||
|
||||
it.container.setChild(
|
||||
JpsKotlinFacetModuleExtension.KIND,
|
||||
|
||||
+4
-4
@@ -171,7 +171,7 @@ public class K2JVMCompileMojo extends KotlinCompileMojoBase<K2JVMCompilerArgumen
|
||||
}
|
||||
else {
|
||||
getLog().debug("Classpath: " + classPathString);
|
||||
arguments.setClasspath(classPathString);
|
||||
arguments.setClasspath(classpathList.toArray(String[]::new));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,19 +255,19 @@ public class K2JVMCompileMojo extends KotlinCompileMojoBase<K2JVMCompilerArgumen
|
||||
File classesDir = new File(destination);
|
||||
File kotlinClassesDir = new File(cachesDir, "classes");
|
||||
File snapshotsFile = new File(cachesDir, "snapshots.bin");
|
||||
String classpath = arguments.getClasspath();
|
||||
String[] classpath = arguments.getClasspath();
|
||||
MavenICReporter icReporter = new MavenICReporter(getLog());
|
||||
|
||||
try {
|
||||
arguments.setDestination(kotlinClassesDir.getAbsolutePath());
|
||||
if (classpath != null) {
|
||||
List<String> filteredClasspath = new ArrayList<>();
|
||||
for (String path : classpath.split(File.pathSeparator)) {
|
||||
for (String path : classpath) {
|
||||
if (!classesDir.equals(new File(path))) {
|
||||
filteredClasspath.add(path);
|
||||
}
|
||||
}
|
||||
arguments.setClasspath(StringUtil.join(filteredClasspath, File.pathSeparator));
|
||||
arguments.setClasspath(filteredClasspath.toArray(new String[0]));
|
||||
}
|
||||
|
||||
IncrementalJvmCompilerRunnerKt.makeIncrementally(cachesDir, sourceRoots, arguments, messageCollector, icReporter);
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ abstract class AbstractIncrementalFirJvmWithPluginCompilerRunnerTest : AbstractI
|
||||
val annotationsJar = findJar(ANNOTATIONS_JAR_DIR, ANNOTATIONS_JAR_NAME, ":plugins:fir-plugin-prototype:plugin-annotations:jar")
|
||||
val pluginJar = findJar(PLUGIN_JAR_DIR, PLUGIN_JAR_NAME, ":plugins:fir-plugin-prototype:jar")
|
||||
|
||||
classpath += "${File.pathSeparator}$annotationsJar"
|
||||
classpath = classpath?.plus(annotationsJar)
|
||||
pluginClasspaths = arrayOf(pluginJar)
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ abstract class BaseJvmAbiTest : TestCase() {
|
||||
val compiler = K2JVMCompiler()
|
||||
val args = compiler.createArguments().apply {
|
||||
freeArgs = listOf(compilation.srcDir.canonicalPath)
|
||||
classpath = (abiDependencies + kotlinJvmStdlib).joinToString(File.pathSeparator) { it.canonicalPath }
|
||||
classpath = (abiDependencies + kotlinJvmStdlib).map { it.canonicalPath }.toTypedArray()
|
||||
pluginClasspaths = arrayOf(abiPluginJar.canonicalPath)
|
||||
pluginOptions = listOfNotNull(
|
||||
abiOption(JvmAbiCommandLineProcessor.OUTPUT_PATH_OPTION.optionName, compilation.abiDir.canonicalPath),
|
||||
|
||||
Reference in New Issue
Block a user