Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8cc4c8f

Browse files
committedApr 3, 2024
Fix that generated swift files could override each other due to case insensitive file system.
1 parent 03bed4e commit 8cc4c8f

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed
 

‎SKIE/acceptance-tests

‎SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/sir/SirFileProvider.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import co.touchlab.skie.util.cache.writeTextIfDifferent
99
import co.touchlab.skie.util.directory.SkieBuildDirectory
1010
import java.nio.file.Path
1111
import kotlin.io.path.absolute
12+
import kotlin.io.path.absolutePathString
1213
import kotlin.io.path.extension
1314

1415
class SirFileProvider(
@@ -17,33 +18,33 @@ class SirFileProvider(
1718
private val skieBuildDirectory: SkieBuildDirectory,
1819
) {
1920

20-
private val irFileByPathCache = mutableMapOf<Path, SirIrFile>()
21+
private val irFileByPathCache = mutableMapOf<String, SirIrFile>()
2122

22-
private val writtenSourceFileByPathCache = mutableMapOf<Path, SirSourceFile>()
23+
private val writtenSourceFileByPathCache = mutableMapOf<String, SirSourceFile>()
2324

24-
private val generatedSourceFileByPathCache = mutableMapOf<Path, SirSourceFile>()
25+
private val generatedSourceFileByPathCache = mutableMapOf<String, SirSourceFile>()
2526

2627
private val skieNamespace: String
2728
get() = kirProvider.skieModule.name
2829

2930
fun getWrittenSourceFileFromSkieNamespace(name: String): SirSourceFile {
3031
val path = relativePath(skieNamespace, name)
3132

32-
check(path !in generatedSourceFileByPathCache) {
33+
check(path.asCacheKey !in generatedSourceFileByPathCache) {
3334
"Generated source file for $path already exists. Combining written and generated source files is not supported."
3435
}
3536

36-
return writtenSourceFileByPathCache.getOrPut(path) {
37+
return writtenSourceFileByPathCache.getOrPut(path.asCacheKey) {
3738
SirSourceFile(skieModule, path)
3839
}
3940
}
4041

4142
fun getGeneratedSourceFile(irFile: SirIrFile): SirSourceFile {
42-
check(irFile.relativePath !in writtenSourceFileByPathCache) {
43+
check(irFile.relativePath.asCacheKey !in writtenSourceFileByPathCache) {
4344
"Written source file for ${irFile.relativePath} already exists. Combining written and generated source files is not supported."
4445
}
4546

46-
return generatedSourceFileByPathCache.getOrPut(irFile.relativePath) {
47+
return generatedSourceFileByPathCache.getOrPut(irFile.relativePath.asCacheKey) {
4748
SirSourceFile(irFile.module, irFile.relativePath, irFile)
4849
}
4950
}
@@ -52,7 +53,7 @@ class SirFileProvider(
5253
getIrFile(skieNamespace, name)
5354

5455
fun getIrFile(namespace: String, name: String): SirIrFile =
55-
irFileByPathCache.getOrPut(relativePath(namespace, name)) {
56+
irFileByPathCache.getOrPut(relativePath(namespace, name).asCacheKey) {
5657
SirIrFile(namespace, name, skieModule)
5758
}
5859

@@ -84,6 +85,9 @@ class SirFileProvider(
8485
return SirCompilableFile(skieModule, absolutePath, null)
8586
}
8687

88+
private val Path.asCacheKey: String
89+
get() = this.normalize().absolutePathString().lowercase()
90+
8791
companion object {
8892

8993
fun relativePath(namespace: String, name: String): Path =

0 commit comments

Comments
 (0)
Please sign in to comment.