From fc9bb5f4e0bb4f258e4c21a9bf3eb90a3405156f Mon Sep 17 00:00:00 2001 From: Alvar Hansen Date: Wed, 3 Jan 2018 11:58:42 +0200 Subject: [PATCH] Filter out duplicate file references from sources build phase --- Sources/XcodeGenKit/PBXProjGenerator.swift | 5 ++++ .../ProjectGeneratorTests.swift | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/Sources/XcodeGenKit/PBXProjGenerator.swift b/Sources/XcodeGenKit/PBXProjGenerator.swift index cdf7071b..cfdb4244 100644 --- a/Sources/XcodeGenKit/PBXProjGenerator.swift +++ b/Sources/XcodeGenKit/PBXProjGenerator.swift @@ -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 } diff --git a/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift b/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift index 8632de58..3d24ecf9 100644 --- a/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift +++ b/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift @@ -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 + } } } }