Skip to content

Commit

Permalink
feat: add path to XcodeProj and XCWorkspace (#892)
Browse files Browse the repository at this point in the history
* feat: add optional projectPath to XcodeProj

* PR comments + Workspace path
  • Loading branch information
ajkolean authored Dec 21, 2024
1 parent 0500afc commit 2f6a810
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
11 changes: 9 additions & 2 deletions Sources/XcodeProj/Project/XcodeProj.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ public final class XcodeProj: Equatable {
/// Project workspace
public var workspace: XCWorkspace

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

/// .pbxproj representation
public var pbxproj: PBXProj

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

self.path = path
self.pbxproj = pbxproj
self.workspace = workspace
self.sharedData = sharedData
Expand All @@ -63,11 +67,13 @@ public final class XcodeProj: Equatable {
public init(workspace: XCWorkspace,
pbxproj: PBXProj,
sharedData: XCSharedData? = nil,
userData: [XCUserData] = []) {
userData: [XCUserData] = [],
path: Path? = nil) {
self.workspace = workspace
self.pbxproj = pbxproj
self.sharedData = sharedData
self.userData = userData
self.path = path
}

// MARK: - Equatable
Expand All @@ -76,7 +82,8 @@ public final class XcodeProj: Equatable {
lhs.workspace == rhs.workspace &&
lhs.pbxproj == rhs.pbxproj &&
lhs.sharedData == rhs.sharedData &&
lhs.userData == rhs.userData
lhs.userData == rhs.userData &&
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 2f6a810

Please sign in to comment.