mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
fix(iOS): don't reference PrivacyInfo.xcprivacy twice for new projects (#46457)
Summary:
This PR fixes an issue with PrivacyInfo files.
When generating a new project for using the latest RC 0.76.0.rc0 I got two privacy manifests references in Xcode.
This is because `PrivacyManifestUtils` look for build phase reference:
```ruby
reference_exists = target.resources_build_phase.files_references.any? { |file_ref| file_ref&.path&.end_with? "xcprivacy" }
```
Which doesn't exist for the generated template.
Here is how Xcode file tree looks like after installing pods:

## Changelog:
[IOS] [FIXED] - don't reference PrivacyInfo.xcprivacy twice for new projects
Pull Request resolved: https://github.com/facebook/react-native/pull/46457
Test Plan:
1. Generate a new project
2. Execute pod install
3. Check if only one PrivacyInfo file exists
Reviewed By: cortinico
Differential Revision: D62580116
Pulled By: cipolleschi
fbshipit-source-id: 1224a41307ae6c9b862832f145baf0edc92476d6
This commit is contained in:
committed by
Facebook GitHub Bot
parent
120558c0cd
commit
cadd41b1a2
@@ -67,14 +67,29 @@ 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" }
|
||||
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.find { |group|
|
||||
group.class == Xcodeproj::Project::Object::PBXGroup && (group.name == target.name || group.path == target.name)
|
||||
} || user_project
|
||||
file_ref = file_root.new_file(file_path)
|
||||
build_file = target.resources_build_phase.add_file_reference(file_ref, true)
|
||||
privacy_info_filename = File.basename(file_path)
|
||||
|
||||
# Check if the file is already in the PBXBuildFile section
|
||||
build_phase_reference_exists = target.resources_build_phase.files_references.any? { |file_ref| file_ref&.path&.end_with?(privacy_info_filename) }
|
||||
|
||||
unless build_phase_reference_exists
|
||||
# Check if the file is already in the PBXFileReference section
|
||||
existing_file_reference = user_project.files.find { |file| file.path&.end_with?(privacy_info_filename) }
|
||||
|
||||
if existing_file_reference
|
||||
# If the file reference exists, add it to the build phase
|
||||
target.resources_build_phase.add_file_reference(existing_file_reference, true)
|
||||
else
|
||||
# If the file reference doesn't exist, add it to the project and the build phase
|
||||
# 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.find { |group|
|
||||
group.class == Xcodeproj::Project::Object::PBXGroup && (group.name == target.name || group.path == target.name)
|
||||
} || user_project
|
||||
puts "file_root: #{file_root}"
|
||||
|
||||
file_ref = file_root.new_file(file_path)
|
||||
target.resources_build_phase.add_file_reference(file_ref, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user