Skip to content

Commit

Permalink
Workspace,Build: reduce mtime updates (#6655)
Browse files Browse the repository at this point in the history
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 <ami@thebrowser.company>
  • Loading branch information
compnerd and fischman-bcny committed Jun 15, 2023
1 parent 56096f1 commit 94cbd45
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Sources/Basics/FileSystem/FileSystem+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,10 @@ extension FileSystem {
try writeIfChanged(path: path, bytes: .init(encodingAsUTF8: string))
}

public func writeIfChanged(path: AbsolutePath, data: Data) throws {
try writeIfChanged(path: path, bytes: .init(data))
}

/// Write bytes to the path if the given contents are different.
public func writeIfChanged(path: AbsolutePath, bytes: ByteString) throws {
try createDirectory(path.parentDirectory, recursive: true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ final class WriteAuxiliaryFileCommand: CustomLLBuildCommand {
}

do {
try self.context.fileSystem.writeFileContents(outputFilePath, string: getFileContents(tool: tool))
try self.context.fileSystem.writeIfChanged(path: outputFilePath, string: getFileContents(tool: tool))
return true
} catch {
self.context.observabilityScope.emit(error: "failed to write auxiliary file '\(outputFilePath.pathString)': \(error.interpolationDescription)")
Expand Down
2 changes: 1 addition & 1 deletion Sources/Workspace/Workspace+State.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fileprivate struct WorkspaceStateStorage {
let storage = V6(dependencies: dependencies, artifacts: artifacts)

let data = try self.encoder.encode(storage)
try self.fileSystem.writeFileContents(self.path, data: data)
try self.fileSystem.writeIfChanged(path: self.path, data: data)
}
}

Expand Down

0 comments on commit 94cbd45

Please sign in to comment.