From 5871f3d6637a578f9ef0250f87fe04c2b8f88c1b Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Wed, 7 Jul 2021 15:54:08 +0300 Subject: [PATCH] CLI: support -option=value syntax for non-advanced flags #KT-47640 Fixed --- .../cli/common/arguments/parseCommandLineArguments.kt | 6 +++--- compiler/testData/cli/jvm/experimentalDeprecated.args | 9 +++------ .../testData/cli/jvm/experimentalDeprecatedWarning.args | 6 ++---- .../testData/cli/jvm/experimentalIsNotAnnotation.args | 3 +-- compiler/testData/cli/jvm/experimentalIsNotMarker.args | 3 +-- compiler/testData/cli/jvm/experimentalNested.args | 3 +-- .../testData/cli/jvm/unrestrictedBuilderInference.out | 1 + .../experimental/jvmhost/test/ScriptingHostTest.kt | 8 ++++---- 8 files changed, 16 insertions(+), 23 deletions(-) diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/parseCommandLineArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/parseCommandLineArguments.kt index bff612f96c5..f6c60c7f581 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/parseCommandLineArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/parseCommandLineArguments.kt @@ -107,7 +107,7 @@ private fun parsePreprocessedCommandLineArguments(args return arg.startsWith(argument.value + "=") } - return argument.value == arg + return argument.value == arg || arg.startsWith(argument.value + "=") } val freeArgs = ArrayList() @@ -160,10 +160,10 @@ private fun parsePreprocessedCommandLineArguments(args val (property, argument) = argumentField val value: Any = when { argumentField.property.returnType.classifier == Boolean::class -> true - argument.isAdvanced && arg.startsWith(argument.value + "=") -> { + arg.startsWith(argument.value + "=") -> { arg.substring(argument.value.length + 1) } - argument.isAdvanced && arg.startsWith(argument.deprecatedName + "=") -> { + arg.startsWith(argument.deprecatedName + "=") -> { arg.substring(argument.deprecatedName.length + 1) } i == args.size -> { diff --git a/compiler/testData/cli/jvm/experimentalDeprecated.args b/compiler/testData/cli/jvm/experimentalDeprecated.args index cdc79254f58..f73e45b7bd2 100644 --- a/compiler/testData/cli/jvm/experimentalDeprecated.args +++ b/compiler/testData/cli/jvm/experimentalDeprecated.args @@ -1,11 +1,8 @@ $TESTDATA_DIR$/experimentalDeprecated.kt -d $TEMP_DIR$ --opt-in -kotlin.RequiresOptIn +-opt-in=kotlin.RequiresOptIn -Xexperimental=org.test.Error1 -Xexperimental=org.test.Hidden1 --opt-in -org.test.Error2 --opt-in -org.test.Hidden2 +-opt-in=org.test.Error2 +-opt-in=org.test.Hidden2 diff --git a/compiler/testData/cli/jvm/experimentalDeprecatedWarning.args b/compiler/testData/cli/jvm/experimentalDeprecatedWarning.args index 97c26bd17a7..cf413bd4db6 100644 --- a/compiler/testData/cli/jvm/experimentalDeprecatedWarning.args +++ b/compiler/testData/cli/jvm/experimentalDeprecatedWarning.args @@ -2,9 +2,7 @@ $TESTDATA_DIR$/experimentalDeprecatedWarning.kt -d $TEMP_DIR$ -Xopt-in=kotlin.RequiresOptIn --opt-in -kotlin.RequiresOptIn --opt-in -org.test.Warning1 +-opt-in=kotlin.RequiresOptIn +-opt-in=org.test.Warning1 -Xexperimental=org.test.Warning2 -Xuse-experimental=org.test.OneMore diff --git a/compiler/testData/cli/jvm/experimentalIsNotAnnotation.args b/compiler/testData/cli/jvm/experimentalIsNotAnnotation.args index da59f5862de..a3dc5a0f1fb 100644 --- a/compiler/testData/cli/jvm/experimentalIsNotAnnotation.args +++ b/compiler/testData/cli/jvm/experimentalIsNotAnnotation.args @@ -2,5 +2,4 @@ $TESTDATA_DIR$/experimentalIsNotAnnotation.kt -d $TEMP_DIR$ -Xexperimental=org.test.NotAnAnnotation1 --opt-in -org.test.NotAnAnnotation2 +-opt-in=org.test.NotAnAnnotation2 diff --git a/compiler/testData/cli/jvm/experimentalIsNotMarker.args b/compiler/testData/cli/jvm/experimentalIsNotMarker.args index b674e93e296..0e31da8c19c 100644 --- a/compiler/testData/cli/jvm/experimentalIsNotMarker.args +++ b/compiler/testData/cli/jvm/experimentalIsNotMarker.args @@ -2,5 +2,4 @@ $TESTDATA_DIR$/experimentalIsNotMarker.kt -d $TEMP_DIR$ -Xexperimental=org.test.NotAMarker1 --opt-in -org.test.NotAMarker2 +-opt-in=org.test.NotAMarker2 diff --git a/compiler/testData/cli/jvm/experimentalNested.args b/compiler/testData/cli/jvm/experimentalNested.args index 3ccc12cfde5..bc6e40d5fc2 100644 --- a/compiler/testData/cli/jvm/experimentalNested.args +++ b/compiler/testData/cli/jvm/experimentalNested.args @@ -1,6 +1,5 @@ $TESTDATA_DIR$/experimentalNested.kt -d $TEMP_DIR$ --opt-in -kotlin.RequiresOptIn +-opt-in=kotlin.RequiresOptIn -Xexperimental=org.test.Outer.Nested diff --git a/compiler/testData/cli/jvm/unrestrictedBuilderInference.out b/compiler/testData/cli/jvm/unrestrictedBuilderInference.out index a2803e584f6..1fb81166ae9 100644 --- a/compiler/testData/cli/jvm/unrestrictedBuilderInference.out +++ b/compiler/testData/cli/jvm/unrestrictedBuilderInference.out @@ -1,3 +1,4 @@ +warning: '-Xopt-in' is deprecated and will be removed in a future release, please use -opt-in instead compiler/testData/cli/jvm/unrestrictedBuilderInference.kt:3:9: warning: variable 'x' is never used val x = buildMap { ^ diff --git a/libraries/scripting/jvm-host-test/test/kotlin/script/experimental/jvmhost/test/ScriptingHostTest.kt b/libraries/scripting/jvm-host-test/test/kotlin/script/experimental/jvmhost/test/ScriptingHostTest.kt index ea125bec3c7..20404931577 100644 --- a/libraries/scripting/jvm-host-test/test/kotlin/script/experimental/jvmhost/test/ScriptingHostTest.kt +++ b/libraries/scripting/jvm-host-test/test/kotlin/script/experimental/jvmhost/test/ScriptingHostTest.kt @@ -326,24 +326,24 @@ class ScriptingHostTest : TestCase() { val script = "println(\"Hi\")" val compilationConfiguration1 = createJvmCompilationConfigurationFromTemplate { - compilerOptions("-jvm-target=1.8") + compilerOptions("-jvm-target->1.8") } val res1 = BasicJvmScriptingHost().eval(script.toScriptSource(), compilationConfiguration1, null) assertTrue(res1 is ResultWithDiagnostics.Failure) - assertNotNull(res1.reports.find { it.message == "Invalid argument: -jvm-target=1.8" }) + assertNotNull(res1.reports.find { it.message == "Invalid argument: -jvm-target->1.8" }) val compilationConfiguration2 = createJvmCompilationConfigurationFromTemplate { refineConfiguration { beforeCompiling { ctx -> ScriptCompilationConfiguration(ctx.compilationConfiguration) { - compilerOptions.append("-jvm-target=1.6") + compilerOptions.append("-jvm-target->1.6") }.asSuccess() } } } val res2 = BasicJvmScriptingHost().eval(script.toScriptSource(), compilationConfiguration2, null) assertTrue(res2 is ResultWithDiagnostics.Failure) - assertNotNull(res2.reports.find { it.message == "Invalid argument: -jvm-target=1.6" }) + assertNotNull(res2.reports.find { it.message == "Invalid argument: -jvm-target->1.6" }) } @Test