Skip to content

Commit a54c627

Browse files
committed
[Xcodeproj] Use FileSystem to access file data.
1 parent 4510ca2 commit a54c627

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

Sources/Xcodeproj/generate().swift

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -118,27 +118,23 @@ public func generate(dstdir: AbsolutePath, projectName: String, graph: PackageGr
118118
return xcodeprojPath
119119
}
120120

121-
import class Foundation.NSData
122-
123121
/// Writes the contents to the file specified.
124-
/// Doesn't re-writes the file in case the new and old contents of file are same.
122+
///
123+
/// This method doesn't rewrite the file in case the new and old contents of
124+
/// file are same.
125125
func open(_ path: AbsolutePath, body: ((String) -> Void) throws -> Void) throws {
126126
let stream = OutputByteStream()
127127
try body { line in
128128
stream <<< line
129129
stream <<< "\n"
130130
}
131-
// If file is already present compare its content with our stream
132-
// and re-write only if its new.
133-
if path.asString.isFile, let data = NSData(contentsOfFile: path.asString) {
134-
// FIXME: We should have a utility for this.
135-
var contents = [UInt8](repeating: 0, count: data.length / sizeof(UInt8.self))
136-
data.getBytes(&contents, length: data.length)
137-
// If contents are same then no need to re-write.
138-
if contents == stream.bytes.contents {
139-
return
140-
}
131+
// If the file exists with the identical contents, we don't need to rewrite it.
132+
//
133+
// This avoids unnecessarily triggering Xcode reloads of the project file.
134+
if let contents = try? localFileSystem.readFileContents(path), contents == stream.bytes {
135+
return
141136
}
137+
142138
// Write the real file.
143139
try localFileSystem.writeFileContents(path, bytes: stream.bytes)
144140
}

0 commit comments

Comments
 (0)