Skip to content

Commit 96c691b

Browse files
committed
BridgeJS: Skip writing output files when content is unchanged
1 parent a98e49d commit 96c691b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Plugins/BridgeJS/Sources/BridgeJSTool/BridgeJSTool.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ import BridgeJSUtilities
225225
withIntermediateDirectories: true,
226226
attributes: nil
227227
)
228-
try outputSwift.write(to: outputSwiftURL, atomically: true, encoding: .utf8)
228+
try writeIfChanged(outputSwift, to: outputSwiftURL)
229229
}
230230
}
231231

@@ -240,7 +240,7 @@ import BridgeJSUtilities
240240
let encoder = JSONEncoder()
241241
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
242242
let skeletonData = try encoder.encode(skeleton)
243-
try skeletonData.write(to: outputSkeletonURL)
243+
try writeIfChanged(skeletonData, to: outputSkeletonURL)
244244
}
245245

246246
if skeleton.exported != nil || skeleton.imported != nil {
@@ -282,6 +282,18 @@ private func hasBridgeJSSkipComment(_ content: String) -> Bool {
282282
BridgeJSGeneratedFile.hasSkipComment(content)
283283
}
284284

285+
private func writeIfChanged(_ content: String, to url: URL) throws {
286+
let existing = try? String(contentsOf: url, encoding: .utf8)
287+
guard existing != content else { return }
288+
try content.write(to: url, atomically: true, encoding: .utf8)
289+
}
290+
291+
private func writeIfChanged(_ data: Data, to url: URL) throws {
292+
let existing = try? Data(contentsOf: url)
293+
guard existing != data else { return }
294+
try data.write(to: url)
295+
}
296+
285297
private func combineGeneratedSwift(_ pieces: [String]) -> String {
286298
let trimmedPieces =
287299
pieces

0 commit comments

Comments
 (0)