Skip to content

Commit af048b8

Browse files
ilmirusSpace Cloud
authored and
Space Cloud
committed
CLI: Follow symbolic links of content roots
Otherwise, incremental compilation is broken #KT-77445
1 parent e212b7e commit af048b8

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ import org.jetbrains.kotlin.util.PhaseType
5151
import org.jetbrains.kotlin.util.tryMeasurePhaseTime
5252
import org.jetbrains.kotlin.utils.addToStdlib.runIf
5353
import java.io.File
54+
import java.nio.file.Paths
55+
import kotlin.io.path.isSymbolicLink
5456

5557
object KotlinToJVMBytecodeCompiler {
5658
var customClassBuilderFactory = CompilerConfigurationKey.create<ClassBuilderFactory>("Custom ClassBuilderFactory")
@@ -471,10 +473,18 @@ fun CompilerConfiguration.configureSourceRoots(chunk: List<Module>, buildFile: F
471473

472474
for (module in chunk) {
473475
for (classpathRoot in module.getClasspathRoots()) {
476+
// The "official" way of `Paths.get(path).isSymbolicLink()` does not work on Windows
477+
// if the path starts with `/C:` - `sun.nio.fs.WindowsPathParser.normalize`
478+
// throws `InvalidPathException: Illegal char <:>`.
479+
val path =
480+
if (System.getProperty("os.name").contains("Windows") && classpathRoot.startsWith("/"))
481+
Paths.get(classpathRoot.removePrefix("/"))
482+
else Paths.get(classpathRoot)
483+
val file = if (path.isSymbolicLink()) path.toRealPath().toFile() else File(classpathRoot)
474484
if (isJava9Module) {
475-
add(CLIConfigurationKeys.CONTENT_ROOTS, JvmModulePathRoot(File(classpathRoot)))
485+
add(CLIConfigurationKeys.CONTENT_ROOTS, JvmModulePathRoot(file))
476486
}
477-
add(CLIConfigurationKeys.CONTENT_ROOTS, JvmClasspathRoot(File(classpathRoot)))
487+
add(CLIConfigurationKeys.CONTENT_ROOTS, JvmClasspathRoot(file))
478488
}
479489
}
480490

0 commit comments

Comments
 (0)