From 86ddfb659545a07abbda3f93e2bd8516c576c036 Mon Sep 17 00:00:00 2001 From: Ben Handanyan Date: Mon, 9 Dec 2024 21:06:51 -0500 Subject: [PATCH 1/2] [iOS] Use configuration type when adding ndebug flag to pods in release --- .../__tests__/new_architecture-test.rb | 6 ++++- .../__tests__/test_utils/InstallerMock.rb | 6 +++-- .../scripts/cocoapods/__tests__/utils-test.rb | 23 ++++++++++++------- .../react-native/scripts/cocoapods/utils.rb | 4 ++-- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/packages/react-native/scripts/cocoapods/__tests__/new_architecture-test.rb b/packages/react-native/scripts/cocoapods/__tests__/new_architecture-test.rb index 6a7d5f7cb8b6d6..c5cadd975d594e 100644 --- a/packages/react-native/scripts/cocoapods/__tests__/new_architecture-test.rb +++ b/packages/react-native/scripts/cocoapods/__tests__/new_architecture-test.rb @@ -524,16 +524,20 @@ def prepare_installer_for_cpp_flags(xcconfigs, build_configs) end pod_target_installation_results_map = {} + user_build_configuration_map = {} build_configs.each do |name, build_configs| pod_target_installation_results_map[name.to_s] = prepare_pod_target_installation_results_mock( name.to_s, build_configs ) + build_configs.each do |config| + user_build_configuration_map[config.name] = config + end end return InstallerMock.new( PodsProjectMock.new, [ - AggregatedProjectMock.new(:xcconfigs => xcconfigs_map, :base_path => "a/path/") + AggregatedProjectMock.new(:xcconfigs => xcconfigs_map, :base_path => "a/path/", :user_build_configurations => user_build_configuration_map) ], :pod_target_installation_results => pod_target_installation_results_map ) diff --git a/packages/react-native/scripts/cocoapods/__tests__/test_utils/InstallerMock.rb b/packages/react-native/scripts/cocoapods/__tests__/test_utils/InstallerMock.rb index c06cb592e0a68a..318c349cacfff4 100644 --- a/packages/react-native/scripts/cocoapods/__tests__/test_utils/InstallerMock.rb +++ b/packages/react-native/scripts/cocoapods/__tests__/test_utils/InstallerMock.rb @@ -96,13 +96,15 @@ def save() class AggregatedProjectMock attr_reader :user_project attr_reader :xcconfigs + attr_reader :user_build_configurations @base_path - def initialize(user_project = UserProjectMock.new, xcconfigs: {}, base_path: "") + def initialize(user_project = UserProjectMock.new, xcconfigs: {}, base_path: "", user_build_configurations: {}) @user_project = user_project @xcconfigs = xcconfigs @base_path = base_path + @user_build_configurations = user_build_configurations end def xcconfig_path(config_name) @@ -199,7 +201,7 @@ def debug? end def type - @is_debug ? :debug : :release + return @is_debug ? :debug : :release end end diff --git a/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb b/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb index 821a702bcad972..a167613e3cc231 100644 --- a/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb +++ b/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb @@ -1153,19 +1153,21 @@ def test_add_flag_to_map_with_inheritance_whenUsedWithArrayAttributes def test_add_ndebug_flag_to_pods_in_release # Arrange xcconfig = XCConfigMock.new("Config") - default_debug_config = BuildConfigurationMock.new("Debug") - default_release_config = BuildConfigurationMock.new("Release") - custom_debug_config1 = BuildConfigurationMock.new("CustomDebug") - custom_debug_config2 = BuildConfigurationMock.new("Custom") - custom_release_config1 = BuildConfigurationMock.new("CustomRelease") - custom_release_config2 = BuildConfigurationMock.new("Production") + default_debug_config = BuildConfigurationMock.new("Debug", {}, is_debug: true) + default_release_config = BuildConfigurationMock.new("Release", {}, is_debug: false) + custom_debug_config1 = BuildConfigurationMock.new("CustomDebug", {}, is_debug: true) + custom_debug_config2 = BuildConfigurationMock.new("Custom", {}, is_debug: true) + custom_release_config1 = BuildConfigurationMock.new("CustomRelease", {}, is_debug: false) + custom_release_config2 = BuildConfigurationMock.new("Production", {}, is_debug: false) + custom_release_config_3 = BuildConfigurationMock.new("Main", {}, is_debug: false) installer = prepare_installer_for_cpp_flags( [ xcconfig ], { "Default" => [ default_debug_config, default_release_config ], "Custom1" => [ custom_debug_config1, custom_release_config1 ], - "Custom2" => [ custom_debug_config2, custom_release_config2 ] + "Custom2" => [ custom_debug_config2, custom_release_config2 ], + "Custom3" => [ custom_release_config_3 ], } ) # Act @@ -1178,6 +1180,7 @@ def test_add_ndebug_flag_to_pods_in_release assert_equal("$(inherited) -DNDEBUG", custom_release_config1.build_settings["OTHER_CPLUSPLUSFLAGS"]) assert_equal(nil, custom_debug_config2.build_settings["OTHER_CPLUSPLUSFLAGS"]) assert_equal("$(inherited) -DNDEBUG", custom_release_config2.build_settings["OTHER_CPLUSPLUSFLAGS"]) + assert_equal("$(inherited) -DNDEBUG", custom_release_config_3.build_settings["OTHER_CPLUSPLUSFLAGS"]) end end @@ -1234,16 +1237,20 @@ def prepare_installer_for_cpp_flags(xcconfigs, build_configs) end pod_target_installation_results_map = {} + user_build_configuration_map = {} build_configs.each do |name, build_configs| pod_target_installation_results_map[name.to_s] = prepare_pod_target_installation_results_mock( name.to_s, build_configs ) + build_configs.each do |config| + user_build_configuration_map[config.name] = config + end end return InstallerMock.new( PodsProjectMock.new, [ - AggregatedProjectMock.new(:xcconfigs => xcconfigs_map, :base_path => "a/path/") + AggregatedProjectMock.new(:xcconfigs => xcconfigs_map, :base_path => "a/path/", :user_build_configurations => user_build_configuration_map) ], :pod_target_installation_results => pod_target_installation_results_map ) diff --git a/packages/react-native/scripts/cocoapods/utils.rb b/packages/react-native/scripts/cocoapods/utils.rb index 4ce64600cb1a91..9cf9eeac260f34 100644 --- a/packages/react-native/scripts/cocoapods/utils.rb +++ b/packages/react-native/scripts/cocoapods/utils.rb @@ -664,7 +664,7 @@ def self.add_ndebug_flag_to_pods_in_release(installer) installer.aggregate_targets.each do |aggregate_target| aggregate_target.xcconfigs.each do |config_name, config_file| - is_release = config_name.downcase.include?("release") || config_name.downcase.include?("production") + is_release = aggregate_target.user_build_configurations[config_name] == :release unless is_release next end @@ -678,7 +678,7 @@ def self.add_ndebug_flag_to_pods_in_release(installer) installer.target_installation_results.pod_target_installation_results.each do |pod_name, target_installation_result| target_installation_result.native_target.build_configurations.each do |config| - is_release = config.name.downcase.include?("release") || config.name.downcase.include?("production") + is_release = config.type == :release unless is_release next end From 04d66a87dd86ef1eda1ea9425758328e0d2009d0 Mon Sep 17 00:00:00 2001 From: Ben Handanyan Date: Mon, 9 Dec 2024 21:21:15 -0500 Subject: [PATCH 2/2] nit update --- .../react-native/scripts/cocoapods/__tests__/utils-test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb b/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb index a167613e3cc231..28b015008402d2 100644 --- a/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb +++ b/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb @@ -1159,7 +1159,7 @@ def test_add_ndebug_flag_to_pods_in_release custom_debug_config2 = BuildConfigurationMock.new("Custom", {}, is_debug: true) custom_release_config1 = BuildConfigurationMock.new("CustomRelease", {}, is_debug: false) custom_release_config2 = BuildConfigurationMock.new("Production", {}, is_debug: false) - custom_release_config_3 = BuildConfigurationMock.new("Main", {}, is_debug: false) + custom_release_config3 = BuildConfigurationMock.new("Main", {}, is_debug: false) installer = prepare_installer_for_cpp_flags( [ xcconfig ], @@ -1167,7 +1167,7 @@ def test_add_ndebug_flag_to_pods_in_release "Default" => [ default_debug_config, default_release_config ], "Custom1" => [ custom_debug_config1, custom_release_config1 ], "Custom2" => [ custom_debug_config2, custom_release_config2 ], - "Custom3" => [ custom_release_config_3 ], + "Custom3" => [ custom_release_config3 ], } ) # Act @@ -1180,7 +1180,7 @@ def test_add_ndebug_flag_to_pods_in_release assert_equal("$(inherited) -DNDEBUG", custom_release_config1.build_settings["OTHER_CPLUSPLUSFLAGS"]) assert_equal(nil, custom_debug_config2.build_settings["OTHER_CPLUSPLUSFLAGS"]) assert_equal("$(inherited) -DNDEBUG", custom_release_config2.build_settings["OTHER_CPLUSPLUSFLAGS"]) - assert_equal("$(inherited) -DNDEBUG", custom_release_config_3.build_settings["OTHER_CPLUSPLUSFLAGS"]) + assert_equal("$(inherited) -DNDEBUG", custom_release_config3.build_settings["OTHER_CPLUSPLUSFLAGS"]) end end