-Xjdk-release. Review fixes
This commit is contained in:
+3
-2
@@ -391,8 +391,9 @@ default: `indy-with-constants` for JVM target 9 or greater, `inline` otherwise""
|
||||
@Argument(
|
||||
value = "-Xjdk-release",
|
||||
valueDescription = "<version>",
|
||||
description = """Compile against specified JDK API. Requires JDK 9 or newer.
|
||||
Supported versions depend on used JDK (For JDK 17 supported targets are 1.8, 9, 10 - 17). Also set `-jvm-target` value"""
|
||||
description = """Compile against the specified JDK API version, similarly to javac's `-release`. Requires JDK 9 or newer.
|
||||
Supported versions depend on the used JDK; for JDK 17+ supported versions are 1.8, 9, 10, ..., 17.
|
||||
Also sets `-jvm-target` value equal to the selected JDK version"""
|
||||
)
|
||||
var jdkRelease: String? by NullableStringFreezableVar(null)
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ class ClasspathRootsResolver(
|
||||
private val requireStdlibModule: Boolean,
|
||||
private val outputDirectory: VirtualFile?,
|
||||
private val javaFileManager: KotlinCliJavaFileManager,
|
||||
private val release: Int
|
||||
private val jdkRelease: Int
|
||||
) {
|
||||
val javaModuleGraph = JavaModuleGraph(javaModuleFinder)
|
||||
|
||||
@@ -125,7 +125,7 @@ class ClasspathRootsResolver(
|
||||
modules += module
|
||||
}
|
||||
}
|
||||
if (release <= 0 || release >= 9) {
|
||||
if (jdkRelease <= 0 || jdkRelease >= 9) {
|
||||
addModularRoots(modules, result)
|
||||
} else {
|
||||
//TODO: see also `addJvmSdkRoots` usages, some refactoring is required with moving such logic into one place
|
||||
@@ -285,13 +285,13 @@ class ClasspathRootsResolver(
|
||||
if (module == null) {
|
||||
report(ERROR, "Module $moduleName cannot be found in the module graph")
|
||||
} else {
|
||||
for ((root, isBinary, isBinarySignature) in module.moduleRoots) {
|
||||
result.add(
|
||||
JavaRoot(
|
||||
root,
|
||||
if (isBinarySignature) JavaRoot.RootType.BINARY_SIG else if (isBinary) JavaRoot.RootType.BINARY else JavaRoot.RootType.SOURCE
|
||||
)
|
||||
)
|
||||
module.moduleRoots.mapTo(result) { (root, isBinary, isBinarySignature) ->
|
||||
val type = when {
|
||||
isBinarySignature -> JavaRoot.RootType.BINARY_SIG
|
||||
isBinary -> JavaRoot.RootType.BINARY
|
||||
else -> JavaRoot.RootType.SOURCE
|
||||
}
|
||||
JavaRoot(root, type)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,8 @@ class CliVirtualFileFinder(
|
||||
|
||||
private fun findBinaryOrSigClass(classId: ClassId, simpleName: String, rootType: Set<JavaRoot.RootType>) =
|
||||
index.findClass(classId, acceptedRootTypes = rootType) { dir, _ ->
|
||||
(dir.findChild("$simpleName.class") ?: findSigFileIfEnabled(dir, simpleName))?.takeIf(VirtualFile::isValid)
|
||||
val file = dir.findChild("$simpleName.class") ?: findSigFileIfEnabled(dir, simpleName)
|
||||
if (file != null && file.isValid) file else null
|
||||
}?.takeIf { it in scope }
|
||||
|
||||
private fun findBinaryOrSigClass(classId: ClassId) =
|
||||
|
||||
@@ -29,30 +29,24 @@ fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArgu
|
||||
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."
|
||||
)
|
||||
when (releaseTargetArg) {
|
||||
"1.6" -> 6
|
||||
"1.8" -> 8
|
||||
else -> releaseTargetArg.toIntOrNull()
|
||||
}
|
||||
if (value == null || value < 6) {
|
||||
messageCollector.report(ERROR, "Unknown JDK release version: $releaseTargetArg")
|
||||
} else {
|
||||
if (value < 6) {
|
||||
//don't use release flag if it equals to compilation JDK version
|
||||
if (value != getJavaVersion() || arguments.jdkHome != null) {
|
||||
put(JVMConfigurationKeys.JDK_RELEASE, value)
|
||||
}
|
||||
if (jvmTargetArg != null && jvmTargetArg != releaseTargetArg) {
|
||||
messageCollector.report(
|
||||
ERROR,
|
||||
"`$value` is not valid value for `-Xrelease` flag."
|
||||
"'-Xjdk-release=$releaseTargetArg' option conflicts with '-jvm-target $jvmTargetArg'. " +
|
||||
"Please remove the '-jvm-target' option"
|
||||
)
|
||||
} else {
|
||||
//don't use release flag if it equals to compilation JDK version
|
||||
if (value != getJavaVersion() || arguments.jdkHome != null) {
|
||||
put(JVMConfigurationKeys.JDK_RELEASE, value)
|
||||
}
|
||||
if (jvmTargetArg != null && jvmTargetArg != releaseTargetArg) {
|
||||
messageCollector.report(
|
||||
ERROR,
|
||||
"`-Xrelease=$releaseTargetArg` option conflicts with '-jvm-target=$jvmTargetArg'."
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,11 +70,6 @@ fun CompilerConfiguration.setupJvmSpecificArguments(arguments: K2JVMCompilerArgu
|
||||
}
|
||||
}
|
||||
|
||||
if (get(JVMConfigurationKeys.JVM_TARGET) == null) {
|
||||
put(JVMConfigurationKeys.JVM_TARGET, JvmTarget.JVM_1_8)
|
||||
}
|
||||
|
||||
|
||||
val jvmTarget = get(JVMConfigurationKeys.JVM_TARGET) ?: JvmTarget.DEFAULT
|
||||
if (jvmTarget.majorVersion < JvmTarget.JVM_1_8.majorVersion) {
|
||||
val jvmDefaultMode = languageVersionSettings.getFlag(JvmAnalysisFlags.jvmDefaultMode)
|
||||
@@ -185,8 +174,8 @@ fun CompilerConfiguration.configureExplicitContentRoots(arguments: K2JVMCompiler
|
||||
}
|
||||
|
||||
fun CompilerConfiguration.configureStandardLibs(paths: KotlinPaths?, arguments: K2JVMCompilerArguments) {
|
||||
val releaseFlagValue = this.get(JVMConfigurationKeys.JDK_RELEASE, 0)
|
||||
val isModularJava = isModularJava() && (releaseFlagValue <= 0 || releaseFlagValue >= 9)
|
||||
val jdkRelease = get(JVMConfigurationKeys.JDK_RELEASE)
|
||||
val isModularJava = isModularJava() && (jdkRelease == null || jdkRelease >= 9)
|
||||
|
||||
fun addRoot(moduleName: String, libraryName: String, getLibrary: (KotlinPaths) -> File, noLibraryArgument: String) {
|
||||
addModularRootIfNotNull(
|
||||
|
||||
@@ -52,22 +52,22 @@ class CliJavaModuleFinder(
|
||||
private val ctSymFile: VirtualFile? by lazy {
|
||||
if (jdkHome == null) return@lazy reportError("JDK_HOME path is not specified in compiler configuration")
|
||||
|
||||
val jdkRootFile = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL).findFileByPath(jdkHome.path)
|
||||
val jdkRootFile = StandardFileSystems.local().findFileByPath(jdkHome.path)
|
||||
?: return@lazy reportError("Can't create virtual file for JDK root under ${jdkHome.path}")
|
||||
|
||||
val lib = jdkRootFile.findChild("lib") ?: return@lazy reportError("Can't find `lib` folder under JDK root: ${jdkHome.path}")
|
||||
|
||||
val ctSym = lib.findChild("ct.sym") ?: return@lazy reportError("Can't find `ct.sym` file in ${jdkHome.path}")
|
||||
|
||||
if (!ctSym.isValid) return@lazy reportError("`ct.sym` is invalid: ${ctSym.path}")
|
||||
|
||||
val ctSym = lib.findChild("ct.sym")
|
||||
?: return@lazy reportError(
|
||||
"This JDK does not have the 'ct.sym' file required for the '-Xjdk-release=$releaseTarget' option: ${jdkHome.path}"
|
||||
)
|
||||
|
||||
ctSym
|
||||
}
|
||||
|
||||
private val ctSymRootFolder: VirtualFile? by lazy {
|
||||
if (ctSymFile != null) {
|
||||
VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.JAR_PROTOCOL)
|
||||
?.findFileByPath(ctSymFile?.path + URLUtil.JAR_SEPARATOR)
|
||||
StandardFileSystems.jar()?.findFileByPath(ctSymFile?.path + URLUtil.JAR_SEPARATOR)
|
||||
?: reportError("Can't open `ct.sym` as jar file, file path: ${ctSymFile?.path} ")
|
||||
} else {
|
||||
null
|
||||
@@ -132,10 +132,8 @@ class CliJavaModuleFinder(
|
||||
if (isCompilationJDK12OrLater) emptyMap()
|
||||
else hashMapOf<String, Boolean>().also { parts ->
|
||||
moduleInfo.exports.forEach {
|
||||
it.packageFqName.pathSegments().fold("") { acc, v ->
|
||||
val packagePart = if (acc.isEmpty()) v.asString() else "$acc.${v.asString()}"
|
||||
parts[packagePart] = false
|
||||
packagePart
|
||||
for (part in generateSequence(it.packageFqName) { part -> if (!part.isRoot) part.parent() else null }) {
|
||||
parts[part.asString()] = false
|
||||
}
|
||||
}
|
||||
//Do it separately to avoid reset to false
|
||||
|
||||
+3
-2
@@ -35,8 +35,9 @@ where advanced options include:
|
||||
-Xjava-package-prefix Package prefix for Java files
|
||||
-Xjava-source-roots=<path> Paths to directories with Java source files
|
||||
-Xjavac-arguments=<option[,]> Java compiler arguments
|
||||
-Xjdk-release=<version> Compile against specified JDK API. Requires JDK 9 or newer.
|
||||
Supported versions depend on used JDK (For JDK 17 supported targets are 1.8, 9, 10 - 17). Also set `-jvm-target` value
|
||||
-Xjdk-release=<version> Compile against the specified JDK API version, similarly to javac's `-release`. Requires JDK 9 or newer.
|
||||
Supported versions depend on the used JDK; for JDK 17+ supported versions are 1.8, 9, 10, ..., 17.
|
||||
Also sets `-jvm-target` value equal to the selected JDK version
|
||||
-Xjspecify-annotations=ignore|strict|warn
|
||||
Specify behavior for jspecify annotations.
|
||||
Default value is 'warn'
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
error: `-Xrelease=11` option conflicts with '-jvm-target=10'.
|
||||
error: '-Xjdk-release=11' option conflicts with '-jvm-target 10'. Please remove the '-jvm-target' option
|
||||
COMPILATION_ERROR
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
error: `-Xrelease=9` option conflicts with '-jvm-target=10'.
|
||||
error: '-Xjdk-release=9' option conflicts with '-jvm-target 10'. Please remove the '-jvm-target' option
|
||||
COMPILATION_ERROR
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
error: `5` is not valid value for `-Xrelease` flag.
|
||||
error: unknown JDK release version: 5
|
||||
error: unknown JVM target version: 5
|
||||
Supported versions: 1.6, 1.8, 9, 10, 11, 12, 13, 14, 15, 16, 17
|
||||
COMPILATION_ERROR
|
||||
|
||||
@@ -149,23 +149,17 @@ class Java11ModulesIntegrationTest : AbstractKotlinCompilerIntegrationTest() {
|
||||
}
|
||||
|
||||
fun testReleaseFlagWrongValue() {
|
||||
// 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("module5", additionalKotlinArguments = listOf("-Xjdk-release=5"))
|
||||
module("module12", additionalKotlinArguments = listOf("-Xjdk-release=12"))
|
||||
}
|
||||
|
||||
fun testReleaseFlag() {
|
||||
// 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("module")
|
||||
module("module11", additionalKotlinArguments = listOf("-Xjdk-release=11"))
|
||||
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"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user