Skip to content

Commit

Permalink
Handle the case where the file reference doesn't have a path (#44410)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertying authored and siddharthkul committed Jul 22, 2024
1 parent e24be30 commit b5b3f3c
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def self.read_privacyinfo_file(file_path)
end

def self.ensure_reference(file_path, user_project, target)
reference_exists = target.resources_build_phase.files_references.any? { |file_ref| file_ref.path.end_with? "PrivacyInfo.xcprivacy" }
reference_exists = target.resources_build_phase.files_references.any? { |file_ref| file_ref.path&.end_with? "PrivacyInfo.xcprivacy" }
unless reference_exists
# We try to find the main group, but if it doesn't exist, we default to adding the file to the project root – both work
file_root = user_project.root_object.main_group.children.first { |group| group.name == target.name } || user_project
Expand All @@ -76,7 +76,12 @@ def self.ensure_reference(file_path, user_project, target)
end
end

def self.get_privacyinfo_file_path(user_project)
def self.get_privacyinfo_file_path(user_project, targets)
file_refs = targets.flat_map { |target| target.resources_build_phase.files_references }
existing_file = file_refs.find { |file_ref| file_ref.path&.end_with? "PrivacyInfo.xcprivacy" }
if existing_file
return existing_file.real_path
end
# We try to find a file we know exists in the project to get the path to the main group directory
info_plist_path = user_project.files.find { |file_ref| file_ref.name == "Info.plist" }
if info_plist_path.nil?
Expand Down

0 comments on commit b5b3f3c

Please sign in to comment.