Skip to content

Commit a50bad4

Browse files
robertyingsiddharthkul
authored andcommitted
Handle the case where the file reference doesn't have a path (#44410)
1 parent 4cee0a4 commit a50bad4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/react-native/scripts/cocoapods/privacy_manifest_utils.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def self.read_privacyinfo_file(file_path)
6767
end
6868

6969
def self.ensure_reference(file_path, user_project, target)
70-
reference_exists = target.resources_build_phase.files_references.any? { |file_ref| file_ref.path.end_with? "PrivacyInfo.xcprivacy" }
70+
reference_exists = target.resources_build_phase.files_references.any? { |file_ref| file_ref.path&.end_with? "PrivacyInfo.xcprivacy" }
7171
unless reference_exists
7272
# 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
7373
file_root = user_project.root_object.main_group.children.first { |group| group.name == target.name } || user_project
@@ -76,7 +76,12 @@ def self.ensure_reference(file_path, user_project, target)
7676
end
7777
end
7878

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

0 commit comments

Comments
 (0)