Skip to content

Commit

Permalink
Merge pull request #753 from abertelrud/SR-3001
Browse files Browse the repository at this point in the history
SR-3001: Generated Xcode project has an incorrect linkage on an executable
  • Loading branch information
abertelrud committed Oct 20, 2016
2 parents 4e67545 + 994dd6f commit 62bad76
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Sources/Xcodeproj/pbxproj().swift
Expand Up @@ -419,7 +419,11 @@ func xcodeProject(

// Add a dependency on the other target.
target.addDependency(on: otherTarget)
let _ = linkPhase.addBuildFile(fileRef: otherTarget.productReference!)

// If it's a library, we also add want to link against its product.
if dependency.isLibrary {
let _ = linkPhase.addBuildFile(fileRef: otherTarget.productReference!)
}
}
}

Expand Down
46 changes: 46 additions & 0 deletions Tests/XcodeprojTests/PackageGraphTests.swift
Expand Up @@ -104,8 +104,51 @@ class PackageGraphTests: XCTestCase {
}
}

func testModuleLinkage() throws {
let fs = InMemoryFileSystem(emptyFiles:
"/Pkg/Sources/HelperTool/main.swift",
"/Pkg/Sources/Library/lib.swift",
"/Pkg/Tests/LibraryTests/aTest.swift"
)

let g = try loadMockPackageGraph([
"/Pkg": Package(name: "Pkg", targets: [Target(name: "LibraryTests", dependencies: ["Library", "HelperTool"])]),
], root: "/Pkg", in: fs)

let project = try xcodeProject(xcodeprojPath: AbsolutePath.root.appending(component: "xcodeproj"), graph: g, extraDirs: [], options: XcodeprojOptions(), fileSystem: fs)

XcodeProjectTester(project) { result in
result.check(projectDir: "Pkg")
result.check(target: "HelperTool") { targetResult in
targetResult.check(productType: .executable)
targetResult.check(dependencies: [])
let linkPhases = targetResult.buildPhases.filter{ $0 is Xcode.FrameworksBuildPhase }
XCTAssertEqual(linkPhases.count, 1)
let linkedFiles = linkPhases.first!.files.map{ $0.fileRef!.path }
XCTAssertEqual(linkedFiles, [])
}
result.check(target: "Library") { targetResult in
targetResult.check(productType: .framework)
targetResult.check(dependencies: [])
let linkPhases = targetResult.buildPhases.filter{ $0 is Xcode.FrameworksBuildPhase }
XCTAssertEqual(linkPhases.count, 1)
let linkedFiles = linkPhases.first!.files.map{ $0.fileRef!.path }
XCTAssertEqual(linkedFiles, [])
}
result.check(target: "LibraryTests") { targetResult in
targetResult.check(productType: .unitTest)
targetResult.check(dependencies: ["Library", "HelperTool"])
let linkPhases = targetResult.buildPhases.filter{ $0 is Xcode.FrameworksBuildPhase }
XCTAssertEqual(linkPhases.count, 1)
let linkedFiles = linkPhases.first!.files.map{ $0.fileRef!.path }
XCTAssertEqual(linkedFiles, ["Library.framework"])
}
}
}

static var allTests = [
("testBasics", testBasics),
("testModuleLinkage", testModuleLinkage),
]
}

Expand Down Expand Up @@ -142,6 +185,9 @@ private class XcodeProjectResult {
var commonBuildSettings: Xcode.BuildSettingsTable.BuildSettings {
return target.buildSettings.common
}
var buildPhases: [Xcode.BuildPhase] {
return target.buildPhases
}
init(_ target: Xcode.Target) {
self.target = target
}
Expand Down

0 comments on commit 62bad76

Please sign in to comment.