Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update XCSharedData Writable conformance to include WorkspaceSettings #743

Merged
merged 2 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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