Misc: Protect freeArgs with FreezableVar

This commit is contained in:
Alexey Sedunov
2017-10-12 19:46:18 +03:00
parent fa4e4cbb42
commit 87f3d24f9b
8 changed files with 16 additions and 12 deletions
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.cli.common.arguments
import org.jetbrains.kotlin.utils.SmartList
import java.io.Serializable
abstract class CommonToolArguments : Freezable(), Serializable {
@@ -24,7 +23,7 @@ abstract class CommonToolArguments : Freezable(), Serializable {
@JvmStatic private val serialVersionUID = 0L
}
var freeArgs: MutableList<String> = SmartList()
var freeArgs: List<String> by FreezableVar(emptyList())
@Transient var errors: ArgumentParseErrors = ArgumentParseErrors()
@@ -16,7 +16,7 @@
package org.jetbrains.kotlin.cli.common.arguments
import com.intellij.util.SmartList
import org.jetbrains.kotlin.utils.SmartList
import kotlin.reflect.KClass
import kotlin.reflect.KMutableProperty1
import kotlin.reflect.full.findAnnotation
@@ -100,12 +100,14 @@ fun <A : CommonToolArguments> parseCommandLineArguments(args: List<String>, resu
return argument.value == arg
}
val freeArgs = ArrayList<String>()
var i = 0
loop@ while (i < args.size) {
val arg = args[i++]
if (freeArgsStarted) {
result.freeArgs.add(arg)
freeArgs.add(arg)
continue
}
if (arg == FREE_ARGS_DELIMITER) {
@@ -118,7 +120,7 @@ fun <A : CommonToolArguments> parseCommandLineArguments(args: List<String>, resu
when {
arg.startsWith(ADVANCED_ARGUMENT_PREFIX) -> errors.unknownExtraFlags.add(arg)
arg.startsWith("-") -> errors.unknownArgs.add(arg)
else -> result.freeArgs.add(arg)
else -> freeArgs.add(arg)
}
continue
}
@@ -148,6 +150,8 @@ fun <A : CommonToolArguments> parseCommandLineArguments(args: List<String>, resu
updateField(property, result, value, argument.delimiter)
}
result.freeArgs += freeArgs
}
private fun <A : CommonToolArguments> updateField(property: KMutableProperty1<A, Any?>, result: A, value: Any, delimiter: String) {
@@ -121,10 +121,10 @@ class IncrementalJsCompilerRunner(
services: Services,
messageCollector: MessageCollector
): ExitCode {
val freeArgsBackup = args.freeArgs.toMutableList()
val freeArgsBackup = args.freeArgs
try {
sourcesToCompile.mapTo(args.freeArgs) { it.absolutePath }
args.freeArgs += sourcesToCompile.map() { it.absolutePath }
val exitCode = K2JSCompiler().exec(messageCollector, services, args)
reporter.reportCompileIteration(sourcesToCompile, exitCode)
return exitCode
@@ -59,6 +59,7 @@ private fun readV1Config(element: Element): KotlinFacetSettings {
val jsArgumentsElement = compilerInfoElement?.getOptionBody("k2jsCompilerArguments")
val compilerArguments = targetPlatform.createCompilerArguments()
compilerArguments.freeArgs = ArrayList()
commonArgumentsElement?.let { XmlSerializer.deserializeInto(compilerArguments, it) }
when (compilerArguments) {
@@ -138,7 +138,7 @@ abstract class AbstractJsLookupTrackerTest : AbstractLookupTrackerTest() {
val args = K2JSCompilerArguments().apply {
outputFile = File(outDir, "out.js").canonicalPath
reportOutputFiles = true
freeArgs.addAll(filesToCompile.map { it.canonicalPath })
freeArgs = filesToCompile.map { it.canonicalPath }
}
return runJSCompiler(args, env)
}
@@ -56,7 +56,7 @@ abstract class AbstractJsProtoComparisonTest : AbstractProtoComparisonTest<Proto
outputFile = File(outputDir, "out.js").canonicalPath
metaInfo = true
main = K2JsArgumentConstants.NO_CALL
freeArgs.addAll(ktFiles)
freeArgs = ktFiles
}
val env = createTestingCompilerEnvironment(messageCollector, outputItemsCollector, services)
@@ -120,7 +120,7 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil
args: K2JSCompilerArguments,
environment: GradleCompilerEnvironment
): ExitCode {
args.freeArgs.addAll(kotlinSources.map { it.absolutePath })
args.freeArgs += kotlinSources.map { it.absolutePath }
return runCompiler(K2JS_COMPILER, args, environment)
}
@@ -129,7 +129,7 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil
args: K2MetadataCompilerArguments,
environment: GradleCompilerEnvironment
): ExitCode {
args.freeArgs.addAll(kotlinSources.map { it.absolutePath })
args.freeArgs += kotlinSources.map { it.absolutePath }
return runCompiler(K2METADATA_COMPILER, args, environment)
}
@@ -21,5 +21,5 @@ import org.jetbrains.kotlin.cli.common.arguments.CommonToolArguments
fun KotlinCommonToolOptions.copyFreeCompilerArgsToArgs(args: CommonToolArguments) {
// cast to List<Any> is important because in Groovy a GString can be inside of a list
val freeArgs = (freeCompilerArgs as List<Any>).map(Any::toString)
args.freeArgs.addAll(freeArgs)
args.freeArgs += freeArgs
}