From 99b5e5a3732bc58bb2fa48a755ee37da03170323 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 1 Feb 2021 20:01:16 +0100 Subject: [PATCH] Deprecate JVM target 1.6 #KT-44650 Fixed --- .../cli/common/arguments/K2JVMCompilerArguments.kt | 8 +++++++- .../org/jetbrains/kotlin/cli/jvm/jvmArguments.kt | 6 ++++++ compiler/testData/cli/jvm/extraHelp.out | 2 ++ compiler/testData/cli/jvm/help.out | 2 +- compiler/testData/cli/jvm/jvm6Target.args | 5 +++++ compiler/testData/cli/jvm/jvm6Target.out | 2 ++ compiler/testData/cli/jvm/jvmDefaultAll.out | 1 + .../org/jetbrains/kotlin/cli/CliTestGenerated.java | 5 +++++ .../CompileKotlinAgainstCustomBinariesTest.kt | 14 +++++++++----- .../kotlin/gradle/dsl/KotlinJvmOptions.kt | 2 +- 10 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 compiler/testData/cli/jvm/jvm6Target.args create mode 100644 compiler/testData/cli/jvm/jvm6Target.out 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 b0295d362f1..9eb8a13aed3 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 @@ -71,7 +71,7 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { @Argument( value = "-jvm-target", valueDescription = "", - description = "Target version of the generated JVM bytecode (1.6, 1.8, 9, 10, 11, 12, 13, 14 or 15), default is 1.8" + description = "Target version of the generated JVM bytecode (1.6 (DEPRECATED), 1.8, 9, 10, 11, 12, 13, 14 or 15), default is 1.8" ) var jvmTarget: String? by NullableStringFreezableVar(JvmTarget.DEFAULT.description) @@ -448,6 +448,12 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { ) var enableJvmPreview: Boolean by FreezableVar(false) + @Argument( + value = "-Xsuppress-deprecated-jvm-target-warning", + description = "Suppress deprecation warning about deprecated JVM target versions" + ) + var suppressDeprecatedJvmTargetWarning: Boolean by FreezableVar(false) + override fun configureAnalysisFlags(collector: MessageCollector): MutableMap, Any> { val result = super.configureAnalysisFlags(collector) result[JvmAnalysisFlags.strictMetadataVersionSemantics] = strictMetadataVersionSemantics diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt index c7aad2ada45..84ab300d7db 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/jvmArguments.kt @@ -29,6 +29,12 @@ fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArgu val jvmTarget = JvmTarget.fromString(arguments.jvmTarget!!) if (jvmTarget != null) { put(JVMConfigurationKeys.JVM_TARGET, jvmTarget) + if (jvmTarget == JvmTarget.JVM_1_6 && !arguments.suppressDeprecatedJvmTargetWarning) { + messageCollector.report( + STRONG_WARNING, + "JVM target 1.6 is deprecated and will be removed in a future release. Please migrate to JVM target 1.8 or above" + ) + } } else { messageCollector.report( ERROR, "Unknown JVM target version: ${arguments.jvmTarget}\n" + diff --git a/compiler/testData/cli/jvm/extraHelp.out b/compiler/testData/cli/jvm/extraHelp.out index 259b0f30665..6512353dce0 100644 --- a/compiler/testData/cli/jvm/extraHelp.out +++ b/compiler/testData/cli/jvm/extraHelp.out @@ -118,6 +118,8 @@ where advanced options include: -Xsupport-compatqual-checker-framework-annotations=enable|disable Specify behavior for Checker Framework compatqual annotations (NullableDecl/NonNullDecl). Default value is 'enable' + -Xsuppress-deprecated-jvm-target-warning + Suppress deprecation warning about deprecated JVM target versions -Xsuppress-missing-builtins-error Suppress the "cannot access built-in declaration" error (useful with -no-stdlib) -Xuse-ir Use the IR backend diff --git a/compiler/testData/cli/jvm/help.out b/compiler/testData/cli/jvm/help.out index e552148ed9b..376f8720d62 100644 --- a/compiler/testData/cli/jvm/help.out +++ b/compiler/testData/cli/jvm/help.out @@ -6,7 +6,7 @@ where possible options include: -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 - -jvm-target Target version of the generated JVM bytecode (1.6, 1.8, 9, 10, 11, 12, 13, 14 or 15), default is 1.8 + -jvm-target Target version of the generated JVM bytecode (1.6 (DEPRECATED), 1.8, 9, 10, 11, 12, 13, 14 or 15), default is 1.8 -module-name Name of the generated .kotlin_module file -no-jdk Don't automatically include the Java runtime into the classpath -no-reflect Don't automatically include Kotlin reflection into the classpath diff --git a/compiler/testData/cli/jvm/jvm6Target.args b/compiler/testData/cli/jvm/jvm6Target.args new file mode 100644 index 00000000000..d7e4dd3f1bd --- /dev/null +++ b/compiler/testData/cli/jvm/jvm6Target.args @@ -0,0 +1,5 @@ +$TESTDATA_DIR$/jvm8Target.kt +-d +$TEMP_DIR$ +-jvm-target +1.6 diff --git a/compiler/testData/cli/jvm/jvm6Target.out b/compiler/testData/cli/jvm/jvm6Target.out new file mode 100644 index 00000000000..ea521634a30 --- /dev/null +++ b/compiler/testData/cli/jvm/jvm6Target.out @@ -0,0 +1,2 @@ +warning: JVM target 1.6 is deprecated and will be removed in a future release. Please migrate to JVM target 1.8 or above +OK diff --git a/compiler/testData/cli/jvm/jvmDefaultAll.out b/compiler/testData/cli/jvm/jvmDefaultAll.out index 9d661afc460..c33fbbd9084 100644 --- a/compiler/testData/cli/jvm/jvmDefaultAll.out +++ b/compiler/testData/cli/jvm/jvmDefaultAll.out @@ -1,2 +1,3 @@ +warning: JVM target 1.6 is deprecated and will be removed in a future release. Please migrate to JVM target 1.8 or above error: '-Xjvm-default=all' is only supported since JVM target 1.8. Recompile with '-jvm-target 1.8' COMPILATION_ERROR diff --git a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java index 445389dac65..e434fa6c490 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java @@ -536,6 +536,11 @@ public class CliTestGenerated extends AbstractCliTest { runTest("compiler/testData/cli/jvm/jsr305Warn.args"); } + @TestMetadata("jvm6Target.args") + public void testJvm6Target() throws Exception { + runTest("compiler/testData/cli/jvm/jvm6Target.args"); + } + @TestMetadata("jvm8Target.args") public void testJvm8Target() throws Exception { runTest("compiler/testData/cli/jvm/jvm8Target.args"); diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt index 0f3e6d047ec..c36330550c9 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime import org.jetbrains.kotlin.codegen.inline.remove import org.jetbrains.kotlin.codegen.optimization.common.asSequence import org.jetbrains.kotlin.codegen.optimization.common.intConstant +import org.jetbrains.kotlin.config.JvmTarget import org.jetbrains.kotlin.config.KotlinCompilerVersion import org.jetbrains.kotlin.config.KotlinCompilerVersion.TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY import org.jetbrains.kotlin.config.LanguageFeature @@ -43,6 +44,7 @@ import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparatorAdaptor.valid import org.jetbrains.kotlin.utils.PathUtil import org.jetbrains.org.objectweb.asm.* import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode +import org.jetbrains.org.objectweb.asm.tree.ClassNode import org.jetbrains.org.objectweb.asm.tree.MethodInsnNode import org.jetbrains.org.objectweb.asm.tree.MethodNode import java.io.ByteArrayInputStream @@ -609,11 +611,13 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration } fun testInlineAnonymousObjectWithDifferentTarget() { - val library = compileLibrary("library", additionalOptions = listOf("-jvm-target", "1.6")) - compileKotlin("source.kt", tmpdir, listOf(library), additionalOptions = listOf("-jvm-target", "1.8")) - val classLoader = - URLClassLoader(arrayOf(library.toURI().toURL(), tmpdir.toURI().toURL()), ForTestCompileRuntime.runtimeJarClassLoader()) - classLoader.loadClass("SourceKt").getDeclaredMethod("main").invoke(null) + val library = compileLibrary("library", additionalOptions = listOf("-jvm-target", JvmTarget.JVM_1_8.description)) + compileKotlin("source.kt", tmpdir, listOf(library), additionalOptions = listOf("-jvm-target", JvmTarget.JVM_9.description)) + for (name in listOf("SourceKt", "SourceKt\$main\$\$inlined\$foo$1")) { + val node = ClassNode() + ClassReader(File(tmpdir, "$name.class").readBytes()).accept(node, 0) + assertEquals(JvmTarget.JVM_9.majorVersion, node.version) + } } fun testFirAgainstFir() { diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJvmOptions.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJvmOptions.kt index 700199bfcbd..d1b1e9eb076 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJvmOptions.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJvmOptions.kt @@ -23,7 +23,7 @@ interface KotlinJvmOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonOption var jdkHome: kotlin.String? /** - * Target version of the generated JVM bytecode (1.6, 1.8, 9, 10, 11, 12, 13, 14 or 15), default is 1.8 + * Target version of the generated JVM bytecode (1.6 (DEPRECATED), 1.8, 9, 10, 11, 12, 13, 14 or 15), default is 1.8 * Possible values: "1.6", "1.8", "9", "10", "11", "12", "13", "14", "15" * Default value: "1.8" */