From 967de03f304404ac8817936da37ca39514a09e33 Mon Sep 17 00:00:00 2001 From: Lorenzo Sciandra Date: Fri, 7 Oct 2022 02:29:59 -0700 Subject: [PATCH] fix(ios): add xcode 14 workaround (turn off signing resource bundles) for pods (#34826) Summary: This is inspired by the Expo workaround https://github.com/expo/expo/commit/d970a9ecbb15b554b6fa23e8d43006fd15152028 to address an issue that cocoapods has with Xcode 14: https://github.com/CocoaPods/CocoaPods/issues/11402 This wants to address this https://github.com/facebook/react-native/issues/34673 in a way that we can also cherry-pick on the 0.70 branch. ## Changelog [iOS] [Fixed] - add xcode 14 workaround (turn off signing resource bundles) for `React-Core` Pull Request resolved: https://github.com/facebook/react-native/pull/34826 Test Plan: Tested locally by opening RNTester via Xcode 14.0.1, and targetting my iPhone as device. After applying the patch, the error for React Core AccessibilityResources disappears. Also, added ruby test for new patch. Reviewed By: hramos Differential Revision: D40063828 Pulled By: hramos fbshipit-source-id: e10d5b6a917a6a7cbacd14ecfdac55e60e46c6f8 --- scripts/cocoapods/__tests__/utils-test.rb | 62 +++++++++++++++++++++++ scripts/cocoapods/utils.rb | 14 +++++ scripts/react_native_pods.rb | 2 + 3 files changed, 78 insertions(+) diff --git a/scripts/cocoapods/__tests__/utils-test.rb b/scripts/cocoapods/__tests__/utils-test.rb index 5d23f65a0a64a4..76d316505ebe0e 100644 --- a/scripts/cocoapods/__tests__/utils-test.rb +++ b/scripts/cocoapods/__tests__/utils-test.rb @@ -382,6 +382,62 @@ def test_fixReactBridgingHeaderSearchPaths_correctlySetsTheHeaderSearchPathsForA end end + # ===================================== # + # Test - Apply Xcode14 React-Core patch # + # ===================================== # + + def test_turnOffResourceBundleReactCore_correctlyAppliesPatch + # Arrange + react_core_target = TargetMock.new('React-Core') + react_core_target_native_target = react_core_target + react_core_debug_config = prepare_Code_Signing_build_configuration("Debug", "YES") + react_core_release_config = prepare_Code_Signing_build_configuration("Release", "YES") + + hermes_engine_target = TargetMock.new('hermes-engine') + hermes_engine_target_native_target = hermes_engine_target + hermes_engine_debug_config = prepare_Code_Signing_build_configuration("Debug", "NO") + hermes_engine_release_config = prepare_Code_Signing_build_configuration("Release", "NO") + + assets_target = TargetMock.new('assets') + assets_target_native_target = assets_target + assets_debug_config = prepare_Code_Signing_build_configuration("Debug", "YES") + assets_release_config = prepare_Code_Signing_build_configuration("Release", "YES") + + installer = InstallerMock.new(pod_target_installation_results: { + 'React-Core': + TargetInstallationResultMock.new( + react_core_target, + react_core_target_native_target, + [TargetMock.new('React-Core',[react_core_debug_config, react_core_release_config])] + ), + 'hermes-engine': + TargetInstallationResultMock.new( + hermes_engine_target, + hermes_engine_target_native_target, + [TargetMock.new('hermes-engine',[hermes_engine_debug_config, hermes_engine_release_config])] + ), + 'assets': + TargetInstallationResultMock.new( + assets_target, + assets_target_native_target, + [TargetMock.new('assets',[assets_debug_config, assets_release_config])] + ), + }) + + # Act + ReactNativePodsUtils.turn_off_resource_bundle_react_core(installer) + + # Assert + # these must have changed + assert_equal(react_core_debug_config.build_settings["CODE_SIGNING_ALLOWED"], "NO") + assert_equal(react_core_release_config.build_settings["CODE_SIGNING_ALLOWED"], "NO") + # these needs to stay the same + assert_equal(hermes_engine_debug_config.build_settings["CODE_SIGNING_ALLOWED"], "NO") + assert_equal(hermes_engine_release_config.build_settings["CODE_SIGNING_ALLOWED"], "NO") + assert_equal(assets_debug_config.build_settings["CODE_SIGNING_ALLOWED"], "YES") + assert_equal(assets_release_config.build_settings["CODE_SIGNING_ALLOWED"], "YES") + end + # ================================= # # Test - Apply Mac Catalyst Patches # # ================================= # @@ -502,3 +558,9 @@ def prepare_target(name, product_type = nil) prepare_config("Release") ], product_type) end + +def prepare_Code_Signing_build_configuration(name, param) + return BuildConfigurationMock.new(name, { + "CODE_SIGNING_ALLOWED" => param + }) +end diff --git a/scripts/cocoapods/utils.rb b/scripts/cocoapods/utils.rb index 0f80b42226e002..ffec05d27a79c1 100644 --- a/scripts/cocoapods/utils.rb +++ b/scripts/cocoapods/utils.rb @@ -39,6 +39,20 @@ def self.has_pod(installer, name) installer.pods_project.pod_group(name) != nil end + def self.turn_off_resource_bundle_react_core(installer) + # this is needed for Xcode 14, see more details here https://github.com/facebook/react-native/issues/34673 + # we should be able to remove this once CocoaPods catches up to it, see more details here https://github.com/CocoaPods/CocoaPods/issues/11402 + installer.target_installation_results.pod_target_installation_results.each do |pod_name, target_installation_result| + if pod_name.to_s == 'React-Core' + target_installation_result.resource_bundle_targets.each do |resource_bundle_target| + resource_bundle_target.build_configurations.each do |config| + config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO' + end + end + end + end + end + def self.exclude_i386_architecture_while_using_hermes(installer) projects = installer.aggregate_targets .map{ |t| t.user_project } diff --git a/scripts/react_native_pods.rb b/scripts/react_native_pods.rb index 25c2e2179fa69a..03376729a1d854 100644 --- a/scripts/react_native_pods.rb +++ b/scripts/react_native_pods.rb @@ -188,6 +188,8 @@ def use_flipper!(versions = {}, configurations: ['Debug']) # - react_native_path: path to React Native. # - mac_catalyst_enabled: whether we are running the Pod on a Mac Catalyst project or not. def react_native_post_install(installer, react_native_path = "../node_modules/react-native", mac_catalyst_enabled: false) + ReactNativePodsUtils.turn_off_resource_bundle_react_core(installer) + ReactNativePodsUtils.apply_mac_catalyst_patches(installer) if mac_catalyst_enabled if ReactNativePodsUtils.has_pod(installer, 'Flipper')