[CLI] argumentsToStrings: Add 'compactArgumentValues' option

Passing 'false' will pass Array or List based arguments multiple times
instead of using the Delimiter.

eg:
compactArgumentValues = true:
"-cp", "library1;library2;library3"

compactArgumentValues = false:
"-cp", "library1", "-cp", -"library2", "-cp", "library3"

Using compactArgumentValues = false can be beneficial
when the many compiler arguments are held in memory.
In this case the raw arguments can intern individual string values, which
is highly effective when the arguments refer to files on disk.

KTIJ-24976
This commit is contained in:
Sebastian Sellmair
2023-04-04 14:43:24 +02:00
committed by Space Team
parent fb66764c4d
commit 082a38216d
2 changed files with 42 additions and 19 deletions
@@ -25,14 +25,28 @@ class CompilerArgumentParsingTest {
@ParameterizedTest
@MethodSource("parameters")
fun `test - parsing random compiler arguments`(type: KClass<out CommonToolArguments>, seed: Int, useShortNames: Boolean) {
fun `test - parsing random compiler arguments`(
type: KClass<out CommonToolArguments>,
seed: Int,
shortArgumentKeys: Boolean,
compactArgumentValues: Boolean
) {
val constructor = type.constructors.find { it.parameters.isEmpty() } ?: error("Missing empty constructor on $type")
val arguments = constructor.call()
arguments.fillRandomValues(Random(seed))
val argumentsAsStrings = arguments.toArgumentStrings(useShortNames)
val argumentsAsStrings = arguments.toArgumentStrings(
shortArgumentKeys = shortArgumentKeys,
compactArgumentValues = compactArgumentValues
)
val parsedArguments = parseCommandLineArguments(type, argumentsAsStrings)
assertEqualArguments(arguments, parsedArguments)
assertEquals(argumentsAsStrings, parsedArguments.toArgumentStrings(useShortNames))
assertEquals(
argumentsAsStrings,
parsedArguments.toArgumentStrings(
shortArgumentKeys = shortArgumentKeys,
compactArgumentValues = compactArgumentValues
)
)
}
companion object {
@@ -40,12 +54,15 @@ class CompilerArgumentParsingTest {
fun parameters(): List<Arguments> = getCompilerArgumentImplementations()
.flatMap { clazz ->
listOf(1002, 2803, 2411).flatMap { seed ->
listOf(true, false).map { useShortNames ->
Arguments.of(
Named.of("${clazz.simpleName}", clazz),
Named.of("seed: $seed", seed),
Named.of("useShortNames: $useShortNames", useShortNames)
)
listOf(true, false).flatMap { shortArgumentKeys ->
listOf(true, false).map { compactArgumentValues ->
Arguments.of(
Named.of("${clazz.simpleName}", clazz),
Named.of("seed: $seed", seed),
Named.of("shortArgumentKeys: $shortArgumentKeys", shortArgumentKeys),
Named.of("compactArgumentValues: $compactArgumentValues", compactArgumentValues)
)
}
}
}
}
@@ -96,14 +113,14 @@ private fun Random.randomString() = nextBytes(nextInt(8, 12)).let { data ->
private fun Random.randomBoolean() = nextBoolean()
private fun Random.randomStringArray(): Array<String> {
val size = nextInt(1, 5)
val size = nextInt(5, 10)
return Array(size) {
randomString()
}
}
private fun Random.randomList(elementType: KType): List<Any>? {
val size = nextInt(1, 5)
val size = nextInt(5, 10)
return List(size) {
randomValue(elementType) ?: return null
}