Normalize virtual file paths to prevent duplicate sources

#KT-52465 Fixed
This commit is contained in:
Alexander Udalov
2022-05-25 08:54:51 +02:00
parent e25dee558f
commit a7f4981fe5
4 changed files with 14 additions and 3 deletions
@@ -44,7 +44,8 @@ inline fun List<KotlinSourceRoot>.forAllFiles(
val virtualFileCreator = PreprocessedFileCreator(project) val virtualFileCreator = PreprocessedFileCreator(project)
for ((sourceRootPath, isCommon) in this) { for ((sourceRootPath, isCommon) in this) {
val vFile = localFileSystem.findFileByPath(sourceRootPath) val sourceRoot = File(sourceRootPath)
val vFile = localFileSystem.findFileByPath(sourceRoot.normalize().path)
if (vFile == null) { if (vFile == null) {
val message = "Source file or directory not found: $sourceRootPath" val message = "Source file or directory not found: $sourceRootPath"
@@ -63,10 +64,10 @@ inline fun List<KotlinSourceRoot>.forAllFiles(
continue continue
} }
for (file in File(sourceRootPath).walkTopDown()) { for (file in sourceRoot.walkTopDown()) {
if (!file.isFile) continue if (!file.isFile) continue
val virtualFile = localFileSystem.findFileByPath(file.absolutePath)?.let(virtualFileCreator::create) val virtualFile = localFileSystem.findFileByPath(file.absoluteFile.normalize().path)?.let(virtualFileCreator::create)
if (virtualFile != null && processedFiles.add(virtualFile)) { if (virtualFile != null && processedFiles.add(virtualFile)) {
body(virtualFile, isCommon) body(virtualFile, isCommon)
} }
@@ -0,0 +1,4 @@
$TESTDATA_DIR$/simple.kt
$TESTDATA_DIR$/./simple.kt
-d
$TEMP_DIR$
@@ -0,0 +1 @@
OK
@@ -264,6 +264,11 @@ public class CliTestGenerated extends AbstractCliTest {
runTest("compiler/testData/cli/jvm/duplicateSourcesInModule.args"); runTest("compiler/testData/cli/jvm/duplicateSourcesInModule.args");
} }
@TestMetadata("duplicateSourcesNormalized.args")
public void testDuplicateSourcesNormalized() throws Exception {
runTest("compiler/testData/cli/jvm/duplicateSourcesNormalized.args");
}
@TestMetadata("emptySources.args") @TestMetadata("emptySources.args")
public void testEmptySources() throws Exception { public void testEmptySources() throws Exception {
runTest("compiler/testData/cli/jvm/emptySources.args"); runTest("compiler/testData/cli/jvm/emptySources.args");