Skip to content

Commit d478725

Browse files
authored
[6.0] Write output-file-map.json atomically (#7415)
* **Explanation**: When using sourcekit-lsp with VS Code it often happens that sourcekitd is trying to read the `output-file-map.json` while SwiftPM is writing it non-atomically. This results in a buffer in sourcekitd that is not null-terminated. To fix this issue, generate the output file map atomically. * **Scope**: Generation of `output-file-map.json` * **Risk**: This could fail if the `FileSystem` subclass in SwiftPM does not support atomic write operations. But I think we only really care about the local file system here, which does support atomic operations * **Testing**: Tests continue passing. I will verify that this fixes the sourcekitd crashes when a new toolchain is released with the fix * **Issue**: rdar://124727242 * **Reviewer**: @MaxDesiatov on #7406
1 parent 3b8489a commit d478725

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,8 @@ package final class SwiftTargetBuildDescription {
779779

780780
content += "}\n"
781781

782-
try self.fileSystem.writeFileContents(path, string: content)
782+
try fileSystem.createDirectory(path.parentDirectory, recursive: true)
783+
try self.fileSystem.writeFileContents(path, bytes: .init(encodingAsUTF8: content), atomically: true)
783784
return path
784785
}
785786

0 commit comments

Comments
 (0)