-Xjdk-release. Review fixes
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user