From 891914167a1af35fe89b71bb2ada74d01cd00a08 Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Tue, 14 Jan 2020 08:11:13 +0100 Subject: [PATCH] Switch cli expression evaluation argument syntax to -expression/-e #KT-35414 fixed --- .../kotlin/cli/common/arguments/K2JVMCompilerArguments.kt | 6 +++++- .../cli-runner/src/org/jetbrains/kotlin/runner/runners.kt | 3 ++- compiler/testData/cli/jvm/expression1.args | 3 ++- compiler/testData/cli/jvm/extraHelp.out | 1 - compiler/testData/cli/jvm/help.out | 1 + .../compiler/plugin/ScriptingWithCliCompilerTest.kt | 4 ++-- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt index b463e9c4bf3..8917c27d985 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt @@ -49,7 +49,11 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { @Argument(value = "-no-reflect", description = "Don't automatically include Kotlin reflection into the classpath") var noReflect: Boolean by FreezableVar(false) - @Argument(value = "-Xexpression", description = "Evaluate the given string as a Kotlin script") + @Argument( + value = "-expression", + shortName = "-e", + description = "Evaluate the given string as a Kotlin script" + ) var expression: String? by FreezableVar(null) @Argument( diff --git a/compiler/cli/cli-runner/src/org/jetbrains/kotlin/runner/runners.kt b/compiler/cli/cli-runner/src/org/jetbrains/kotlin/runner/runners.kt index 70801d79815..d88202cc0d6 100644 --- a/compiler/cli/cli-runner/src/org/jetbrains/kotlin/runner/runners.kt +++ b/compiler/cli/cli-runner/src/org/jetbrains/kotlin/runner/runners.kt @@ -151,7 +151,8 @@ class ExpressionRunner(private val code: String) : RunnerWithCompiler() { override fun run(classpath: List, arguments: List, compilerClasspath: List) { val compilerArgs = ArrayList().apply { addClasspathArgIfNeeded(classpath) - add("-Xexpression=$code") + add("-expression") + add(code) addAll(arguments) } runCompiler(compilerClasspath, compilerArgs) diff --git a/compiler/testData/cli/jvm/expression1.args b/compiler/testData/cli/jvm/expression1.args index 0cfa0de1b50..6ac9c93ba07 100644 --- a/compiler/testData/cli/jvm/expression1.args +++ b/compiler/testData/cli/jvm/expression1.args @@ -1,4 +1,5 @@ --Xexpression=val x = 2; System.err.println((args + listOf(2,1).map { (it * x).toString() }).joinToString()) +-expression +val x = 2; System.err.println((args + listOf(2,1).map { (it * x).toString() }).joinToString()) -- a b diff --git a/compiler/testData/cli/jvm/extraHelp.out b/compiler/testData/cli/jvm/extraHelp.out index 6be538617a0..06ddf0df617 100644 --- a/compiler/testData/cli/jvm/extraHelp.out +++ b/compiler/testData/cli/jvm/extraHelp.out @@ -19,7 +19,6 @@ where advanced options include: -Xdump-declarations-to= Path to JSON file to dump Java to Kotlin declaration mappings -Xdisable-standard-script Disable standard kotlin script support -Xemit-jvm-type-annotations Emit JVM type annotations in bytecode - -Xexpression Evaluate the given string as a Kotlin script -Xfriend-paths= Paths to output directories for friend modules (whose internals should be visible) -Xmultifile-parts-inherit Compile multifile classes as a hierarchy of parts and facade -Xir-check-local-names Check that names of local classes and anonymous objects are the same in the IR backend as in the old backend diff --git a/compiler/testData/cli/jvm/help.out b/compiler/testData/cli/jvm/help.out index e3dc1f09062..81871fde6b2 100644 --- a/compiler/testData/cli/jvm/help.out +++ b/compiler/testData/cli/jvm/help.out @@ -2,6 +2,7 @@ Usage: kotlinc-jvm where possible options include: -classpath (-cp) List of directories and JAR/ZIP archives to search for user class files -d Destination for generated class files + -expression (-e) Evaluate the given string as a Kotlin script -include-runtime Include Kotlin runtime into the resulting JAR -java-parameters Generate metadata for Java 1.8 reflection on method parameters -jdk-home Include a custom JDK from the specified location into the classpath instead of the default JAVA_HOME diff --git a/plugins/scripting/scripting-compiler/tests/org/jetbrains/kotlin/scripting/compiler/plugin/ScriptingWithCliCompilerTest.kt b/plugins/scripting/scripting-compiler/tests/org/jetbrains/kotlin/scripting/compiler/plugin/ScriptingWithCliCompilerTest.kt index dc82869ae3a..a87f719d10d 100644 --- a/plugins/scripting/scripting-compiler/tests/org/jetbrains/kotlin/scripting/compiler/plugin/ScriptingWithCliCompilerTest.kt +++ b/plugins/scripting/scripting-compiler/tests/org/jetbrains/kotlin/scripting/compiler/plugin/ScriptingWithCliCompilerTest.kt @@ -50,7 +50,7 @@ class ScriptingWithCliCompilerTest { fun testExpression() { runWithK2JVMCompiler( arrayOf( - "-Xexpression", + "-expression", "val x = 7; println(x * 6); for (arg in args) println(arg)", "--", "hi", @@ -64,7 +64,7 @@ class ScriptingWithCliCompilerTest { fun testExpressionWithComma() { runWithK2JVMCompiler( arrayOf( - "-Xexpression", + "-expression", "listOf(1,2)" ), listOf("\\[1, 2\\]")