Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xcode11's platformFilter is ignored in PBXTargetDependency.swift #525

Closed
jbuchman opened this issue Feb 25, 2020 · 0 comments · Fixed by #546
Closed

Xcode11's platformFilter is ignored in PBXTargetDependency.swift #525

jbuchman opened this issue Feb 25, 2020 · 0 comments · Fixed by #546

Comments

@jbuchman
Copy link

jbuchman commented Feb 25, 2020

Context 🕵️‍♀️

When writing iOS apps with watchOS target dependencies and also supporting macOS Catalyst, the target's platformFilter in the target dependencies is being ignored when reading and writing project.pbxproj file.

What 🌱

My app which has watchOS, iOS and macOS/Catalyst components has a target in which the iOS app is compiled. That target includes a dependency on the watchOS target as well. To resolve the fact that you can't embed a watchOS target in a Catalyst app, I select "iOS" from the Platforms dropdown in the Dependencies of the Build Phases tab. However, when reading/writing the project files using this xcodeproj library, this dropdown setting is forgotten.

Proposal 🎉

From 924fcef87cf4202786240f47b3fc6db20e82e840 Mon Sep 17 00:00:00 2001
From: Jeremy Buchman <[email protected]>
Date: Tue, 25 Feb 2020 16:03:51 -0700
Subject: [PATCH] Added platformFilter to target dependency for Xcode 11
 support (WatchOS + Catalyst)

---
 .../Objects/Targets/PBXTargetDependency.swift         | 11 +++++++++++
 .../Objects/Project/PBXProjIntegrationTests.swift     |  3 +++
 2 files changed, 14 insertions(+)

diff --git a/Sources/XcodeProj/Objects/Targets/PBXTargetDependency.swift b/Sources/XcodeProj/Objects/Targets/PBXTargetDependency.swift
index a21e721..817813e 100644
--- a/Sources/XcodeProj/Objects/Targets/PBXTargetDependency.swift
+++ b/Sources/XcodeProj/Objects/Targets/PBXTargetDependency.swift
@@ -7,6 +7,10 @@ public final class PBXTargetDependency: PBXObject {
     /// Target name.
     public var name: String?
 
+    /// Platform filter attribute.
+    /// Introduced in: Xcode 11
+    public var platformFilter: String?
+    
     /// Target reference.
     var targetReference: PBXObjectReference?
 
@@ -72,6 +76,7 @@ public final class PBXTargetDependency: PBXObject {
         case target
         case targetProxy
         case productRef
+        case platformFilter
     }
 
     public required init(from decoder: Decoder) throws {
@@ -79,6 +84,7 @@ public final class PBXTargetDependency: PBXObject {
         let referenceRepository = decoder.context.objectReferenceRepository
         let objects = decoder.context.objects
         name = try container.decodeIfPresent(.name)
+        platformFilter = try container.decodeIfPresent(.platformFilter)
         if let targetReference: String = try container.decodeIfPresent(.target) {
             self.targetReference = referenceRepository.getOrCreate(reference: targetReference, objects: objects)
         }
@@ -101,6 +107,11 @@ extension PBXTargetDependency: PlistSerializable {
         if let name = name {
             dictionary["name"] = .string(CommentedString(name))
         }
+        
+        if let platformFilter = platformFilter {
+            dictionary["platformFilter"] = .string(.init(platformFilter))
+        }
+        
         if let targetReference = targetReference {
             let targetObject: PBXTarget? = targetReference.getObject()
             dictionary["target"] = .string(CommentedString(targetReference.value, comment: targetObject?.name))

PS: I would have just submitted a pull request, but I couldn't resolve an issue with one of the tests and thus I couldn't get the project to compile without commenting out that test. (PBXProjIntegrationTests.swift)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant