diff --git a/Fixtures/SynchronizedRootGroups/SynchronizedRootGroups.xcodeproj/project.pbxproj b/Fixtures/SynchronizedRootGroups/SynchronizedRootGroups.xcodeproj/project.pbxproj index a8db250fe..d28e4ac9a 100644 --- a/Fixtures/SynchronizedRootGroups/SynchronizedRootGroups.xcodeproj/project.pbxproj +++ b/Fixtures/SynchronizedRootGroups/SynchronizedRootGroups.xcodeproj/project.pbxproj @@ -44,6 +44,11 @@ membershipExceptions = ( XPCService.xpc, ); + platformFiltersByRelativePath = { + XPCService.xpc = ( + macos, + ); + }; }; /* End PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet section */ diff --git a/Fixtures/XCProj/Everything.xcodeproj/project.xcproj b/Fixtures/XCProj/Everything.xcodeproj/project.xcproj index 86af42341..e45ff8eb6 100644 --- a/Fixtures/XCProj/Everything.xcodeproj/project.xcproj +++ b/Fixtures/XCProj/Everything.xcodeproj/project.xcproj @@ -115,6 +115,9 @@ "inclusions": [ "Extra.framework", ], + "platforms": { + "Extra.framework": [ "ios", "tvos" ], + }, }, ], }, diff --git a/Sources/XcodeProj/Objects/Files/PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet.swift b/Sources/XcodeProj/Objects/Files/PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet.swift index b2326893e..d941cb9d4 100644 --- a/Sources/XcodeProj/Objects/Files/PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet.swift +++ b/Sources/XcodeProj/Objects/Files/PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet.swift @@ -21,6 +21,9 @@ 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 @@ -28,11 +31,13 @@ public class PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet: PBX 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() } @@ -42,6 +47,7 @@ public class PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet: PBX case buildPhase case membershipExceptions case attributesByRelativePath + case platformFiltersByRelativePath } public required init(from decoder: Decoder) throws { @@ -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) } @@ -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)) } diff --git a/Sources/XcodeProj/Objects/Sourcery/Equality.generated.swift b/Sources/XcodeProj/Objects/Sourcery/Equality.generated.swift index f2d335f07..a53ce6ec9 100644 --- a/Sources/XcodeProj/Objects/Sourcery/Equality.generated.swift +++ b/Sources/XcodeProj/Objects/Sourcery/Equality.generated.swift @@ -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) } diff --git a/Sources/XcodeProj/XCProj/XCProjDecoder.swift b/Sources/XcodeProj/XCProj/XCProjDecoder.swift index 6b1f4b427..0a7ad7671 100644 --- a/Sources/XcodeProj/XCProj/XCProjDecoder.swift +++ b/Sources/XcodeProj/XCProj/XCProjDecoder.swift @@ -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 } @@ -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( diff --git a/Sources/XcodeProj/XCProj/XCProjEncoder.swift b/Sources/XcodeProj/XCProj/XCProjEncoder.swift index 22e08e9ab..6e9bde7fc 100644 --- a/Sources/XcodeProj/XCProj/XCProjEncoder.swift +++ b/Sources/XcodeProj/XCProj/XCProjEncoder.swift @@ -542,7 +542,7 @@ extension XCProjEncoder { sense: .inclusions, membershipExceptions: exception.membershipExceptions, attributesByRelativePath: exception.attributesByRelativePath, - platformFiltersByRelativePath: nil + platformFiltersByRelativePath: exception.platformFiltersByRelativePath ) )) diff --git a/Tests/XcodeProjTests/Objects/Project/PBXProjEncoderTests.swift b/Tests/XcodeProjTests/Objects/Project/PBXProjEncoderTests.swift index aa7424c5e..ed15b56a9 100644 --- a/Tests/XcodeProjTests/Objects/Project/PBXProjEncoderTests.swift +++ b/Tests/XcodeProjTests/Objects/Project/PBXProjEncoderTests.swift @@ -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) } diff --git a/Tests/XcodeProjTests/XCProj/XCProjDecoderTests.swift b/Tests/XcodeProjTests/XCProj/XCProjDecoderTests.swift index 717ab3286..6f61bf25a 100644 --- a/Tests/XcodeProjTests/XCProj/XCProjDecoderTests.swift +++ b/Tests/XcodeProjTests/XCProj/XCProjDecoderTests.swift @@ -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) } diff --git a/Tests/XcodeProjTests/XCProj/XCProjEncoderTests.swift b/Tests/XcodeProjTests/XCProj/XCProjEncoderTests.swift index 15cd1d9c9..7750b1645 100644 --- a/Tests/XcodeProjTests/XCProj/XCProjEncoderTests.swift +++ b/Tests/XcodeProjTests/XCProj/XCProjEncoderTests.swift @@ -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 {