From d2ecc1e3619ba7c254240391fd992d7dad7b7905 Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Mon, 4 Jan 2021 13:06:18 +0100 Subject: [PATCH] Implement -X arguments passing from kotlin runner to compiler --- .../src/org/jetbrains/kotlin/runner/Main.kt | 21 ++++++++++----- .../src/org/jetbrains/kotlin/runner/Runner.kt | 1 + .../org/jetbrains/kotlin/runner/runners.kt | 11 +++++--- .../testData/launcher/funWithResultReturn.kts | 4 +++ .../jetbrains/kotlin/cli/AbstractCliTest.java | 5 ++-- .../kotlin/cli/LauncherScriptTest.kt | 26 ++++++++++++++++--- 6 files changed, 52 insertions(+), 16 deletions(-) create mode 100644 compiler/testData/launcher/funWithResultReturn.kts diff --git a/compiler/cli/cli-runner/src/org/jetbrains/kotlin/runner/Main.kt b/compiler/cli/cli-runner/src/org/jetbrains/kotlin/runner/Main.kt index 67ab6854cba..a1faab9b8ab 100644 --- a/compiler/cli/cli-runner/src/org/jetbrains/kotlin/runner/Main.kt +++ b/compiler/cli/cli-runner/src/org/jetbrains/kotlin/runner/Main.kt @@ -42,6 +42,7 @@ object Main { var collectingExpressions = false var needsCompiler = false val arguments = arrayListOf() + val compilerArguments = arrayListOf() var expression: String? = null var noReflect = false @@ -103,6 +104,10 @@ object Main { } else if ("-no-reflect" == arg) { noReflect = true + compilerArguments.add(arg) + } + else if (arg.startsWith("-X")) { + compilerArguments.add(arg) } else if (arg.startsWith("-")) { throw RunnerException("unsupported argument: $arg") @@ -146,7 +151,7 @@ object Main { } } - runner.run(classpath, arguments, compilerClasspath) + runner.run(classpath, compilerArguments, arguments, compilerClasspath) } private fun MutableList.addPath(path: String) { @@ -167,19 +172,21 @@ object Main { private fun printUsageAndExit() { println("""kotlin: run Kotlin programs, scripts or REPL. -Usage: kotlin +Usage: kotlin [] where command may be one of: foo.Bar Runs the 'main' function from the class with the given qualified name + (compiler arguments are ignored) app.jar Runs the given JAR file as 'java -jar' would do - (-classpath argument is ignored and no Kotlin runtime is added to the classpath) -""" + -// script.kts Compiles and runs the given script -// -expression (-e) '2+2' Evaluates the expression and prints the result -"""and possible options include: + (compiler arguments are ignored and no Kotlin stdlib is added to the classpath) + script.kts Compiles and runs the given script, passing to it + -expression (-e) '2+2' Evaluates the expression and prints the result, passing to it + Runs Kotlin REPL, passing to it +and possible options include: -classpath (-cp) Paths where to find user class files -Dname=value Set a system JVM property -J