Skip to content

Commit

Permalink
Merge pull request #24 from microsoft/dalemyers/pbxreferenceproxy
Browse files Browse the repository at this point in the history
Fix paths for PBXReferenceProxy
  • Loading branch information
dalemyers authored Nov 30, 2023
2 parents 1fb5030 + fbd4958 commit 5225779
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 28 deletions.
18 changes: 18 additions & 0 deletions tests/collateral/Two.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
remoteGlobalIDString = DD624D2E25B05EEE0081F68F;
remoteInfo = "wat WatchKit Extension";
};
07231F3E207DA2FF007D566D /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = NOTAREALREFERENCE /* SomeOtherProject.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 67A017B82069820500472EB6;
remoteInfo = Sometest;
};
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -128,6 +135,7 @@
DD62471925AF30980081F68F /* Frameworks */ = {
isa = PBXGroup;
children = (
07231F3F207DA2FF007D566D /* SomeTest.framework */,
);
name = Frameworks;
sourceTree = "<group>";
Expand Down Expand Up @@ -331,6 +339,16 @@
};
/* End PBXProject section */

/* Begin PBXReferenceProxy section */
07231F3F207DA2FF007D566D /* SomeTest.framework */ = {
isa = PBXReferenceProxy;
fileType = wrapper.framework;
path = SomeTest.framework;
remoteRef = 07231F3E207DA2FF007D566D /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
/* End PBXReferenceProxy section */

/* Begin PBXResourcesBuildPhase section */
DD624D1B25B05EED0081F68F /* Resources */ = {
isa = PBXResourcesBuildPhase;
Expand Down
41 changes: 31 additions & 10 deletions tests/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ def test_get_paths(one: xcodeproj.XcodeProject, two: xcodeproj.XcodeProject) ->
"Carthage/Build/CocoaLumberjack.xcframework",
"wat WatchKit Extension/NotificationController.swift",
"CLJTest/AppDelegate.swift",
"$(BUILT_PRODUCTS_DIR)",
"$(BUILT_PRODUCTS_DIR)",
"wat WatchKit Extension.appex",
"CLJTest.app",
"CLJTest/Base.lproj/LaunchScreen.storyboard",
"wat WatchKit App/Base.lproj/Interface.storyboard",
"wat WatchKit Extension/Assets.xcassets",
Expand All @@ -120,14 +120,21 @@ def test_get_paths(one: xcodeproj.XcodeProject, two: xcodeproj.XcodeProject) ->
"wat WatchKit Extension/PushNotificationPayload.apns",
"CLJTest/ViewController.swift",
"wat WatchKit Extension/ExtensionDelegate.swift",
"$(BUILT_PRODUCTS_DIR)",
"wat.app",
"CLJTest/Base.lproj/Main.storyboard",
"$(BUILT_PRODUCTS_DIR)",
"wat WatchKit App.app",
]

for index, item in enumerate(one.fetch_type(xcodeproj.PBXFileReference).values()):
assert item.relative_path() == expected[index]
assert item.absolute_path() == os.path.join(COLLATERAL_PATH, expected[index])
absolute_path = item.absolute_path()

assert absolute_path is not None

if absolute_path.startswith("$(BUILT_PRODUCTS_DIR)/"):
assert absolute_path == "$(BUILT_PRODUCTS_DIR)/" + expected[index]
else:
assert absolute_path == os.path.join(COLLATERAL_PATH, expected[index])

groups = [
"wat WatchKit App",
Expand Down Expand Up @@ -182,8 +189,8 @@ def test_get_paths_prepopulated(one: xcodeproj.XcodeProject, two: xcodeproj.Xcod
"Carthage/Build/CocoaLumberjack.xcframework",
"wat WatchKit Extension/NotificationController.swift",
"CLJTest/AppDelegate.swift",
"$(BUILT_PRODUCTS_DIR)",
"$(BUILT_PRODUCTS_DIR)",
"wat WatchKit Extension.appex",
"CLJTest.app",
"CLJTest/Base.lproj/LaunchScreen.storyboard",
"wat WatchKit App/Base.lproj/Interface.storyboard",
"wat WatchKit Extension/Assets.xcassets",
Expand All @@ -192,14 +199,21 @@ def test_get_paths_prepopulated(one: xcodeproj.XcodeProject, two: xcodeproj.Xcod
"wat WatchKit Extension/PushNotificationPayload.apns",
"CLJTest/ViewController.swift",
"wat WatchKit Extension/ExtensionDelegate.swift",
"$(BUILT_PRODUCTS_DIR)",
"wat.app",
"CLJTest/Base.lproj/Main.storyboard",
"$(BUILT_PRODUCTS_DIR)",
"wat WatchKit App.app",
]

for index, item in enumerate(one.fetch_type(xcodeproj.PBXFileReference).values()):
assert item.relative_path() == expected[index]
assert item.absolute_path() == os.path.join(COLLATERAL_PATH, expected[index])
absolute_path = item.absolute_path()

assert absolute_path is not None

if absolute_path.startswith("$(BUILT_PRODUCTS_DIR)/"):
assert absolute_path == "$(BUILT_PRODUCTS_DIR)/" + expected[index]
else:
assert absolute_path == os.path.join(COLLATERAL_PATH, expected[index])

groups = [
"wat WatchKit App",
Expand Down Expand Up @@ -231,6 +245,13 @@ def test_get_paths_prepopulated(one: xcodeproj.XcodeProject, two: xcodeproj.Xcod
assert version_group.relative_path() is None
assert version_group.absolute_path() is None

reference_proxy_expectations = [("BUILT_PRODUCTS_DIR", "SomeTest.framework")]

for index, proxy in enumerate(two.fetch_type(xcodeproj.PBXReferenceProxy).values()):
expected_root, expected_relative = reference_proxy_expectations[index]
assert proxy.relative_path() == expected_relative
assert proxy.absolute_path() == os.path.join(f"$({expected_root})", expected_relative)


def test_get_parents(two: xcodeproj.XcodeProject) -> None:
"""Test that getting parents works.
Expand Down
3 changes: 2 additions & 1 deletion xcodeproj/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
PBXVariantGroup,
PBXFileReference,
XCVersionGroup,
PBXReferenceProxy,
)
from .pbxproject import PBXProject
from .other import PBXTargetDependency, PBXContainerItemProxy
Expand Down Expand Up @@ -233,7 +234,7 @@ def populate_paths(self) -> None:
if self._is_populated:
return

non_set = []
non_set: list[PBXPathObject] = []

root_group = self.objects[self.project.main_group_id]
self._populate(root_group, None, non_set)
Expand Down
15 changes: 0 additions & 15 deletions xcodeproj/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,6 @@ class PBXContainerItemProxy(PBXObject):
remote_info: str


@deserialize.auto_snake()
@deserialize.downcast_identifier(PBXObject, "PBXReferenceProxy")
class PBXReferenceProxy(PBXObject):
"""Represents a PBXReferenceProxy.
It's not clear what this one is. As far as I can tell, it references
something in another project in the same workspace.
"""

file_type: str
path: str
remote_ref: str
source_tree: str


@deserialize.auto_snake()
class ProjectReference:
"""A reference to another project."""
Expand Down
25 changes: 23 additions & 2 deletions xcodeproj/pathobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ def relative_path(self) -> Optional[str]:
return cast(str, self.path)

if self.source_tree == "<absolute>":
if not self.path.startswith(os.sep):
if self.path and not self.path.startswith(os.sep):
setattr(self, "_relative_path", self.path)
return self.path

if self.source_tree != "<group>":
if self.source_tree in ["BUILT_PRODUCTS_DIR", "SDKROOT", "DEVELOPER_DIR"]:
return f"$({self.source_tree})"
return self.path
raise Exception(f"Unexpected source tree: {self.source_tree}")

parent = self.parent_group()
Expand Down Expand Up @@ -127,6 +127,12 @@ def absolute_path(self) -> Optional[str]:
if path.startswith("/"):
return path

if self.source_tree in ["BUILT_PRODUCTS_DIR", "SDKROOT", "DEVELOPER_DIR"]:
if self.path:
return os.path.join(f"$({self.source_tree})", self.path)

return f"$({self.source_tree})"

return os.path.join(self.project().source_root, path)


Expand Down Expand Up @@ -223,3 +229,18 @@ def children(self) -> List[PBXPathObject]:
:returns: The children for this group
"""
return [cast(PBXPathObject, self.objects()[child_id]) for child_id in self.child_ids]


@deserialize.auto_snake()
@deserialize.downcast_identifier(PBXObject, "PBXReferenceProxy")
class PBXReferenceProxy(PBXPathObject):
"""Represents a PBXReferenceProxy.
It's not clear what this one is. As far as I can tell, it references
something in another project in the same workspace.
"""

file_type: str
path: str
remote_ref: str
source_tree: str

0 comments on commit 5225779

Please sign in to comment.