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

feat: add path to XcodeProj and XCWorkspace #892

Merged
merged 2 commits into from
Dec 21, 2024
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
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
}
}
Loading