Use -source/target 1.6 for Java sources in codegen tests
In cases when the test has the JVM_TARGET directive, use that one for Java compilation as well. Otherwise, for box tests, the corresponding test in `JvmTarget6OnJvm6` (module `:compiler:tests-different-jdk`) will fail. However, it affects all codegen tests, so fix a bunch of them which use Java 8+ features to explicitly compile with JVM target 1.8. In particular, this obsoletes the SKIP_JDK6 directive in those tests because "JVM_TARGET: 1.8" also skips it for JDK 6. The check for IS_SOURCE_6_STILL_SUPPORTED is needed in order to still be able to run tests in the project while only having a single JDK > 11 installed, and having all of the env vars JDK_16, JDK_17, JDK_18 pointing to that JDK.
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
// SKIP_JDK6
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
// FILE: Base.java
|
// FILE: Base.java
|
||||||
|
|
||||||
public interface Base {
|
public interface Base {
|
||||||
@@ -12,6 +10,7 @@ public interface Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FILE: main.kt
|
// FILE: main.kt
|
||||||
|
// JVM_TARGET: 1.8
|
||||||
|
|
||||||
public interface BaseKotlin : Base {
|
public interface BaseKotlin : Base {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
// SKIP_JDK6
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
// FILE: Base.java
|
// FILE: Base.java
|
||||||
|
|
||||||
public interface Base {
|
public interface Base {
|
||||||
@@ -12,6 +10,7 @@ public interface Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FILE: main.kt
|
// FILE: main.kt
|
||||||
|
// JVM_TARGET: 1.8
|
||||||
|
|
||||||
public interface BaseKotlin : Base {
|
public interface BaseKotlin : Base {
|
||||||
override fun getValue() = "OK"
|
override fun getValue() = "OK"
|
||||||
|
|||||||
+1
-2
@@ -1,4 +1,3 @@
|
|||||||
// SKIP_JDK6
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// FILE: Base.java
|
// FILE: Base.java
|
||||||
|
|
||||||
@@ -18,8 +17,8 @@ public interface Base2 extends Base {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// FILE: main.kt
|
// FILE: main.kt
|
||||||
|
// JVM_TARGET: 1.8
|
||||||
|
|
||||||
interface KBase : Base
|
interface KBase : Base
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,3 @@
|
|||||||
// SKIP_JDK6
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// FILE: Base.java
|
// FILE: Base.java
|
||||||
|
|
||||||
@@ -18,6 +17,7 @@ public interface Base2 extends Base {
|
|||||||
|
|
||||||
|
|
||||||
// FILE: main.kt
|
// FILE: main.kt
|
||||||
|
// JVM_TARGET: 1.8
|
||||||
|
|
||||||
interface KBase : Base {
|
interface KBase : Base {
|
||||||
override fun test() = "O" + getValue()
|
override fun test() = "O" + getValue()
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// SKIP_JDK6
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// FILE: Base.java
|
// FILE: Base.java
|
||||||
|
|
||||||
@@ -11,6 +10,8 @@ public interface Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FILE: main.kt
|
// FILE: main.kt
|
||||||
|
// JVM_TARGET: 1.8
|
||||||
|
|
||||||
class Fail : Base {
|
class Fail : Base {
|
||||||
override fun getValue() = "Fail"
|
override fun getValue() = "Fail"
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -1,4 +1,3 @@
|
|||||||
// SKIP_JDK6
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// FILE: Base.java
|
// FILE: Base.java
|
||||||
|
|
||||||
@@ -11,6 +10,8 @@ public interface Base extends KBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FILE: main.kt
|
// FILE: main.kt
|
||||||
|
// JVM_TARGET: 1.8
|
||||||
|
|
||||||
interface KBase {
|
interface KBase {
|
||||||
fun getValue(): String
|
fun getValue(): String
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -1,4 +1,3 @@
|
|||||||
// SKIP_JDK6
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// FILE: Base.java
|
// FILE: Base.java
|
||||||
|
|
||||||
@@ -11,6 +10,8 @@ public interface Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FILE: main.kt
|
// FILE: main.kt
|
||||||
|
// JVM_TARGET: 1.8
|
||||||
|
|
||||||
class Fail : Base {
|
class Fail : Base {
|
||||||
override fun getValue() = "Fail"
|
override fun getValue() = "Fail"
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -1,6 +1,5 @@
|
|||||||
// !LANGUAGE: -NoDelegationToJavaDefaultInterfaceMembers
|
// !LANGUAGE: -NoDelegationToJavaDefaultInterfaceMembers
|
||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
// IGNORE_BACKEND_FIR: JVM_IR
|
||||||
// SKIP_JDK6
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// FILE: Base.java
|
// FILE: Base.java
|
||||||
|
|
||||||
@@ -13,6 +12,8 @@ public interface Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FILE: main.kt
|
// FILE: main.kt
|
||||||
|
// JVM_TARGET: 1.8
|
||||||
|
|
||||||
class OK : Base {
|
class OK : Base {
|
||||||
override fun getValue() = "OK"
|
override fun getValue() = "OK"
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,5 @@
|
|||||||
// !LANGUAGE: +StrictJavaNullabilityAssertions
|
// !LANGUAGE: +StrictJavaNullabilityAssertions
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// SKIP_JDK6
|
|
||||||
// See KT-8135
|
// See KT-8135
|
||||||
// We could generate runtime assertion on call site for 'generic<NOT_NULL_TYPE>()' below.
|
// We could generate runtime assertion on call site for 'generic<NOT_NULL_TYPE>()' below.
|
||||||
|
|
||||||
@@ -24,7 +23,8 @@ fun <T> generic(j: J) = j.nullT<T>()
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class J {
|
public class J {
|
||||||
public <T> @NotNull T nullT() {
|
@NotNull
|
||||||
|
public <T> T nullT() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// SKIP_JDK6
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// FILE: Simple.java
|
// FILE: Simple.java
|
||||||
|
|
||||||
@@ -9,6 +8,7 @@ public interface Simple {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FILE: main.kt
|
// FILE: main.kt
|
||||||
|
// JVM_TARGET: 1.8
|
||||||
|
|
||||||
interface KInterface: Simple {
|
interface KInterface: Simple {
|
||||||
override fun test(s: String): String {
|
override fun test(s: String): String {
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,3 @@
|
|||||||
// SKIP_JDK6
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// FILE: Test.java
|
// FILE: Test.java
|
||||||
|
|
||||||
@@ -12,6 +11,7 @@ interface Test<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FILE: main.kt
|
// FILE: main.kt
|
||||||
|
// JVM_TARGET: 1.8
|
||||||
|
|
||||||
class Child : Test<String> {
|
class Child : Test<String> {
|
||||||
override fun call() : String {
|
override fun call() : String {
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,3 @@
|
|||||||
// SKIP_JDK6
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// FILE: JavaCall.java
|
// FILE: JavaCall.java
|
||||||
|
|
||||||
@@ -24,6 +23,7 @@ interface Test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FILE: sam.kt
|
// FILE: sam.kt
|
||||||
|
// JVM_TARGET: 1.8
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
val lambda = { "X" }
|
val lambda = { "X" }
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
// SKIP_JDK6
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
|
// JVM_TARGET: 1.8
|
||||||
// FILE: Test.kt
|
// FILE: Test.kt
|
||||||
open class KFoo {
|
open class KFoo {
|
||||||
fun foo(): String {
|
fun foo(): String {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// SKIP_JDK6
|
|
||||||
// FILE: I.java
|
// FILE: I.java
|
||||||
interface I {
|
interface I {
|
||||||
default String ifun() { return "fail"; }
|
default String ifun() { return "fail"; }
|
||||||
@@ -14,6 +13,7 @@ public class Z {
|
|||||||
public class Zz extends Z implements I {}
|
public class Zz extends Z implements I {}
|
||||||
|
|
||||||
// FILE: multipleImplFromJava.kt
|
// FILE: multipleImplFromJava.kt
|
||||||
|
// JVM_TARGET: 1.8
|
||||||
|
|
||||||
class Cc : Zz()
|
class Cc : Zz()
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,5 @@
|
|||||||
// FILE: kt43217.kt
|
// FILE: kt43217.kt
|
||||||
|
// JVM_TARGET: 1.8
|
||||||
class A {
|
class A {
|
||||||
private val b =
|
private val b =
|
||||||
object : DoubleExpression() {
|
object : DoubleExpression() {
|
||||||
@@ -43,4 +44,3 @@ public interface ObservableDouble extends ObservableValue<Double> {
|
|||||||
@NotNull
|
@NotNull
|
||||||
Object isEqualTo(double value);
|
Object isEqualTo(double value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-1
@@ -18,12 +18,17 @@ package org.jetbrains.kotlin.codegen
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoot
|
import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoot
|
||||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||||
|
import org.jetbrains.kotlin.config.JvmTarget
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
abstract class AbstractBlackBoxAgainstJavaCodegenTest : AbstractBlackBoxCodegenTest() {
|
abstract class AbstractBlackBoxAgainstJavaCodegenTest : AbstractBlackBoxCodegenTest() {
|
||||||
override fun doMultiFileTest(wholeFile: File, files: List<TestFile>) {
|
override fun doMultiFileTest(wholeFile: File, files: List<TestFile>) {
|
||||||
javaClassesOutputDirectory = writeJavaFiles(files)!!.let { directory ->
|
javaClassesOutputDirectory = writeJavaFiles(files)!!.let { directory ->
|
||||||
CodegenTestUtil.compileJava(CodegenTestUtil.findJavaSourcesInDirectory(directory), emptyList(), extractJavacOptions(files))
|
val jvmTargets = files.mapNotNullTo(mutableSetOf()) { it.directives["JVM_TARGET"]?.let((JvmTarget)::fromString) }
|
||||||
|
check(jvmTargets.size <= 1) { "Having different JVM_TARGETs for different files is not supported in this test." }
|
||||||
|
CodegenTestUtil.compileJava(
|
||||||
|
CodegenTestUtil.findJavaSourcesInDirectory(directory), emptyList(), extractJavacOptions(files, jvmTargets.firstOrNull())
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
super.doMultiFileTest(wholeFile, files.map { file ->
|
super.doMultiFileTest(wholeFile, files.map { file ->
|
||||||
|
|||||||
@@ -63,9 +63,7 @@ import static org.jetbrains.kotlin.cli.common.output.OutputUtilsKt.writeAllTo;
|
|||||||
import static org.jetbrains.kotlin.codegen.CodegenTestUtil.*;
|
import static org.jetbrains.kotlin.codegen.CodegenTestUtil.*;
|
||||||
import static org.jetbrains.kotlin.codegen.TestUtilsKt.extractUrls;
|
import static org.jetbrains.kotlin.codegen.TestUtilsKt.extractUrls;
|
||||||
import static org.jetbrains.kotlin.test.KotlinTestUtils.getAnnotationsJar;
|
import static org.jetbrains.kotlin.test.KotlinTestUtils.getAnnotationsJar;
|
||||||
import static org.jetbrains.kotlin.test.clientserver.TestProcessServerKt.getBoxMethodOrNull;
|
import static org.jetbrains.kotlin.test.clientserver.TestProcessServerKt.*;
|
||||||
import static org.jetbrains.kotlin.test.clientserver.TestProcessServerKt.getGeneratedClass;
|
|
||||||
import static org.jetbrains.kotlin.test.clientserver.TestProcessServerKt.runBoxMethod;
|
|
||||||
|
|
||||||
public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.TestFile> {
|
public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.TestFile> {
|
||||||
private static final String DEFAULT_TEST_FILE_NAME = "a_test";
|
private static final String DEFAULT_TEST_FILE_NAME = "a_test";
|
||||||
@@ -487,7 +485,6 @@ public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.Test
|
|||||||
it -> InTextDirectivesUtils.isDirectiveDefined(it.content, "ANDROID_ANNOTATIONS")
|
it -> InTextDirectivesUtils.isDirectiveDefined(it.content, "ANDROID_ANNOTATIONS")
|
||||||
);
|
);
|
||||||
|
|
||||||
List<String> javacOptions = extractJavacOptions(files);
|
|
||||||
List<File> classpath = new ArrayList<>();
|
List<File> classpath = new ArrayList<>();
|
||||||
classpath.add(getAnnotationsJar());
|
classpath.add(getAnnotationsJar());
|
||||||
|
|
||||||
@@ -531,6 +528,7 @@ public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.Test
|
|||||||
updateJavaClasspath(javaClasspath);
|
updateJavaClasspath(javaClasspath);
|
||||||
|
|
||||||
javaClassesOutputDirectory = getJavaClassesOutputDirectory();
|
javaClassesOutputDirectory = getJavaClassesOutputDirectory();
|
||||||
|
List<String> javacOptions = extractJavacOptions(files, configuration.get(JVMConfigurationKeys.JVM_TARGET));
|
||||||
compileJava(findJavaSourcesInDirectory(javaSourceDir), javaClasspath, javacOptions, javaClassesOutputDirectory);
|
compileJava(findJavaSourcesInDirectory(javaSourceDir), javaClasspath, javacOptions, javaClassesOutputDirectory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -538,22 +536,33 @@ public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.Test
|
|||||||
protected void updateJavaClasspath(@NotNull List<String> javaClasspath) {}
|
protected void updateJavaClasspath(@NotNull List<String> javaClasspath) {}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected static List<String> extractJavacOptions(@NotNull List<TestFile> files) {
|
protected static List<String> extractJavacOptions(@NotNull List<TestFile> files, @Nullable JvmTarget kotlinTarget) {
|
||||||
List<String> javacOptions = new ArrayList<>(0);
|
List<String> javacOptions = new ArrayList<>(0);
|
||||||
for (TestFile file : files) {
|
for (TestFile file : files) {
|
||||||
javacOptions.addAll(InTextDirectivesUtils.findListWithPrefixes(file.content, "// JAVAC_OPTIONS:"));
|
javacOptions.addAll(InTextDirectivesUtils.findListWithPrefixes(file.content, "// JAVAC_OPTIONS:"));
|
||||||
}
|
}
|
||||||
updateJavacOptions(javacOptions);
|
String javaTarget = computeJavaTarget(javacOptions, kotlinTarget);
|
||||||
|
if (javaTarget != null) {
|
||||||
|
javacOptions.add("-source");
|
||||||
|
javacOptions.add(javaTarget);
|
||||||
|
javacOptions.add("-target");
|
||||||
|
javacOptions.add(javaTarget);
|
||||||
|
}
|
||||||
return javacOptions;
|
return javacOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void updateJavacOptions(@NotNull List<String> javacOptions) {
|
private static final boolean IS_SOURCE_6_STILL_SUPPORTED =
|
||||||
if (JAVA_COMPILATION_TARGET != null && !javacOptions.contains("-target")) {
|
// JDKs up to 11 do support -source/target 1.6, but later -- don't.
|
||||||
javacOptions.add("-source");
|
Arrays.asList("1.6", "1.7", "1.8", "9", "10", "11").contains(System.getProperty("java.specification.version"));
|
||||||
javacOptions.add(JAVA_COMPILATION_TARGET);
|
|
||||||
javacOptions.add("-target");
|
private static String computeJavaTarget(@NotNull List<String> javacOptions, @Nullable JvmTarget kotlinTarget) {
|
||||||
javacOptions.add(JAVA_COMPILATION_TARGET);
|
if (JAVA_COMPILATION_TARGET != null && !javacOptions.contains("-target"))
|
||||||
}
|
return JAVA_COMPILATION_TARGET;
|
||||||
|
if (kotlinTarget != null && kotlinTarget.compareTo(JvmTarget.JVM_1_6) > 0)
|
||||||
|
return kotlinTarget.getDescription();
|
||||||
|
if (IS_SOURCE_6_STILL_SUPPORTED)
|
||||||
|
return "1.6";
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
Reference in New Issue
Block a user