Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CocoaPods crash with nonexistent files #41848

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ def initialize(name)
@name = name
@path = name
end

def real_path
@path
end
end

class XCConfigMock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -797,14 +797,16 @@ def test_updateSearchPaths_whenNotUseFrameworks_addsSearchPaths

def test_applyATSConfig_plistNil
# Arrange
FileMock.mocked_existing_files("Info.plist")
FileMock.mocked_existing_files("Extension-Info.plist")
user_project_mock = prepare_user_project_mock_with_plists()
pods_projects_mock = PodsProjectMock.new([], {"some_pod" => {}})
installer = InstallerMock.new(pods_projects_mock, [
AggregatedProjectMock.new(user_project_mock)
])

# # Act
ReactNativePodsUtils.apply_ats_config(installer)
ReactNativePodsUtils.apply_ats_config(installer, file_manager: FileMock)

# # Assert
assert_equal(user_project_mock.files.length, 2)
Expand All @@ -820,6 +822,8 @@ def test_applyATSConfig_plistNil

def test_applyATSConfig_plistNonNil
# Arrange
FileMock.mocked_existing_files("Info.plist")
FileMock.mocked_existing_files("Extension-Info.plist")
user_project_mock = prepare_user_project_mock_with_plists()
pods_projects_mock = PodsProjectMock.new([], {"some_pod" => {}})
installer = InstallerMock.new(pods_projects_mock, [
Expand All @@ -829,7 +833,7 @@ def test_applyATSConfig_plistNonNil
Xcodeproj::Plist.write_to_path({}, "/test/Extension-Info.plist")

# # Act
ReactNativePodsUtils.apply_ats_config(installer)
ReactNativePodsUtils.apply_ats_config(installer, file_manager: FileMock)

# # Assert
assert_equal(user_project_mock.files.length, 2)
Expand Down
8 changes: 4 additions & 4 deletions packages/react-native/scripts/cocoapods/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -519,11 +519,11 @@ def self.set_imagemanager_search_path(target_installation_result)
ReactNativePodsUtils.update_header_paths_if_depends_on(target_installation_result, "React-ImageManager", header_search_paths)
end

def self.get_plist_paths_from(user_project)
def self.get_plist_paths_from(user_project, file_manager)
info_plists = user_project
.files
.select { |p|
p.name&.end_with?('Info.plist')
file_manager.exist?(p.real_path) && p.name&.end_with?('Info.plist')
}
return info_plists
end
Expand All @@ -547,11 +547,11 @@ def self.update_ats_in_plist(plistPaths, parent)
end
end

def self.apply_ats_config(installer)
def self.apply_ats_config(installer, file_manager: File)
user_project = installer.aggregate_targets
.map{ |t| t.user_project }
.first
plistPaths = self.get_plist_paths_from(user_project)
plistPaths = self.get_plist_paths_from(user_project, file_manager)
self.update_ats_in_plist(plistPaths, user_project.path.parent)
end

Expand Down