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
10 changes: 5 additions & 5 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extension PBXTarget {
/// Retrieves the path to the Info.plist file from the target's build settings.
///
/// - Returns: The `INFOPLIST_FILE` value if present, otherwise `nil`.
func infoPlistPath() -> [BuildConfiguration: String] {
func infoPlistPaths() -> [BuildConfiguration: String] {
buildConfigurationList?.stringSettings(for: .infoPlistFile) ?? [:]
}

Expand Down
11 changes: 9 additions & 2 deletions Sources/XcodeGraphMapper/Mappers/Targets/PBXTargetMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,15 @@ struct PBXTargetMapper: PBXTargetMapping {

/// Extracts and parses the project's Info.plist as a dictionary, or returns an empty dictionary if none is found.
private func extractInfoPlist(from target: PBXTarget, xcodeProj: XcodeProj) async throws -> InfoPlist {
if let (config, plistPath) = target.infoPlistPath().first {
let path = xcodeProj.srcPath.appending(try RelativePath(validating: plistPath))
if let (config, plistPath) = target.infoPlistPaths().sorted(by: { $0.key.name > $1.key.name }).first {
let pathString = plistPath
.replacingOccurrences(of: "$(SRCROOT)", with: xcodeProj.srcPathString)
.replacingOccurrences(of: "$(PROJECT_DIR)", with: xcodeProj.projectPath.parentDirectory.pathString)
let path = if pathString.starts(with: "/") {
try AbsolutePath(validating: pathString)
} else {
xcodeProj.srcPath.appending(try RelativePath(validating: pathString))
}
let plistDictionary = try await readPlistAsDictionary(at: path)
return .dictionary(plistDictionary, configuration: config)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,97 @@ struct PBXTargetMapperTests: Sendable {
}() == true)
}

@Test("Parses a valid Info.plist referenced with a SRCROOT variable")
func testMapTarget_validPlist_referenced_with_SRCROOT() async throws {
// Given

let xcodeProj = try await XcodeProj.test()
let srcPath = xcodeProj.srcPath
let relativePath = try RelativePath(validating: "Info.plist")
let plistPath = srcPath.appending(relativePath)

let plistContent: [String: Any] = [
"CFBundleIdentifier": "com.example.app",
"CFBundleName": "ExampleApp",
"CFVersion": 1.4,
]
let data = try PropertyListSerialization.data(fromPropertyList: plistContent, format: .xml, options: 0)
try data.write(to: URL(fileURLWithPath: plistPath.pathString))

let target = createTarget(
name: "App",
xcodeProj: xcodeProj,
productType: .application,
buildSettings: [
"PRODUCT_BUNDLE_IDENTIFIER": "com.example.app",
"INFOPLIST_FILE": "$(SRCROOT)/\(relativePath.pathString)",
]
)

try xcodeProj.write(path: xcodeProj.path!)
let mapper = PBXTargetMapper()

// When
let mapped = try await mapper.map(pbxTarget: target, xcodeProj: xcodeProj)

// Then
#expect(
mapped.infoPlist == .dictionary(
[
"CFBundleIdentifier": "com.example.app",
"CFBundleName": "ExampleApp",
"CFVersion": 1.4,
],
configuration: .release("Release")
)
)
}

@Test("Parses a valid Info.plist referenced with a PROJECT_DIR variable")
func testMapTarget_validPlist_referenced_with_PROJECT_DIR() async throws {
// Given
let xcodeProj = try await XcodeProj.test()
let srcPath = xcodeProj.srcPath
let relativePath = try RelativePath(validating: "Info.plist")
let plistPath = srcPath.appending(relativePath)

let plistContent: [String: Any] = [
"CFBundleIdentifier": "com.example.app",
"CFBundleName": "ExampleApp",
"CFVersion": 1.4,
]
let data = try PropertyListSerialization.data(fromPropertyList: plistContent, format: .xml, options: 0)
try data.write(to: URL(fileURLWithPath: plistPath.pathString))

let target = createTarget(
name: "App",
xcodeProj: xcodeProj,
productType: .application,
buildSettings: [
"PRODUCT_BUNDLE_IDENTIFIER": "com.example.app",
"INFOPLIST_FILE": "$(PROJECT_DIR)/\(relativePath.pathString)",
]
)

try xcodeProj.write(path: xcodeProj.path!)
let mapper = PBXTargetMapper()

// When
let mapped = try await mapper.map(pbxTarget: target, xcodeProj: xcodeProj)

// Then
#expect(
mapped.infoPlist == .dictionary(
[
"CFBundleIdentifier": "com.example.app",
"CFBundleName": "ExampleApp",
"CFVersion": 1.4,
],
configuration: .release("Release")
)
)
}

@Test("Throws invalidPlist when Info.plist cannot be parsed")
func testMapTarget_invalidPlist() async throws {
// Given
Expand Down