From 96c691b84d6721043049364e54e31196fd1111b8 Mon Sep 17 00:00:00 2001 From: Krzysztof Rodak Date: Mon, 16 Feb 2026 13:31:37 +0100 Subject: [PATCH] BridgeJS: Skip writing output files when content is unchanged --- .../Sources/BridgeJSTool/BridgeJSTool.swift | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSTool/BridgeJSTool.swift b/Plugins/BridgeJS/Sources/BridgeJSTool/BridgeJSTool.swift index 3b784b732..2f742318b 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSTool/BridgeJSTool.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSTool/BridgeJSTool.swift @@ -225,7 +225,7 @@ import BridgeJSUtilities withIntermediateDirectories: true, attributes: nil ) - try outputSwift.write(to: outputSwiftURL, atomically: true, encoding: .utf8) + try writeIfChanged(outputSwift, to: outputSwiftURL) } } @@ -240,7 +240,7 @@ import BridgeJSUtilities let encoder = JSONEncoder() encoder.outputFormatting = [.prettyPrinted, .sortedKeys] let skeletonData = try encoder.encode(skeleton) - try skeletonData.write(to: outputSkeletonURL) + try writeIfChanged(skeletonData, to: outputSkeletonURL) } if skeleton.exported != nil || skeleton.imported != nil { @@ -282,6 +282,18 @@ private func hasBridgeJSSkipComment(_ content: String) -> Bool { BridgeJSGeneratedFile.hasSkipComment(content) } +private func writeIfChanged(_ content: String, to url: URL) throws { + let existing = try? String(contentsOf: url, encoding: .utf8) + guard existing != content else { return } + try content.write(to: url, atomically: true, encoding: .utf8) +} + +private func writeIfChanged(_ data: Data, to url: URL) throws { + let existing = try? Data(contentsOf: url) + guard existing != data else { return } + try data.write(to: url) +} + private func combineGeneratedSwift(_ pieces: [String]) -> String { let trimmedPieces = pieces