Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,10 @@ public struct XcodeGraphMapper: XcodeGraphMapping {
}
let projectNativeTargets: [String: ProjectNativeTarget] = xcodeProjects.reduce(into: [:]) { acc, xcodeProject in
for nativeTarget in xcodeProject.pbxproj.nativeTargets {
acc[nativeTarget.name] = ProjectNativeTarget(
let name = Target.sanitizedProductNameFrom(
targetName: nativeTarget.name
)
acc[name] = ProjectNativeTarget(
nativeTarget: nativeTarget,
project: xcodeProject
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import XcodeProj

/// Model representing a `PBXNativeTarget` in a give `XcodeProj`
struct ProjectNativeTarget {
struct ProjectNativeTarget: Equatable {
let nativeTarget: PBXNativeTarget
let project: XcodeProj
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,56 @@ struct XcodeGraphMapperTests {
#expect(graph.workspace.name == "Workspace")
}

@Test("Maps a project with sanitizable target names")
func testProjectWithSanitizableTargetNames() async throws {
// Given
let pbxProj = PBXProj()

let xcodeProj = try await XcodeProj.test(
projectName: "SingleProject",
pbxProj: pbxProj
)

let projectMapper = MockPBXProjectMapping()
given(projectMapper)
.map(
xcodeProj: .any,
projectNativeTargets: .any
)
.willReturn(
.test()
)

// Add a single target to the project
try PBXNativeTarget.test(
name: "App-With-Dash",
productType: .application
)
.add(to: pbxProj)
.add(to: pbxProj.rootObject)

try xcodeProj.write(path: xcodeProj.path!)
let mapper = XcodeGraphMapper(
projectMapper: projectMapper
)
// When
_ = try await mapper.buildGraph(from: .project(xcodeProj))

// Then
verify(projectMapper)
.map(
xcodeProj: .any,
projectNativeTargets: .matching(
{
$0.keys.map { $0 } == [
"App_With_Dash",
]
}
)
)
.called(1)
}

@Test("Maps a workspace with multiple projects into a single graph")
func testWorkspaceGraphMultipleProjects() async throws {
// Given
Expand Down Expand Up @@ -359,10 +409,5 @@ struct XcodeGraphMapperTests {
],
]
)
// // Verify dependencies are mapped
// let targetDep = GraphDependency.target(name: "AFramework", path: xcodeProj.srcPath)
// let expectedDependency = try #require(graph.dependencies.first?.value)

// #expect(expectedDependency == [targetDep])
}
}