From c6949ee841239dcb6e45c1fc7fe64637711d8f2a Mon Sep 17 00:00:00 2001 From: Arkkeeper Date: Sat, 18 Jun 2022 21:16:20 +0300 Subject: [PATCH 1/6] Mac Catalyst patches --- scripts/react_native_pods.rb | 24 ++++++++++++++++++++++++ template/ios/Podfile | 2 ++ 2 files changed, 26 insertions(+) diff --git a/scripts/react_native_pods.rb b/scripts/react_native_pods.rb index f8f36a411d4c31..d0a18004b7cedc 100644 --- a/scripts/react_native_pods.rb +++ b/scripts/react_native_pods.rb @@ -498,6 +498,30 @@ def __apply_Xcode_12_5_M1_post_install_workaround(installer) `sed -i -e $'s/ && (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_10_0)//' #{time_header}` end +# Apply three patches necessary for successful building and archiving RN on Mac Catalyst targets +def __apply_mac_catalyst_patches(installer) + # Fix bundle signing issues + installer.pods_project.targets.each do |target| + if target.respond_to?(:product_type) and target.product_type == "com.apple.product-type.bundle" + target.build_configurations.each do |config| + config.build_settings['CODE_SIGN_IDENTITY[sdk=macosx*]'] = '-' + end + end + end + + installer.aggregate_targets.each do |aggregate_target| + aggregate_target.user_project.native_targets.each do |target| + target.build_configurations.each do |config| + # Explicitly set dead code stripping flag + config.build_settings['DEAD_CODE_STRIPPING'] = 'YES' + # Modify library search paths + config.build_settings['LIBRARY_SEARCH_PATHS'] = ['$(SDKROOT)/usr/lib/swift', '$(SDKROOT)/System/iOSSupport/usr/lib/swift', '$(inherited)'] + end + end + aggregate_target.user_project.save + end +end + # Monkeypatch of `Pod::Lockfile` to ensure automatic update of dependencies integrated with a local podspec when their version changed. # This is necessary because local podspec dependencies must be otherwise manually updated. module LocalPodspecPatch diff --git a/template/ios/Podfile b/template/ios/Podfile index 938146d23e839b..30cd2368214ba6 100644 --- a/template/ios/Podfile +++ b/template/ios/Podfile @@ -33,5 +33,7 @@ target 'HelloWorld' do post_install do |installer| react_native_post_install(installer) __apply_Xcode_12_5_M1_post_install_workaround(installer) + # Enable the next line in order to apply patches necessary for Mac Catalyst builds + #__apply_mac_catalyst_patches(installer) end end From e04f353cd7813357d783f22928bcb78d8a611d83 Mon Sep 17 00:00:00 2001 From: Arkkeeper Date: Wed, 22 Jun 2022 12:45:10 +0300 Subject: [PATCH 2/6] Mac Catalyst Patches moved to cocoapods/utils.rb --- scripts/cocoapods/__tests__/utils-test.rb | 47 +++++++++++++++++++++++ scripts/cocoapods/utils.rb | 24 ++++++++++++ scripts/react_native_pods.rb | 21 +--------- 3 files changed, 72 insertions(+), 20 deletions(-) diff --git a/scripts/cocoapods/__tests__/utils-test.rb b/scripts/cocoapods/__tests__/utils-test.rb index 410af249835e00..c3c90b1fde1013 100644 --- a/scripts/cocoapods/__tests__/utils-test.rb +++ b/scripts/cocoapods/__tests__/utils-test.rb @@ -299,6 +299,53 @@ def test_fixLibrarySearchPaths_correctlySetsTheSearchPathsForAllProjects assert_equal(pods_projects_mock.save_invocation_count, 1) end + # ================================= # + # Test - Apply Mac Catalyst Patches # + # ================================= # + + def test_applyMacCatalystPatches_correctlyAppliesNecessaryPatches + firstTarget = prepare_target("FirstTarget") + secondTarget = prepare_target("SecondTarget") + thirdTarget = prepare_target("ThirdTarget") + user_project_mock = UserProjectMock.new("a/path", [ + prepare_config("Debug"), + prepare_config("Release"), + ], + :native_targets => [ + firstTarget, + secondTarget + ] + ) + pods_projects_mock = PodsProjectMock.new([], {"hermes-engine" => {}}, :native_targets => [ + thirdTarget + ]) + installer = InstallerMock.new(pods_projects_mock, [ + AggregatedProjectMock.new(user_project_mock) + ]) + + # Act + ReactNativePodsUtils.apply_mac_catalyst_patches(installer) + + # Assert + pods_projects_mock.targets.each do |target| + if target.respond_to?(:product_type) and target.product_type == "com.apple.product-type.bundle" + target.build_configurations.each do |config| + assert_equal(config.build_settings["CODE_SIGN_IDENTITY[sdk=macosx*]"], "-") + end + end + end + + user_project_mock.native_targets.each do |target| + target.build_configurations.each do |config| + assert_equal(config.build_settings["DEAD_CODE_STRIPPING"], "YES") + assert_equal(config.build_settings["PRESERVE_DEAD_CODE_INITS_AND_TERMS"], "YES") + assert_equal(config.build_settings["LIBRARY_SEARCH_PATHS"], ["$(SDKROOT)/usr/lib/swift", "$(SDKROOT)/System/iOSSupport/usr/lib/swift", "$(inherited)"]) + end + end + + assert_equal(user_project_mock.save_invocation_count, 1) + end + # ==================================== # # Test - Set Node_Modules User Setting # # ==================================== # diff --git a/scripts/cocoapods/utils.rb b/scripts/cocoapods/utils.rb index 6ea8db0c3847a5..ed720ed512c93b 100644 --- a/scripts/cocoapods/utils.rb +++ b/scripts/cocoapods/utils.rb @@ -93,6 +93,30 @@ def self.fix_library_search_paths(installer) end end + def self.apply_mac_catalyst_patches(installer) + # Fix bundle signing issues + installer.pods_project.targets.each do |target| + if target.respond_to?(:product_type) and target.product_type == "com.apple.product-type.bundle" + target.build_configurations.each do |config| + config.build_settings['CODE_SIGN_IDENTITY[sdk=macosx*]'] = '-' + end + end + end + + installer.aggregate_targets.each do |aggregate_target| + aggregate_target.user_project.native_targets.each do |target| + target.build_configurations.each do |config| + # Explicitly set dead code stripping flags + config.build_settings['DEAD_CODE_STRIPPING'] = 'YES' + config.build_settings['PRESERVE_DEAD_CODE_INITS_AND_TERMS'] = 'YES' + # Modify library search paths + config.build_settings['LIBRARY_SEARCH_PATHS'] = ['$(SDKROOT)/usr/lib/swift', '$(SDKROOT)/System/iOSSupport/usr/lib/swift', '$(inherited)'] + end + end + aggregate_target.user_project.save + end + end + private def self.fix_library_search_path(config) diff --git a/scripts/react_native_pods.rb b/scripts/react_native_pods.rb index d0a18004b7cedc..a9a4cb8acff51b 100644 --- a/scripts/react_native_pods.rb +++ b/scripts/react_native_pods.rb @@ -500,26 +500,7 @@ def __apply_Xcode_12_5_M1_post_install_workaround(installer) # Apply three patches necessary for successful building and archiving RN on Mac Catalyst targets def __apply_mac_catalyst_patches(installer) - # Fix bundle signing issues - installer.pods_project.targets.each do |target| - if target.respond_to?(:product_type) and target.product_type == "com.apple.product-type.bundle" - target.build_configurations.each do |config| - config.build_settings['CODE_SIGN_IDENTITY[sdk=macosx*]'] = '-' - end - end - end - - installer.aggregate_targets.each do |aggregate_target| - aggregate_target.user_project.native_targets.each do |target| - target.build_configurations.each do |config| - # Explicitly set dead code stripping flag - config.build_settings['DEAD_CODE_STRIPPING'] = 'YES' - # Modify library search paths - config.build_settings['LIBRARY_SEARCH_PATHS'] = ['$(SDKROOT)/usr/lib/swift', '$(SDKROOT)/System/iOSSupport/usr/lib/swift', '$(inherited)'] - end - end - aggregate_target.user_project.save - end + ReactNativePodsUtils.apply_mac_catalyst_patches(installer) end # Monkeypatch of `Pod::Lockfile` to ensure automatic update of dependencies integrated with a local podspec when their version changed. From 6b261b85ab3e7f86472da0e1c52f12ce569f3ba0 Mon Sep 17 00:00:00 2001 From: Arkkeeper Date: Wed, 29 Jun 2022 18:28:07 +0300 Subject: [PATCH 3/6] mac_catalyst_enabled flag --- packages/rn-tester/Podfile | 3 ++- scripts/react_native_pods.rb | 11 +++++------ template/ios/Podfile | 8 +++++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/rn-tester/Podfile b/packages/rn-tester/Podfile index 24130f1874ce5c..c1578100963236 100644 --- a/packages/rn-tester/Podfile +++ b/packages/rn-tester/Podfile @@ -21,6 +21,7 @@ def pods(options = {}, use_flipper: false) project 'RNTesterPods.xcodeproj' fabric_enabled = true + mac_catalyst_enabled = false hermes_enabled = ENV['USE_HERMES'] == '1' puts "Building RNTester with Fabric #{fabric_enabled ? "enabled" : "disabled"}.#{hermes_enabled ? " Using Hermes engine." : ""}" @@ -64,6 +65,6 @@ target 'RNTesterIntegrationTests' do end post_install do |installer| - react_native_post_install(installer, @prefix_path) + react_native_post_install(installer, mac_catalyst_enabled, @prefix_path) __apply_Xcode_12_5_M1_post_install_workaround(installer) end diff --git a/scripts/react_native_pods.rb b/scripts/react_native_pods.rb index a9a4cb8acff51b..0d5fd6b78e9f2a 100644 --- a/scripts/react_native_pods.rb +++ b/scripts/react_native_pods.rb @@ -140,7 +140,11 @@ def use_flipper!(versions = {}, configurations: ['Debug']) use_flipper_pods(versions, :configurations => configurations) end -def react_native_post_install(installer, react_native_path = "../node_modules/react-native") +def react_native_post_install(installer, mac_catalyst_enabled, react_native_path = "../node_modules/react-native") + if mac_catalyst_enabled + ReactNativePodsUtils.apply_mac_catalyst_patches(installer) + end + if ReactNativePodsUtils.has_pod(installer, 'Flipper') flipper_post_install(installer) end @@ -498,11 +502,6 @@ def __apply_Xcode_12_5_M1_post_install_workaround(installer) `sed -i -e $'s/ && (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_10_0)//' #{time_header}` end -# Apply three patches necessary for successful building and archiving RN on Mac Catalyst targets -def __apply_mac_catalyst_patches(installer) - ReactNativePodsUtils.apply_mac_catalyst_patches(installer) -end - # Monkeypatch of `Pod::Lockfile` to ensure automatic update of dependencies integrated with a local podspec when their version changed. # This is necessary because local podspec dependencies must be otherwise manually updated. module LocalPodspecPatch diff --git a/template/ios/Podfile b/template/ios/Podfile index 30cd2368214ba6..177d0e30ce33e3 100644 --- a/template/ios/Podfile +++ b/template/ios/Podfile @@ -31,9 +31,11 @@ target 'HelloWorld' do end post_install do |installer| - react_native_post_install(installer) + # Set `mac_catalyst_enabled` to `true` in order to apply patches necessary for Mac Catalyst builds + mac_catalyst_enabled = false + + react_native_post_install(installer, mac_catalyst_enabled) __apply_Xcode_12_5_M1_post_install_workaround(installer) - # Enable the next line in order to apply patches necessary for Mac Catalyst builds - #__apply_mac_catalyst_patches(installer) + end end From 2e163cd10ac5476fb1a81a34408df90b52a0d0de Mon Sep 17 00:00:00 2001 From: Arkkeeper Date: Wed, 29 Jun 2022 18:30:53 +0300 Subject: [PATCH 4/6] Mac Catalyst tests fixed --- .../__tests__/test_utils/InstallerMock.rb | 6 ++- scripts/cocoapods/__tests__/utils-test.rb | 38 +++++++++---------- scripts/cocoapods/utils.rb | 4 +- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/scripts/cocoapods/__tests__/test_utils/InstallerMock.rb b/scripts/cocoapods/__tests__/test_utils/InstallerMock.rb index c09f0659b6fe83..59a3aef80b40e7 100644 --- a/scripts/cocoapods/__tests__/test_utils/InstallerMock.rb +++ b/scripts/cocoapods/__tests__/test_utils/InstallerMock.rb @@ -138,12 +138,16 @@ def save_as(file_path) class TargetMock attr_reader :name attr_reader :build_configurations + attr_reader :product_type attr_reader :received_resolved_build_setting_parameters - def initialize(name, build_configurations = []) + def initialize(name, build_configurations = [], product_type = nil) @name = name @build_configurations = build_configurations + unless product_type.nil? + @product_type = product_type + end @received_resolved_build_setting_parameters = [] end diff --git a/scripts/cocoapods/__tests__/utils-test.rb b/scripts/cocoapods/__tests__/utils-test.rb index c3c90b1fde1013..40f5895c0cf064 100644 --- a/scripts/cocoapods/__tests__/utils-test.rb +++ b/scripts/cocoapods/__tests__/utils-test.rb @@ -250,20 +250,20 @@ def test_fixLibrarySearchPath_whenThereAreSearchPathsAndNoSwift_removesSwift5_5A # ============================== # def test_fixLibrarySearchPaths_correctlySetsTheSearchPathsForAllProjects - firstTarget = prepare_target("FirstTarget") - secondTarget = prepare_target("SecondTarget") - thirdTarget = prepare_target("ThirdTarget") + first_target = prepare_target("FirstTarget") + second_target = prepare_target("SecondTarget") + third_target = prepare_target("ThirdTarget") user_project_mock = UserProjectMock.new("a/path", [ prepare_config("Debug"), prepare_config("Release"), ], :native_targets => [ - firstTarget, - secondTarget + first_target, + second_target ] ) pods_projects_mock = PodsProjectMock.new([], {"hermes-engine" => {}}, :native_targets => [ - thirdTarget + third_target ]) installer = InstallerMock.new(pods_projects_mock, [ AggregatedProjectMock.new(user_project_mock) @@ -304,21 +304,19 @@ def test_fixLibrarySearchPaths_correctlySetsTheSearchPathsForAllProjects # ================================= # def test_applyMacCatalystPatches_correctlyAppliesNecessaryPatches - firstTarget = prepare_target("FirstTarget") - secondTarget = prepare_target("SecondTarget") - thirdTarget = prepare_target("ThirdTarget") + first_target = prepare_target("FirstTarget") + second_target = prepare_target("SecondTarget") + third_target = prepare_target("ThirdTarget", "com.apple.product-type.bundle") user_project_mock = UserProjectMock.new("a/path", [ prepare_config("Debug"), prepare_config("Release"), ], :native_targets => [ - firstTarget, - secondTarget + first_target, + second_target ] ) - pods_projects_mock = PodsProjectMock.new([], {"hermes-engine" => {}}, :native_targets => [ - thirdTarget - ]) + pods_projects_mock = PodsProjectMock.new([third_target], {"hermes-engine" => {}}, :native_targets => []) installer = InstallerMock.new(pods_projects_mock, [ AggregatedProjectMock.new(user_project_mock) ]) @@ -344,7 +342,7 @@ def test_applyMacCatalystPatches_correctlyAppliesNecessaryPatches end assert_equal(user_project_mock.save_invocation_count, 1) - end + end # ==================================== # # Test - Set Node_Modules User Setting # @@ -388,9 +386,9 @@ def prepare_config(config_name) ]}) end -def prepare_target(name) - return TargetMock.new(name, [ - prepare_config("Debug"), - prepare_config("Release") - ]) +def prepare_target(name, product_type = nil) + return TargetMock.new(name, [ + prepare_config("Debug"), + prepare_config("Release") + ], product_type) end diff --git a/scripts/cocoapods/utils.rb b/scripts/cocoapods/utils.rb index ed720ed512c93b..d0fa21c7c700ad 100644 --- a/scripts/cocoapods/utils.rb +++ b/scripts/cocoapods/utils.rb @@ -111,9 +111,9 @@ def self.apply_mac_catalyst_patches(installer) config.build_settings['PRESERVE_DEAD_CODE_INITS_AND_TERMS'] = 'YES' # Modify library search paths config.build_settings['LIBRARY_SEARCH_PATHS'] = ['$(SDKROOT)/usr/lib/swift', '$(SDKROOT)/System/iOSSupport/usr/lib/swift', '$(inherited)'] - end + end end - aggregate_target.user_project.save + aggregate_target.user_project.save() end end From e56e5c6b47e052df46b0c5c10c1c022153a76f1e Mon Sep 17 00:00:00 2001 From: Arkkeeper Date: Thu, 30 Jun 2022 10:19:06 +0300 Subject: [PATCH 5/6] Fix for rn-tester Podfile --- packages/rn-tester/Podfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rn-tester/Podfile b/packages/rn-tester/Podfile index c1578100963236..8d164e3750ca44 100644 --- a/packages/rn-tester/Podfile +++ b/packages/rn-tester/Podfile @@ -21,7 +21,6 @@ def pods(options = {}, use_flipper: false) project 'RNTesterPods.xcodeproj' fabric_enabled = true - mac_catalyst_enabled = false hermes_enabled = ENV['USE_HERMES'] == '1' puts "Building RNTester with Fabric #{fabric_enabled ? "enabled" : "disabled"}.#{hermes_enabled ? " Using Hermes engine." : ""}" @@ -65,6 +64,7 @@ target 'RNTesterIntegrationTests' do end post_install do |installer| + mac_catalyst_enabled = false react_native_post_install(installer, mac_catalyst_enabled, @prefix_path) __apply_Xcode_12_5_M1_post_install_workaround(installer) end From 6b6ed3faf4d8008b20aa091d5f49e0017065260a Mon Sep 17 00:00:00 2001 From: Arkkeeper Date: Thu, 30 Jun 2022 12:54:33 +0300 Subject: [PATCH 6/6] Improvements for Mac Catalyst patches & tests --- packages/rn-tester/Podfile | 4 +--- scripts/cocoapods/__tests__/utils-test.rb | 16 ++++++++++------ scripts/react_native_pods.rb | 6 ++---- template/ios/Podfile | 11 ++++++----- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/packages/rn-tester/Podfile b/packages/rn-tester/Podfile index d101d4f23745e0..d50d388be19208 100644 --- a/packages/rn-tester/Podfile +++ b/packages/rn-tester/Podfile @@ -21,7 +21,6 @@ def pods(options = {}, use_flipper: false) project 'RNTesterPods.xcodeproj' fabric_enabled = true - mac_catalyst_enabled = false # Hermes is now enabled by default. # The following line will only disable Hermes if the USE_HERMES envvar is SET to a value other than 1 (e.g. USE_HERMES=0). @@ -68,7 +67,6 @@ target 'RNTesterIntegrationTests' do end post_install do |installer| - mac_catalyst_enabled = false - react_native_post_install(installer, mac_catalyst_enabled, @prefix_path) + react_native_post_install(installer, @prefix_path, :mac_catalyst_enabled => false) __apply_Xcode_12_5_M1_post_install_workaround(installer) end diff --git a/scripts/cocoapods/__tests__/utils-test.rb b/scripts/cocoapods/__tests__/utils-test.rb index 24c447f726ad8b..b4cbaddca9d465 100644 --- a/scripts/cocoapods/__tests__/utils-test.rb +++ b/scripts/cocoapods/__tests__/utils-test.rb @@ -341,12 +341,16 @@ def test_applyMacCatalystPatches_correctlyAppliesNecessaryPatches ReactNativePodsUtils.apply_mac_catalyst_patches(installer) # Assert - pods_projects_mock.targets.each do |target| - if target.respond_to?(:product_type) and target.product_type == "com.apple.product-type.bundle" - target.build_configurations.each do |config| - assert_equal(config.build_settings["CODE_SIGN_IDENTITY[sdk=macosx*]"], "-") - end - end + first_target.build_configurations.each do |config| + assert_nil(config.build_settings["CODE_SIGN_IDENTITY[sdk=macosx*]"]) + end + + second_target.build_configurations.each do |config| + assert_nil(config.build_settings["CODE_SIGN_IDENTITY[sdk=macosx*]"]) + end + + third_target.build_configurations.each do |config| + assert_equal(config.build_settings["CODE_SIGN_IDENTITY[sdk=macosx*]"], "-") end user_project_mock.native_targets.each do |target| diff --git a/scripts/react_native_pods.rb b/scripts/react_native_pods.rb index 9526589960e8d6..c3ca45a2394709 100644 --- a/scripts/react_native_pods.rb +++ b/scripts/react_native_pods.rb @@ -141,10 +141,8 @@ def use_flipper!(versions = {}, configurations: ['Debug']) use_flipper_pods(versions, :configurations => configurations) end -def react_native_post_install(installer, mac_catalyst_enabled, react_native_path = "../node_modules/react-native") - if mac_catalyst_enabled - ReactNativePodsUtils.apply_mac_catalyst_patches(installer) - end +def react_native_post_install(installer, react_native_path = "../node_modules/react-native", mac_catalyst_enabled: false) + ReactNativePodsUtils.apply_mac_catalyst_patches(installer) if mac_catalyst_enabled if ReactNativePodsUtils.has_pod(installer, 'Flipper') flipper_post_install(installer) diff --git a/template/ios/Podfile b/template/ios/Podfile index f32d7c125b8acf..92e7ee1919e671 100644 --- a/template/ios/Podfile +++ b/template/ios/Podfile @@ -32,11 +32,12 @@ target 'HelloWorld' do end post_install do |installer| - # Set `mac_catalyst_enabled` to `true` in order to apply patches necessary for Mac Catalyst builds - mac_catalyst_enabled = false - - react_native_post_install(installer, mac_catalyst_enabled) + react_native_post_install( + installer, + # Set `mac_catalyst_enabled` to `true` in order to apply patches + # necessary for Mac Catalyst builds + :mac_catalyst_enabled => false + ) __apply_Xcode_12_5_M1_post_install_workaround(installer) - end end