Skip to content
Open
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 @@ -44,6 +44,11 @@
membershipExceptions = (
XPCService.xpc,
);
platformFiltersByRelativePath = {
XPCService.xpc = (
macos,
);
};
};
/* End PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet section */

Expand Down
3 changes: 3 additions & 0 deletions Fixtures/XCProj/Everything.xcodeproj/project.xcproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
"inclusions": [
"Extra.framework",
],
"platforms": {
"Extra.framework": [ "ios", "tvos" ],
},
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,23 @@ public class PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet: PBX
/// For example `RemoveHeadersOnCopy` and `CodeSignOnCopy`.
public var attributesByRelativePath: [String: [String]]?

/// Platform filters for members of this build phase, keyed by path relative to the synchronized root.
public var platformFiltersByRelativePath: [String: [String]]?

var buildPhaseReference: PBXObjectReference

// MARK: - Init

public init(
buildPhase: PBXBuildPhase,
membershipExceptions: [String]?,
attributesByRelativePath: [String: [String]]?
attributesByRelativePath: [String: [String]]?,
platformFiltersByRelativePath: [String: [String]]? = nil
) {
buildPhaseReference = buildPhase.reference
self.membershipExceptions = membershipExceptions
self.attributesByRelativePath = attributesByRelativePath
self.platformFiltersByRelativePath = platformFiltersByRelativePath
super.init()
}

Expand All @@ -42,6 +47,7 @@ public class PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet: PBX
case buildPhase
case membershipExceptions
case attributesByRelativePath
case platformFiltersByRelativePath
}

public required init(from decoder: Decoder) throws {
Expand All @@ -52,6 +58,7 @@ public class PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet: PBX
self.buildPhaseReference = referenceRepository.getOrCreate(reference: buildPhaseReference, objects: objects)
membershipExceptions = try container.decodeIfPresent(.membershipExceptions)
attributesByRelativePath = try container.decodeIfPresent(.attributesByRelativePath)
platformFiltersByRelativePath = try container.decodeIfPresent(.platformFiltersByRelativePath)
try super.init(from: decoder)
}

Expand All @@ -77,6 +84,12 @@ public class PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet: PBX
(CommentedString(key), .array(value.map { .string(CommentedString($0)) }))
}))
}
if let platformFiltersByRelativePath {
let entries = platformFiltersByRelativePath.map { path, filters in
(CommentedString(path), PlistValue.array(filters.map { .string(CommentedString($0)) }))
}
dictionary["platformFiltersByRelativePath"] = .dictionary(Dictionary(uniqueKeysWithValues: entries))
}
dictionary["buildPhase"] = .string(CommentedString(buildPhase.reference.value, comment: buildPhase.name() ?? "CopyFiles"))
return (key: CommentedString(reference, comment: "PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet"), value: .dictionary(dictionary))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ extension PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet {
/// :nodoc:
func isEqual(to rhs: PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet) -> Bool {
if membershipExceptions != rhs.membershipExceptions { return false }
if platformFiltersByRelativePath != rhs.platformFiltersByRelativePath { return false }
if buildPhaseReference != rhs.buildPhaseReference { return false }
return super.isEqual(to: rhs)
}
Expand Down
18 changes: 6 additions & 12 deletions Sources/XcodeProj/XCProj/XCProjDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ extension XCProjDecoder {
throw XCProjError.unresolvedTarget(content.target.targetName)
}
let common = content.commonProperties
try rejectUnrepresentable(common, allowsPlatformFilters: true)
try rejectUnrepresentable(common)
let compilerFlags: [String: String]? = content.additionalCompilerFlags.isEmpty
? nil
: content.additionalCompilerFlags.reduce(into: [:]) { $0[$1.key.value] = $1.value }
Expand All @@ -992,29 +992,23 @@ extension XCProjDecoder {
case let .buildPhase(content):
let phase = try resolvePhase(content.buildPhase)
let common = content.commonProperties
try rejectUnrepresentable(common, allowsPlatformFilters: false)
try rejectUnrepresentable(common)
let set = try PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet(
buildPhase: phase,
membershipExceptions: common.membershipExceptions.isEmpty ? nil : common.membershipExceptions.map(\.value).sorted(),
attributesByRelativePath: attributesByRelativePath(common)
attributesByRelativePath: attributesByRelativePath(common),
platformFiltersByRelativePath: platformFiltersByRelativePath(common)
)
add(set)
return set
}
}

/// The property list exception sets carry less than the schema ones: neither has a place for
/// asset tags, and the build phase variant has none for platform filters either.
private func rejectUnrepresentable(
_ common: XCSchema.CommonExceptionSetProperties,
allowsPlatformFilters: Bool
) throws {
/// The property list exception sets do not represent asset tags.
private func rejectUnrepresentable(_ common: XCSchema.CommonExceptionSetProperties) throws {
if !common.assetTagsByFolderMemberID.isEmpty {
throw XCProjError.unsupportedBuildFileAttribute("asset-tags in a folder exception set")
}
if !allowsPlatformFilters, !common.platformFiltersByFolderMemberID.isEmpty {
throw XCProjError.unsupportedBuildFileAttribute("platforms in a build phase exception set")
}
}

private func attributesByRelativePath(
Expand Down
2 changes: 1 addition & 1 deletion Sources/XcodeProj/XCProj/XCProjEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ extension XCProjEncoder {
sense: .inclusions,
membershipExceptions: exception.membershipExceptions,
attributesByRelativePath: exception.attributesByRelativePath,
platformFiltersByRelativePath: nil
platformFiltersByRelativePath: exception.platformFiltersByRelativePath
)
))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@
line = lines.validate(line: "membershipExceptions = (", after: line)
line = lines.validate(line: "XPCService.xpc,", after: line)
line = lines.validate(line: ");", after: line)
line = lines.validate(line: "platformFiltersByRelativePath = {", onLineAfter: line)
line = lines.validate(line: "XPCService.xpc = (", onLineAfter: line)
line = lines.validate(line: "macos,", onLineAfter: line)
line = lines.validate(line: ");", onLineAfter: line)
line = lines.validate(line: "};", onLineAfter: line)
line = lines.validate(line: "};", after: line)
line = lines.validate(line: "/* End PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet section */", after: line)
}
Expand Down
1 change: 1 addition & 0 deletions Tests/XcodeProjTests/XCProj/XCProjDecoderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ import XcodeProjectFormat
exceptions.compactMap { $0 as? PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet }.first
)
#expect(phaseException.membershipExceptions == ["Extra.framework"])
#expect(phaseException.platformFiltersByRelativePath == ["Extra.framework": ["ios", "tvos"]])
#expect(phaseException.buildPhase is PBXCopyFilesBuildPhase)
}

Expand Down
3 changes: 3 additions & 0 deletions Tests/XcodeProjTests/XCProj/XCProjEncoderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import XcodeProjectFormat
let originalFolders = try #require(original.rootObject?.targets.first?.fileSystemSynchronizedGroups)
let convertedFolders = try #require(converted.rootObject?.targets.first?.fileSystemSynchronizedGroups)
#expect(originalFolders.map(\.path) == convertedFolders.map(\.path))

let phaseException = try #require(converted.fileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet.first)
#expect(phaseException.platformFiltersByRelativePath == ["XPCService.xpc": ["macos"]])
}

@Test func convertProjectWithBuildConfigurationFilesInSynchronizedGroup() throws {
Expand Down