From 718ad1231147c276406343059d079d3326520867 Mon Sep 17 00:00:00 2001 From: Omar Al-Ithawi Date: Sat, 22 Jun 2024 05:21:01 +0300 Subject: [PATCH] fix: support `productRef` when removing files fix the exception below: ``` File "pbxproj/pbxextensions/ProjectFiles.py", line 332, in remove_file_by_id if build_file.fileRef == file_ref.get_id(): AttributeError: 'PBXBuildFile' object has no attribute 'fileRef' ``` Fixes #352 --- pbxproj/pbxextensions/ProjectFiles.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pbxproj/pbxextensions/ProjectFiles.py b/pbxproj/pbxextensions/ProjectFiles.py index d00483a..a67ea72 100644 --- a/pbxproj/pbxextensions/ProjectFiles.py +++ b/pbxproj/pbxextensions/ProjectFiles.py @@ -329,7 +329,7 @@ def remove_file_by_id(self, file_id, target_name=None): for build_file_id in filter(lambda x: x in self.objects, build_phase.files): build_file = self.objects[build_file_id] - if build_file.fileRef == file_ref.get_id(): + if hasattr(build_file, 'fileRef') and build_file.fileRef == file_ref.get_id(): # remove the build file from the phase build_phase.remove_build_file(build_file) @@ -339,7 +339,11 @@ def remove_file_by_id(self, file_id, target_name=None): target.remove_build_phase(build_phase) # remove it iff it's removed from all targets or no build file reference it - if len([1 for x in self.objects.get_objects_in_section('PBXBuildFile') if x.fileRef == file_ref.get_id()]) != 0: + if len([ + True + for x in self.objects.get_objects_in_section('PBXBuildFile') + if hasattr(x, 'fileRef') == file_ref.get_id() + ]) != 0: return True # remove the file from any groups if there is no reference from any target