Validate "-jvm-target" value in CLI, improve message
This commit is contained in:
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.codegen.optimization.OptimizationClassBuilderFactory
|
||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
||||
import org.jetbrains.kotlin.config.JvmTarget
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ScriptDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
@@ -155,7 +156,7 @@ class GenerationState @JvmOverloads constructor(
|
||||
val isInlineDisabled: Boolean = configuration.getBoolean(CommonConfigurationKeys.DISABLE_INLINE)
|
||||
val useTypeTableInSerializer: Boolean = configuration.getBoolean(JVMConfigurationKeys.USE_TYPE_TABLE)
|
||||
val inheritMultifileParts: Boolean = configuration.getBoolean(JVMConfigurationKeys.INHERIT_MULTIFILE_PARTS)
|
||||
val isJvm8Target: Boolean = configuration.getBoolean(JVMConfigurationKeys.JVM_8_TARGET)
|
||||
val isJvm8Target: Boolean = configuration.get(JVMConfigurationKeys.JVM_TARGET) == JvmTarget.JVM_1_8
|
||||
|
||||
val rootContext: CodegenContext<*> = RootContext(this)
|
||||
|
||||
|
||||
+2
-2
@@ -51,8 +51,8 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments {
|
||||
@Argument(value = "module-name", description = "Module name")
|
||||
public String moduleName;
|
||||
|
||||
@Argument(value = "jvm-target", description = "Compile code to specified JVM target: 1.6 or 1.8. Default one is 1.6.")
|
||||
@ValueDescription("<1.6|1.8>")
|
||||
@Argument(value = "jvm-target", description = "Target version of the generated JVM bytecode (1.6 or 1.8), default is 1.6")
|
||||
@ValueDescription("<version>")
|
||||
public String jvmTarget;
|
||||
|
||||
// Advanced options
|
||||
|
||||
@@ -128,8 +128,17 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
if (friendPaths != null) {
|
||||
configuration.put(JVMConfigurationKeys.FRIEND_PATHS, friendPaths)
|
||||
}
|
||||
if ("1.8".equals(arguments.jvmTarget)) {
|
||||
configuration.put(JVMConfigurationKeys.JVM_8_TARGET, true)
|
||||
|
||||
if (arguments.jvmTarget != null) {
|
||||
val jvmTarget = JvmTarget.fromString(arguments.jvmTarget)
|
||||
if (jvmTarget != null) {
|
||||
configuration.put(JVMConfigurationKeys.JVM_TARGET, jvmTarget)
|
||||
}
|
||||
else {
|
||||
val errorMessage = "Unknown JVM target version: ${arguments.jvmTarget}\n" +
|
||||
"Supported versions: ${JvmTarget.values().joinToString { it.string }}"
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, errorMessage, CompilerMessageLocation.NO_LOCATION)
|
||||
}
|
||||
}
|
||||
|
||||
putAdvancedOptions(configuration, arguments)
|
||||
|
||||
@@ -57,8 +57,8 @@ public class JVMConfigurationKeys {
|
||||
public static final CompilerConfigurationKey<Boolean> USE_TYPE_TABLE =
|
||||
CompilerConfigurationKey.create("use type table in serializer");
|
||||
|
||||
public static final CompilerConfigurationKey<Boolean> JVM_8_TARGET =
|
||||
CompilerConfigurationKey.create("compile to jvm 8");
|
||||
public static final CompilerConfigurationKey<JvmTarget> JVM_TARGET =
|
||||
CompilerConfigurationKey.create("JVM bytecode target version");
|
||||
|
||||
public static final CompilerConfigurationKey<IncrementalCompilationComponents> INCREMENTAL_COMPILATION_COMPONENTS =
|
||||
CompilerConfigurationKey.create("incremental cache provider");
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.config
|
||||
|
||||
enum class JvmTarget(val string: String) {
|
||||
JVM_1_6("1.6"),
|
||||
JVM_1_8("1.8"),
|
||||
;
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun fromString(string: String) = values().find { it.string == string }
|
||||
}
|
||||
}
|
||||
Vendored
+1
-1
@@ -9,7 +9,7 @@ where possible options include:
|
||||
-script Evaluate the script file
|
||||
-kotlin-home <path> Path to Kotlin compiler home directory, used for runtime libraries discovery
|
||||
-module-name Module name
|
||||
-jvm-target <1.6|1.8> Compile code to specified JVM target: 1.6 or 1.8. Default one is 1.6.
|
||||
-jvm-target <version> Target version of the generated JVM bytecode (1.6 or 1.8), default is 1.6
|
||||
-language-version <version> Provide source compatibility with specified language version
|
||||
-nowarn Generate no warnings
|
||||
-verbose Enable verbose logging output
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ where possible options include:
|
||||
-script Evaluate the script file
|
||||
-kotlin-home <path> Path to Kotlin compiler home directory, used for runtime libraries discovery
|
||||
-module-name Module name
|
||||
-jvm-target <1.6|1.8> Compile code to specified JVM target: 1.6 or 1.8. Default one is 1.6.
|
||||
-jvm-target <version> Target version of the generated JVM bytecode (1.6 or 1.8), default is 1.6
|
||||
-language-version <version> Provide source compatibility with specified language version
|
||||
-nowarn Generate no warnings
|
||||
-verbose Enable verbose logging output
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
$TESTDATA_DIR$/simple.kt
|
||||
-d
|
||||
$TEMP_DIR$
|
||||
-jvm-target
|
||||
1.5
|
||||
@@ -0,0 +1,3 @@
|
||||
error: unknown JVM target version: 1.5
|
||||
Supported versions: 1.6, 1.8
|
||||
COMPILATION_ERROR
|
||||
@@ -289,6 +289,12 @@ public class CliTestGenerated extends AbstractCliTest {
|
||||
doJvmTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("wrongJvmTargetVersion.args")
|
||||
public void testWrongJvmTargetVersion() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/wrongJvmTargetVersion.args");
|
||||
doJvmTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("wrongScriptWithNoSource.args")
|
||||
public void testWrongScriptWithNoSource() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/wrongScriptWithNoSource.args");
|
||||
|
||||
@@ -44,6 +44,7 @@ import org.jetbrains.kotlin.codegen.state.GenerationState;
|
||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys;
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration;
|
||||
import org.jetbrains.kotlin.config.JVMConfigurationKeys;
|
||||
import org.jetbrains.kotlin.config.JvmTarget;
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic;
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages;
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.ResolutionUtils;
|
||||
@@ -128,7 +129,7 @@ public class KotlinBytecodeToolWindow extends JPanel implements Disposable {
|
||||
}
|
||||
|
||||
if (jvm8Target.isSelected()) {
|
||||
configuration.put(JVMConfigurationKeys.JVM_8_TARGET, true);
|
||||
configuration.put(JVMConfigurationKeys.JVM_TARGET, JvmTarget.JVM_1_8);
|
||||
}
|
||||
|
||||
return getBytecodeForFile(ktFile, configuration);
|
||||
|
||||
Reference in New Issue
Block a user