Skip to content

Commit 94cbd45

Browse files
Workspace,Build: reduce mtime updates (#6655)
When building a project inside of VSCode with the LSP enabled, rebuilding the project would trigger a change to the mtimes of the auxiliary files resulting in an unnecessary rebuilding of targets. In conjunction with the changes to tools-support-core (swiftlang/swift-tools-support-core#422), incremental builds do not trigger a cascade of rebuilds that are unnecessary. Extracted from a patch by Ami Fischman! Co-authored-by: Ami Fischman <[email protected]>
1 parent 56096f1 commit 94cbd45

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

Sources/Basics/FileSystem/FileSystem+Extensions.swift

+4
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,10 @@ extension FileSystem {
526526
try writeIfChanged(path: path, bytes: .init(encodingAsUTF8: string))
527527
}
528528

529+
public func writeIfChanged(path: AbsolutePath, data: Data) throws {
530+
try writeIfChanged(path: path, bytes: .init(data))
531+
}
532+
529533
/// Write bytes to the path if the given contents are different.
530534
public func writeIfChanged(path: AbsolutePath, bytes: ByteString) throws {
531535
try createDirectory(path.parentDirectory, recursive: true)

Sources/Build/BuildOperationBuildSystemDelegateHandler.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ final class WriteAuxiliaryFileCommand: CustomLLBuildCommand {
517517
}
518518

519519
do {
520-
try self.context.fileSystem.writeFileContents(outputFilePath, string: getFileContents(tool: tool))
520+
try self.context.fileSystem.writeIfChanged(path: outputFilePath, string: getFileContents(tool: tool))
521521
return true
522522
} catch {
523523
self.context.observabilityScope.emit(error: "failed to write auxiliary file '\(outputFilePath.pathString)': \(error.interpolationDescription)")

Sources/Workspace/Workspace+State.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ fileprivate struct WorkspaceStateStorage {
135135
let storage = V6(dependencies: dependencies, artifacts: artifacts)
136136

137137
let data = try self.encoder.encode(storage)
138-
try self.fileSystem.writeFileContents(self.path, data: data)
138+
try self.fileSystem.writeIfChanged(path: self.path, data: data)
139139
}
140140
}
141141

0 commit comments

Comments
 (0)