Handle the case where the file reference doesn't have a path (#44410)

This commit is contained in:
Rui Ying
2024-07-22 11:17:10 -07:00
committed by siddharthkul
parent e24be3072c
commit b5b3f3c43d
@@ -67,7 +67,7 @@ module PrivacyManifestUtils
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
@@ -76,7 +76,12 @@ module PrivacyManifestUtils
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?