Skip to content

Commit

Permalink
PR comments + Workspace path
Browse files Browse the repository at this point in the history
  • Loading branch information
ajkolean committed Dec 20, 2024
1 parent b9c3e13 commit 8217e48
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
12 changes: 6 additions & 6 deletions Sources/XcodeProj/Project/XcodeProj.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public final class XcodeProj: Equatable {
/// Project workspace
public var workspace: XCWorkspace

/// The path to the `.xcodeproj` directory.
private let projectPath: Path?
/// The path to the `.xcodeproj` directory.
public let path: Path?

/// .pbxproj representation
public var pbxproj: PBXProj
Expand Down Expand Up @@ -46,7 +46,7 @@ public final class XcodeProj: Equatable {
.glob("*.xcuserdatad")
.compactMap { try? XCUserData(path: $0) }

projectPath = path
self.path = path
self.pbxproj = pbxproj
self.workspace = workspace
self.sharedData = sharedData
Expand All @@ -68,12 +68,12 @@ public final class XcodeProj: Equatable {
pbxproj: PBXProj,
sharedData: XCSharedData? = nil,
userData: [XCUserData] = [],
projectPath: Path? = nil) {
path: Path? = nil) {
self.workspace = workspace
self.pbxproj = pbxproj
self.sharedData = sharedData
self.userData = userData
self.projectPath = projectPath
self.path = path
}

// MARK: - Equatable
Expand All @@ -83,7 +83,7 @@ public final class XcodeProj: Equatable {
lhs.pbxproj == rhs.pbxproj &&
lhs.sharedData == rhs.sharedData &&
lhs.userData == rhs.userData &&
lhs.projectPath == rhs.projectPath
lhs.path == rhs.path
}
}

Expand Down
17 changes: 11 additions & 6 deletions Sources/XcodeProj/Workspace/XCWorkspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ public final class XCWorkspace: Writable, Equatable {
/// Workspace data
public var data: XCWorkspaceData

/// The path to the `.xcworkspace` directory.
public let path: Path?

// MARK: - Init

/// Initializes the workspace with the path where the workspace is.
Expand All @@ -15,14 +18,14 @@ public final class XCWorkspace: Writable, Equatable {
/// - Parameter path: .xcworkspace path.
/// - Throws: throws an error if the workspace cannot be initialized.
public convenience init(path: Path) throws {
if !path.exists {
guard path.exists else {
throw XCWorkspaceError.notFound(path: path)
}
let xcworkspaceDataPaths = path.glob("*.xcworkspacedata")
if xcworkspaceDataPaths.isEmpty {
self.init()
if let xcworkspaceDataPath = xcworkspaceDataPaths.first {
try self.init(data: XCWorkspaceData(path: xcworkspaceDataPath), path: path)
} else {
try self.init(data: XCWorkspaceData(path: xcworkspaceDataPaths.first!))
self.init()
}
}

Expand All @@ -44,8 +47,10 @@ public final class XCWorkspace: Writable, Equatable {
///
/// - Parameters:
/// - data: workspace data.
public init(data: XCWorkspaceData) {
/// - path: .xcworkspace path.
public init(data: XCWorkspaceData, path: Path? = nil) {
self.data = data
self.path = path
}

// MARK: - Writable
Expand Down Expand Up @@ -75,6 +80,6 @@ public final class XCWorkspace: Writable, Equatable {
// MARK: - Equatable

public static func == (lhs: XCWorkspace, rhs: XCWorkspace) -> Bool {
lhs.data == rhs.data
lhs.data == rhs.data && lhs.path == rhs.path
}
}

0 comments on commit 8217e48

Please sign in to comment.