Release flag. Check conflicts with `-jvm-target'
This commit is contained in:
+5
-6
@@ -389,13 +389,12 @@ default: `indy-with-constants` for JVM target 9 or greater, `inline` otherwise""
|
|||||||
var stringConcat: String? by NullableStringFreezableVar(null)
|
var stringConcat: String? by NullableStringFreezableVar(null)
|
||||||
|
|
||||||
@Argument(
|
@Argument(
|
||||||
value = "-Xrelease",
|
value = "-Xjdk-release",
|
||||||
valueDescription = "Supported versions depend on used JDK",
|
valueDescription = "<version>",
|
||||||
description = """
|
description = """Compile against specified JDK API. Requires JDK 9 or newer.
|
||||||
Compile against specified JDK API. Supported versions depend on used JDK.
|
Supported versions depend on used JDK (For JDK 17 supported targets are 1.8, 9, 10 - 17). Also set `-jvm-target` value"""
|
||||||
"""
|
|
||||||
)
|
)
|
||||||
var release: String? by NullableStringFreezableVar(null)
|
var jdkRelease: String? by NullableStringFreezableVar(null)
|
||||||
|
|
||||||
|
|
||||||
@Argument(
|
@Argument(
|
||||||
|
|||||||
@@ -25,8 +25,41 @@ fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArgu
|
|||||||
|
|
||||||
putIfNotNull(JVMConfigurationKeys.FRIEND_PATHS, arguments.friendPaths?.asList())
|
putIfNotNull(JVMConfigurationKeys.FRIEND_PATHS, arguments.friendPaths?.asList())
|
||||||
|
|
||||||
if (arguments.jvmTarget != null) {
|
val releaseTargetArg = arguments.jdkRelease
|
||||||
val jvmTarget = JvmTarget.fromString(arguments.jvmTarget!!)
|
val jvmTargetArg = arguments.jvmTarget
|
||||||
|
if (releaseTargetArg != null) {
|
||||||
|
val value =
|
||||||
|
if (releaseTargetArg == "1.6" || releaseTargetArg == "1.8") releaseTargetArg.substringAfter("1.").toIntOrNull()
|
||||||
|
else releaseTargetArg.toIntOrNull()
|
||||||
|
if (value == null) {
|
||||||
|
messageCollector.report(
|
||||||
|
ERROR,
|
||||||
|
"Can't parse value passed for `-Xrelease`: $releaseTargetArg."
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
if (value < 6) {
|
||||||
|
messageCollector.report(
|
||||||
|
ERROR,
|
||||||
|
"`$value` is not valid value for `-Xrelease` flag."
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
//don't use release flag if it equals to compilation JDK version
|
||||||
|
if (value != getJavaVersion() || arguments.jdkHome != null) {
|
||||||
|
put(JVMConfigurationKeys.RELEASE, value)
|
||||||
|
}
|
||||||
|
if (jvmTargetArg != null && jvmTargetArg != releaseTargetArg) {
|
||||||
|
messageCollector.report(
|
||||||
|
ERROR,
|
||||||
|
"`-Xrelease=$releaseTargetArg` option conflicts with '-jvm-target=$jvmTargetArg'."
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val jvmTargetValue = releaseTargetArg ?: jvmTargetArg
|
||||||
|
if (jvmTargetValue != null) {
|
||||||
|
val jvmTarget = JvmTarget.fromString(jvmTargetValue)
|
||||||
if (jvmTarget != null) {
|
if (jvmTarget != null) {
|
||||||
put(JVMConfigurationKeys.JVM_TARGET, jvmTarget)
|
put(JVMConfigurationKeys.JVM_TARGET, jvmTarget)
|
||||||
if (jvmTarget == JvmTarget.JVM_1_6 && !arguments.suppressDeprecatedJvmTargetWarning) {
|
if (jvmTarget == JvmTarget.JVM_1_6 && !arguments.suppressDeprecatedJvmTargetWarning) {
|
||||||
@@ -37,7 +70,7 @@ fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArgu
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
messageCollector.report(
|
messageCollector.report(
|
||||||
ERROR, "Unknown JVM target version: ${arguments.jvmTarget}\n" +
|
ERROR, "Unknown JVM target version: $jvmTargetValue\n" +
|
||||||
"Supported versions: ${JvmTarget.values().joinToString { it.description }}"
|
"Supported versions: ${JvmTarget.values().joinToString { it.description }}"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -73,29 +106,6 @@ fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArgu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val releaseTarget = arguments.release
|
|
||||||
if (releaseTarget != null) {
|
|
||||||
val value = releaseTarget.toIntOrNull()
|
|
||||||
if (value == null) {
|
|
||||||
messageCollector.report(
|
|
||||||
ERROR,
|
|
||||||
"Can't parse value passed for `-Xrelease`: $releaseTarget."
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
if (value < 6) {
|
|
||||||
messageCollector.report(
|
|
||||||
ERROR,
|
|
||||||
"`$value` is not valid value for `-Xrelease` flag."
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
//don't use release flag if it equals to compilation JDK version
|
|
||||||
if (value != getJavaVersion() || arguments.jdkHome != null) {
|
|
||||||
put(JVMConfigurationKeys.RELEASE, value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
handleClosureGenerationSchemeArgument("-Xsam-conversions", arguments.samConversions, JVMConfigurationKeys.SAM_CONVERSIONS, jvmTarget)
|
handleClosureGenerationSchemeArgument("-Xsam-conversions", arguments.samConversions, JVMConfigurationKeys.SAM_CONVERSIONS, jvmTarget)
|
||||||
handleClosureGenerationSchemeArgument("-Xlambdas", arguments.lambdas, JVMConfigurationKeys.LAMBDAS, jvmTarget)
|
handleClosureGenerationSchemeArgument("-Xlambdas", arguments.lambdas, JVMConfigurationKeys.LAMBDAS, jvmTarget)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
error: `-Xrelease=11` option conflicts with '-jvm-target=10'.
|
||||||
|
COMPILATION_ERROR
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package foo;
|
||||||
|
|
||||||
|
public class Foo {
|
||||||
|
|
||||||
|
val z: java.nio.ByteBuffer? = null
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
error: `-Xrelease=9` option conflicts with '-jvm-target=10'.
|
||||||
|
COMPILATION_ERROR
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package foo;
|
||||||
|
|
||||||
|
public class Foo {
|
||||||
|
|
||||||
|
val z: java.nio.ByteBuffer? = null
|
||||||
|
}
|
||||||
@@ -1,2 +1,4 @@
|
|||||||
error: `5` is not valid value for `-Xrelease` flag.
|
error: `5` is not valid value for `-Xrelease` flag.
|
||||||
|
error: unknown JVM target version: 5
|
||||||
|
Supported versions: 1.6, 1.8, 9, 10, 11, 12, 13, 14, 15, 16, 17
|
||||||
COMPILATION_ERROR
|
COMPILATION_ERROR
|
||||||
|
|||||||
@@ -152,16 +152,23 @@ class Java11ModulesIntegrationTest : AbstractKotlinCompilerIntegrationTest() {
|
|||||||
fun testReleaseFlagWrongValue() {
|
fun testReleaseFlagWrongValue() {
|
||||||
// Test that although we have moduleA in the module path, it's not in the module graph
|
// Test that although we have moduleA in the module path, it's not in the module graph
|
||||||
// because we did not provide -Xadd-modules=moduleA
|
// because we did not provide -Xadd-modules=moduleA
|
||||||
module("module5", additionalKotlinArguments = listOf("-Xrelease=5"))
|
module("module5", additionalKotlinArguments = listOf("-Xjdk-release=5"))
|
||||||
module("module12", additionalKotlinArguments = listOf("-Xrelease=12"))
|
module("module12", additionalKotlinArguments = listOf("-Xjdk-release=12"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testReleaseFlag() {
|
fun testReleaseFlag() {
|
||||||
// Test that although we have moduleA in the module path, it's not in the module graph
|
// Test that although we have moduleA in the module path, it's not in the module graph
|
||||||
// because we did not provide -Xadd-modules=moduleA
|
// because we did not provide -Xadd-modules=moduleA
|
||||||
module("module")
|
module("module")
|
||||||
module("module11", additionalKotlinArguments = listOf("-Xrelease=11"))
|
module("module11", additionalKotlinArguments = listOf("-Xjdk-release=11"))
|
||||||
module("moduleSwing", additionalKotlinArguments = listOf("-Xrelease=9"))
|
module("moduleSwing", additionalKotlinArguments = listOf("-Xjdk-release=9"))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testReleaseFlagConflict() {
|
||||||
|
// Test that although we have moduleA in the module path, it's not in the module graph
|
||||||
|
// because we did not provide -Xadd-modules=moduleA
|
||||||
|
module("module9", additionalKotlinArguments = listOf("-Xjdk-release=9", "-jvm-target=10"))
|
||||||
|
module("module11", additionalKotlinArguments = listOf("-Xjdk-release=11", "-jvm-target=10"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testNamedReadsTransitive() {
|
fun testNamedReadsTransitive() {
|
||||||
|
|||||||
Reference in New Issue
Block a user