Merge pull request #217 from allu22/duplicate-source-ref

Filter out duplicate file references from sources build phase
This commit is contained in:
Yonas Kolb 2018-01-03 19:16:04 +08:00 committed by GitHub
commit 2338b47d84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View File

@ -408,6 +408,11 @@ public class PBXProjGenerator {
func getBuildFilesForPhase(_ buildPhase: BuildPhase) -> [String] {
let files = sourceFiles
.filter { $0.buildPhase == buildPhase }
.reduce(into: [SourceFile]()) { (output, sourceFile) in
if !output.contains(where: { $0.fileReference == sourceFile.fileReference }) {
output.append(sourceFile)
}
}
.sorted { $0.path.lastComponent < $1.path.lastComponent }
files.forEach { addObject($0.buildFile) }
return files.map { $0.buildFile.reference }

View File

@ -744,6 +744,31 @@ func projectGeneratorTests() {
try project.expectFile(paths: ["C", "file.123"], buildPhase: .resources)
try project.expectFile(paths: ["C", "Info.plist"], buildPhase: .none)
}
$0.it("duplicate TargetSource is included once in sources build phase") {
let directories = """
Sources:
A:
- a.swift
"""
try createDirectories(directories)
let target = Target(name: "Test", type: .application, platform: .iOS, sources: [
"Sources/A/a.swift",
"Sources/A/a.swift",
])
let spec = ProjectSpec(basePath: directoryPath, name: "Test", targets: [target])
let project = try getPbxProj(spec)
try project.expectFile(paths: ["Sources/A", "a.swift"], names: ["A", "a.swift"], buildPhase: .sources)
let sourcesBuildPhase = project.objects.buildPhases
.first(where: { $0.1.buildPhase == BuildPhase.sources })!
.value
try expect(sourcesBuildPhase.files.count) == 1
}
}
}
}