Skip to content

Commit

Permalink
Add resolveGroupPath
Browse files Browse the repository at this point in the history
  • Loading branch information
giginet committed Oct 15, 2019
1 parent 62a26b0 commit e63fe6b
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions Sources/XcodeGenKit/SourceGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ class SourceGenerator {
self.pbxProj = pbxProj
self.projectDirectory = projectDirectory
}

private func resolveGroupPath(_ path: Path, isTopLevelGroup: Bool) -> String {
if isTopLevelGroup, let relativePath = try? path.relativePath(from: projectDirectory ?? project.basePath).string {
return relativePath
} else {
return path.lastComponent
}
}

@discardableResult
func addObject<T: PBXObject>(_ object: T, context: String? = nil) -> T {
Expand Down Expand Up @@ -288,13 +296,8 @@ class SourceGenerator {
let isTopLevelGroup = (isBaseGroup && !createIntermediateGroups) || isRootPath

let groupName = name ?? path.lastComponent
let groupPath: String
switch try? path.relativePath(from: projectDirectory ?? project.basePath).string {
case .some(let relativePath) where isTopLevelGroup:
groupPath = relativePath
default:
groupPath = path.lastComponent
}
let groupPath = resolveGroupPath(path, isTopLevelGroup: isTopLevelGroup)

let group = PBXGroup(
children: children,
sourceTree: .group,
Expand Down

0 comments on commit e63fe6b

Please sign in to comment.