Added new group parameter to target sources, allowing to add them to a custom parent group (resolving #478)

This commit is contained in:
Steven Roebert
2019-11-19 15:56:23 -05:00
committed by Romuald CARI
parent 538d1c6804
commit 15e615300e
4 changed files with 134 additions and 27 deletions
@@ -469,6 +469,38 @@ class SourceGeneratorTests: XCTestCase {
try pbxProj.expectFile(paths: ["../OtherDirectory/C/D", "e.swift"], names: ["D", "e.swift"], buildPhase: .sources)
try pbxProj.expectFile(paths: ["Sources/B", "b.swift"], names: ["B", "b.swift"], buildPhase: .sources)
}
$0.it("generates custom groups") {
let directories = """
Sources:
A:
- b.swift
F:
- G:
- h.swift
B:
- b.swift
- C:
- c.swift
"""
try createDirectories(directories)
let target = Target(name: "Test", type: .application, platform: .iOS, sources: [
TargetSource(path: "Sources/A/b.swift", group: "CustomGroup1"),
TargetSource(path: "Sources/F/G/h.swift", group: "CustomGroup1"),
TargetSource(path: "Sources/B", group: "CustomGroup2", createIntermediateGroups: false),
])
let options = SpecOptions(createIntermediateGroups: true)
let project = Project(basePath: directoryPath, name: "Test", targets: [target], options: options)
let pbxProj = try project.generatePbxProj()
try pbxProj.expectFile(paths: ["CustomGroup1", "Sources/A", "b.swift"], names: ["CustomGroup1", "A", "b.swift"], buildPhase: .sources)
try pbxProj.expectFile(paths: ["CustomGroup1", "Sources/F/G", "h.swift"], names: ["CustomGroup1", "G", "h.swift"], buildPhase: .sources)
try pbxProj.expectFile(paths: ["CustomGroup2", "Sources/B", "b.swift"], names: ["CustomGroup2", "B", "b.swift"], buildPhase: .sources)
try pbxProj.expectFile(paths: ["CustomGroup2", "Sources/B", "C", "c.swift"], names: ["CustomGroup2", "B", "C", "c.swift"], buildPhase: .sources)
}
$0.it("generates folder references") {
let directories = """
@@ -953,18 +985,24 @@ extension PBXProj {
}
private func getFileReference(group: PBXGroup, paths: [String], names: [String]) -> PBXFileReference? {
guard !paths.isEmpty else { return nil }
guard !paths.isEmpty else {
return nil
}
let path = paths.first!
let name = names.first!
let restOfPath = Array(paths.dropFirst())
let restOfName = Array(names.dropFirst())
if restOfPath.isEmpty {
let fileReferences: [PBXFileReference] = group.children.compactMap { $0 as? PBXFileReference }
return fileReferences.first { $0.path == path && $0.nameOrPath == name }
fileReferences.forEach { print("path: \($0.path ?? "nil"), name: \($0.name ?? "nil")") }
return fileReferences.first { ($0.path == nil || $0.path == path) && $0.nameOrPath == name }
} else {
let groups = group.children.compactMap { $0 as? PBXGroup }
guard let group = groups.first(where: { $0.path == path && $0.nameOrPath == name }) else { return nil }
groups.forEach { print("path: \($0.path ?? "nil"), name: \($0.name ?? "nil")") }
guard let group = groups.first(where: { ($0.path == nil || $0.path == path) && $0.nameOrPath == name }) else {
return nil
}
return getFileReference(group: group, paths: restOfPath, names: restOfName)
}
}