Skip to content

Commit

Permalink
Update XCSharedData Writable conformance to include WorkspaceSettings (
Browse files Browse the repository at this point in the history
…#743)

Resolves #738

### Short description 📝
- Update `XCSharedData` `Writable` conformance so that `WorkspaceSettings` are written.

### Solution 📦

- There was already a pattern defined for writing `XCSharedData` properties (`schemes` and `breakpoints`), and so I followed the same pattern to write the `workspaceSettings` property.
  • Loading branch information
dayton-bobbitt authored Mar 6, 2023
1 parent 0008426 commit 1c8daed
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Sources/XcodeProj/Project/WorkspaceSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,9 @@ public class WorkspaceSettings: Codable, Equatable, Writable {
try path.write(data)
}
}

extension WorkspaceSettings {
static func path(_ path: Path) -> Path {
path + "WorkspaceSettings.xcsettings"
}
}
15 changes: 15 additions & 0 deletions Sources/XcodeProj/Project/XCSharedData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public final class XCSharedData: Equatable, Writable {
public func write(path: Path, override: Bool) throws {
try writeSchemes(path: path, override: override)
try writeBreakpoints(path: path, override: override)
try writeWorkspaceSettings(path: path, override: override)
}

func writeSchemes(path: Path, override: Bool) throws {
Expand Down Expand Up @@ -91,6 +92,20 @@ public final class XCSharedData: Equatable, Writable {
try debuggerPath.mkpath()
try breakpoints.write(path: XCBreakpointList.path(debuggerPath), override: override)
}

func writeWorkspaceSettings(path: Path, override: Bool) throws {
/**
* We don't want to delete this path when `override` is `true` because
* that will delete everything in the folder, including schemes and breakpoints.
* Instead, just create the path if it doesn't exist and let the `write` method
* in `WorkspaceSettings` handle the override.
*/
if !path.exists {
try path.mkpath()
}

try workspaceSettings?.write(path: WorkspaceSettings.path(path), override: override)
}
}

extension XCSharedData {
Expand Down
19 changes: 19 additions & 0 deletions Tests/XcodeProjTests/Project/XcodeProjTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ final class XcodeProjIntegrationTests: XCTestCase {
try testReadWriteProducesNoDiff(from: iosProjectPath,
initModel: XcodeProj.init(path:))
}

func test_write_includes_workspace_settings() throws {
// Define workspace settings that should be written
let workspaceSettings = WorkspaceSettings(buildSystem: .new, derivedDataLocationStyle: .default, autoCreateSchemes: false)

testWrite(from: iosProjectPath,
initModel: { try? XcodeProj(path: $0) },
modify: { project in
project.sharedData?.workspaceSettings = workspaceSettings
return project
},
assertion: {
/**
* Expect that the workspace settings read from file are equal to the
* workspace settings we expected to write.
*/
XCTAssertEqual($1.sharedData?.workspaceSettings, workspaceSettings)
})
}

// MARK: - Private

Expand Down

0 comments on commit 1c8daed

Please sign in to comment.