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 @@ -58,28 +58,35 @@ struct PBXFrameworksBuildPhaseMapper: PBXFrameworksBuildPhaseMapping {
)
}
let fileRef = try buildFile.file.throwing(PBXFrameworksBuildPhaseMappingError.missingFileReference)
switch fileRef.sourceTree {
case .buildProductsDir:
guard let path = fileRef.path else { break }
if let path = fileRef.path {
let name = path.replacingOccurrences(of: ".framework", with: "")
let linkingStatus: LinkingStatus = (buildFile.settings?["ATTRIBUTES"] as? [String])?
.contains("Weak") == true ? .optional : .required
if let target = xcodeProj.pbxproj.targets(named: name).first {
return .target(
name: target.name,
status: linkingStatus,
condition: nil
)
} else if let projectNativeTarget = projectNativeTargets[name] {
return .project(
target: projectNativeTarget.nativeTarget.name,
path: projectNativeTarget.project.projectPath.parentDirectory,
switch fileRef.sourceTree {
case .buildProductsDir:
if let target = xcodeProj.pbxproj.targets(named: name).first {
return .target(
name: target.name,
status: linkingStatus,
condition: nil
)
} else if let projectNativeTarget = projectNativeTargets[name] {
return .project(
target: projectNativeTarget.nativeTarget.name,
path: projectNativeTarget.project.projectPath.parentDirectory,
status: linkingStatus,
condition: nil
)
}
case .sdkRoot, .developerDir:
return .sdk(
name: name,
status: linkingStatus,
condition: nil
)
default:
break
}
default:
break
}
let filePathString = try fileRef.fullPath(sourceRoot: xcodeProj.srcPathString)
.throwing(PBXFrameworksBuildPhaseMappingError.missingFilePath(name: fileRef.name))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,63 @@ struct PBXFrameworksBuildPhaseMapperTests {
]
)
}

@Test("Maps SDK frameworks")
func testMapSDKFrameworks() async throws {
// Given
let xcodeProj = try await XcodeProj.test()
let pbxProj = xcodeProj.pbxproj

let accessibilityFrameworkRef = PBXFileReference(
sourceTree: .sdkRoot,
path: "Accessibility.framework"
)
let accessibilityFrameworkBuildFile = PBXBuildFile(file: accessibilityFrameworkRef).add(to: pbxProj)

let foundationFrameworkRef = PBXFileReference(
sourceTree: .developerDir,
path: "Foundation.framework"
)
let foundationFrameworkBuildFile = PBXBuildFile(file: foundationFrameworkRef).add(to: pbxProj)

let frameworksPhase = PBXFrameworksBuildPhase(
files: [
accessibilityFrameworkBuildFile,
foundationFrameworkBuildFile,
]
).add(to: pbxProj)

try PBXNativeTarget(
name: "App",
buildPhases: [frameworksPhase],
productType: .application
)
.add(to: pbxProj)
.add(to: pbxProj.rootObject)

let mapper = PBXFrameworksBuildPhaseMapper()

// When
let frameworks = try mapper.map(
frameworksPhase,
xcodeProj: xcodeProj,
projectNativeTargets: [:]
)

// Then
#expect(
frameworks.sorted(by: { $0.name < $1.name }) == [
.sdk(
name: "Accessibility",
status: .required,
condition: nil
),
.sdk(
name: "Foundation",
status: .required,
condition: nil
),
]
)
}
}