Skip to content

Commit

Permalink
Replace ':' with File.pathSeparator in command line arguments
Browse files Browse the repository at this point in the history
':' is a valid character in path on Windows.
  • Loading branch information
ting-yuan committed Sep 26, 2024
1 parent 2addebe commit aceb6a0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -474,13 +474,13 @@ fun parseFile(arg: String): File {
fun <T> parseList(arg: String, transform: (String) -> T): List<T> {
if (arg.length > 0 && arg[0] == '-')
throw IllegalArgumentException("expecting a List but got $arg")
return arg.split(':').map { transform(it) }
return arg.split(File.pathSeparatorChar).map { transform(it) }
}

fun <T> parseMap(arg: String, transform: (String) -> T): Map<String, T> {
if (arg.length > 0 && arg[0] == '-')
throw IllegalArgumentException("expecting a Map but got $arg")
return arg.split(':').map {
return arg.split(File.pathSeparatorChar).map {
val (k, v) = it.split('=')
k to transform(v)
}.toMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import java.io.File
class CommandLineArgParserTest {
@Test
fun testJvm() {
val sep = File.pathSeparator
val args = arrayListOf<String>(
"-module-name=MyModule",
"-source-roots", "/path/to/A:/path/to/B",
"-source-roots", "/path/to/A$sep/path/to/B",
"/path/to/processorA.jar",
"-kotlin-output-dir=/path/to/output/kotlin",
"-java-output-dir=/path/to/output/java",
Expand All @@ -23,7 +24,7 @@ class CommandLineArgParserTest {
"-project-base-dir", "/path/to/base",
"-output-base-dir", "/path/to/output",
"-caches-dir", "/path/to/caches",
"/path/to/processorB.jar:rel/to/processorC.jar",
"/path/to/processorB.jar${sep}rel/to/processorC.jar",
).toTypedArray()
val (config, classpath) = kspJvmArgParser(args)
Assert.assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ internal fun printHelpMsg(optionsList: String) {
println(optionsList)
println("where:")
println(" * is required")
println(" List is colon separated. E.g., arg1:arg2:arg3")
println(" Map is in the form key1=value1:key2=value2")
println(" List is <path-separator> separated. E.g., arg1:arg2:arg3 on Linux/Mac, or arg1;arg2;arg3 on Windows")
println(" Map is in the form key1=value1:key2=value2 on Linux/Mac or key1=value1;key2=value2 on Windows")
}

internal fun runWithArgs(args: Array<String>, parse: (Array<String>) -> Pair<KSPConfig, List<String>>) {
Expand Down

0 comments on commit aceb6a0

Please sign in to comment.