Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Sources/XcodeProj/Workspace/XCWorkspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ public final class XCWorkspace: Writable, Equatable {
public func write(path: Path, override: Bool = true) throws {
let dataPath = path + "contents.xcworkspacedata"
if override, dataPath.exists {
if let existingContent: String = try? dataPath.read(),
Comment thread
fortmarek marked this conversation as resolved.
existingContent == data.rawContents() {
// Raw data matches what's on disk
// there's no need to overwrite the contents
// this mitigates Xcode forcing users to
// close and re-open projects/workspaces
// on regneration.
Comment thread
ferologics marked this conversation as resolved.
Outdated
return
}
try dataPath.delete()
}
try dataPath.mkpath()
Expand Down
14 changes: 9 additions & 5 deletions Sources/XcodeProj/Workspace/XCWorkspaceData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,24 @@ extension XCWorkspaceData: Writable {

self.init(children: children)
}

// MARK: - <Writable>

public func write(path: Path, override: Bool = true) throws {

func rawContents() -> String {
let document = AEXMLDocument()
let workspace = document.addChild(name: "Workspace", value: nil, attributes: ["version": "1.0"])
_ = children
.map { $0.xmlElement() }
.map(workspace.addChild)
return document.xmlXcodeFormat
}

// MARK: - <Writable>

public func write(path: Path, override: Bool = true) throws {
let rawXml = rawContents()
if override, path.exists {
try path.delete()
}
try path.write(document.xmlXcodeFormat)
try path.write(rawXml)
}
}

Expand Down