Skip to content

Commit 2375b07

Browse files
robertyingcipolleschi
authored andcommitted
Handle the case where the file reference doesn't have a path (#44410)
Summary: The new cocoapod post install script includes aggregation and generation of privacy manifests for iOS, which is great. However, the script doesn't consider the case where the file reference doesn't have a path. Example, for a project setup like the screenshot: <img width="249" alt="image" src="https://github.com/facebook/react-native/assets/22592111/45dd1cf4-c2f6-4abb-940f-136a4d502966"> The code https://github.com/facebook/react-native/blob/05a4232dd591e2d43f192d69ca14a04f4a3fb6a1/packages/react-native/scripts/cocoapods/privacy_manifest_utils.rb#L80-L81 prints `file_refs`: ``` [ <PBXFileReference name=`LaunchScreen.storyboard` path=`learnX/LaunchScreen.storyboard` UUID=`81AB9BB72411601600AC10FF`>, <PBXVariantGroup name=`InfoPlist.strings` UUID=`D40B9F832B248EF5004BC08C`>, <PBXFileReference path=`AppCenter-Config.plist` UUID=`D40B9F802B248EC2004BC08C`>, <PBXFileReference name=`PrivacyInfo.xcprivacy` path=`learnX/PrivacyInfo.xcprivacy` UUID=`D403DD362BCA2BCF00E5295C`>, <PBXFileReference name=`Assets.xcassets` path=`learnX/Assets.xcassets` UUID=`D40B9F652B248AEB004BC08C`> ] ``` where a `PBXVariantGroup` exists and it doesn't have `path`. The error `undefined method 'end_with?' for nil` occurs as a result. ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [IOS] [FIXED] - In privacy manifest post install script, handle the case where the file reference doesn't have a path Pull Request resolved: #44410 Test Plan: 1. Add a new "Strings File (Legacy)" in Xcode to the project. 2. Run `pod install` for iOS. 3. See the error `undefined method 'end_with?' for nil`. 4. Apply the fix and rerun `pod install`. 5. The script runs successfully. Reviewed By: javache Differential Revision: D57056159 Pulled By: cipolleschi fbshipit-source-id: 42caaf1a98efb9111f6ff1014a5c8b7703b042f2
1 parent 156e8cf commit 2375b07

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

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

Lines changed: 2 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.find { |group|
@@ -80,7 +80,7 @@ def self.ensure_reference(file_path, user_project, target)
8080

8181
def self.get_privacyinfo_file_path(user_project, targets)
8282
file_refs = targets.flat_map { |target| target.resources_build_phase.files_references }
83-
existing_file = file_refs.find { |file_ref| file_ref.path.end_with? "PrivacyInfo.xcprivacy" }
83+
existing_file = file_refs.find { |file_ref| file_ref.path&.end_with? "PrivacyInfo.xcprivacy" }
8484
if existing_file
8585
return existing_file.real_path
8686
end

0 commit comments

Comments
 (0)