Skip to content

Commit 462fae4

Browse files
benhandanyanfacebook-github-bot
authored andcommitted
Use configuration type when adding ndebug flag to pods in release (facebook#48193)
Summary: While I was [working on fixing the iOS debugger logic](facebook#48174) based on configuration name regex match, I wanted to know if other logic was also based on configuration names. I think I found and fixed the only other configuration name-based logic in the repo in this PR. ## 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] [CHANGED] - Use configuration type when adding ndebug flag to pods in release Pull Request resolved: facebook#48193 Test Plan: In a fresh react-native project, I added to the Podfile: ```ruby installer.aggregate_targets.each do |aggregate_target| aggregate_target.xcconfigs.each do |config_name, config_file| is_release = aggregate_target.user_build_configurations[config_name] == :release puts "aggregate_targets #{config_name} is_release: #{is_release}" end end 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.type == :release puts "target_installation_results #{config.name} is_release: #{is_release}" end end ``` to confirm my logic. It output the following: ``` aggregate_targets Release is_release: true aggregate_targets Local is_release: false ... target_installation_results Local is_release: false target_installation_results Release is_release: true ... ``` I also updated the applicable tests I could find for this logic. Reviewed By: cortinico Differential Revision: D67025325 Pulled By: cipolleschi fbshipit-source-id: 45d68ee86e3255d843275a72916883c8c4bbc13d
1 parent 7d771de commit 462fae4

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

packages/react-native/scripts/cocoapods/__tests__/new_architecture-test.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,16 +524,20 @@ def prepare_installer_for_cpp_flags(xcconfigs, build_configs)
524524
end
525525

526526
pod_target_installation_results_map = {}
527+
user_build_configuration_map = {}
527528
build_configs.each do |name, build_configs|
528529
pod_target_installation_results_map[name.to_s] = prepare_pod_target_installation_results_mock(
529530
name.to_s, build_configs
530531
)
532+
build_configs.each do |config|
533+
user_build_configuration_map[config.name] = config
534+
end
531535
end
532536

533537
return InstallerMock.new(
534538
PodsProjectMock.new,
535539
[
536-
AggregatedProjectMock.new(:xcconfigs => xcconfigs_map, :base_path => "a/path/")
540+
AggregatedProjectMock.new(:xcconfigs => xcconfigs_map, :base_path => "a/path/", :user_build_configurations => user_build_configuration_map)
537541
],
538542
:pod_target_installation_results => pod_target_installation_results_map
539543
)

packages/react-native/scripts/cocoapods/__tests__/test_utils/InstallerMock.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,15 @@ def save()
9696
class AggregatedProjectMock
9797
attr_reader :user_project
9898
attr_reader :xcconfigs
99+
attr_reader :user_build_configurations
99100

100101
@base_path
101102

102-
def initialize(user_project = UserProjectMock.new, xcconfigs: {}, base_path: "")
103+
def initialize(user_project = UserProjectMock.new, xcconfigs: {}, base_path: "", user_build_configurations: {})
103104
@user_project = user_project
104105
@xcconfigs = xcconfigs
105106
@base_path = base_path
107+
@user_build_configurations = user_build_configurations
106108
end
107109

108110
def xcconfig_path(config_name)
@@ -199,7 +201,7 @@ def debug?
199201
end
200202

201203
def type
202-
@is_debug ? :debug : :release
204+
return @is_debug ? :debug : :release
203205
end
204206
end
205207

packages/react-native/scripts/cocoapods/__tests__/utils-test.rb

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,19 +1153,21 @@ def test_add_flag_to_map_with_inheritance_whenUsedWithArrayAttributes
11531153
def test_add_ndebug_flag_to_pods_in_release
11541154
# Arrange
11551155
xcconfig = XCConfigMock.new("Config")
1156-
default_debug_config = BuildConfigurationMock.new("Debug")
1157-
default_release_config = BuildConfigurationMock.new("Release")
1158-
custom_debug_config1 = BuildConfigurationMock.new("CustomDebug")
1159-
custom_debug_config2 = BuildConfigurationMock.new("Custom")
1160-
custom_release_config1 = BuildConfigurationMock.new("CustomRelease")
1161-
custom_release_config2 = BuildConfigurationMock.new("Production")
1156+
default_debug_config = BuildConfigurationMock.new("Debug", {}, is_debug: true)
1157+
default_release_config = BuildConfigurationMock.new("Release", {}, is_debug: false)
1158+
custom_debug_config1 = BuildConfigurationMock.new("CustomDebug", {}, is_debug: true)
1159+
custom_debug_config2 = BuildConfigurationMock.new("Custom", {}, is_debug: true)
1160+
custom_release_config1 = BuildConfigurationMock.new("CustomRelease", {}, is_debug: false)
1161+
custom_release_config2 = BuildConfigurationMock.new("Production", {}, is_debug: false)
1162+
custom_release_config3 = BuildConfigurationMock.new("Main", {}, is_debug: false)
11621163

11631164
installer = prepare_installer_for_cpp_flags(
11641165
[ xcconfig ],
11651166
{
11661167
"Default" => [ default_debug_config, default_release_config ],
11671168
"Custom1" => [ custom_debug_config1, custom_release_config1 ],
1168-
"Custom2" => [ custom_debug_config2, custom_release_config2 ]
1169+
"Custom2" => [ custom_debug_config2, custom_release_config2 ],
1170+
"Custom3" => [ custom_release_config3 ],
11691171
}
11701172
)
11711173
# Act
@@ -1178,6 +1180,7 @@ def test_add_ndebug_flag_to_pods_in_release
11781180
assert_equal("$(inherited) -DNDEBUG", custom_release_config1.build_settings["OTHER_CPLUSPLUSFLAGS"])
11791181
assert_equal(nil, custom_debug_config2.build_settings["OTHER_CPLUSPLUSFLAGS"])
11801182
assert_equal("$(inherited) -DNDEBUG", custom_release_config2.build_settings["OTHER_CPLUSPLUSFLAGS"])
1183+
assert_equal("$(inherited) -DNDEBUG", custom_release_config3.build_settings["OTHER_CPLUSPLUSFLAGS"])
11811184
end
11821185
end
11831186

@@ -1234,16 +1237,20 @@ def prepare_installer_for_cpp_flags(xcconfigs, build_configs)
12341237
end
12351238

12361239
pod_target_installation_results_map = {}
1240+
user_build_configuration_map = {}
12371241
build_configs.each do |name, build_configs|
12381242
pod_target_installation_results_map[name.to_s] = prepare_pod_target_installation_results_mock(
12391243
name.to_s, build_configs
12401244
)
1245+
build_configs.each do |config|
1246+
user_build_configuration_map[config.name] = config
1247+
end
12411248
end
12421249

12431250
return InstallerMock.new(
12441251
PodsProjectMock.new,
12451252
[
1246-
AggregatedProjectMock.new(:xcconfigs => xcconfigs_map, :base_path => "a/path/")
1253+
AggregatedProjectMock.new(:xcconfigs => xcconfigs_map, :base_path => "a/path/", :user_build_configurations => user_build_configuration_map)
12471254
],
12481255
:pod_target_installation_results => pod_target_installation_results_map
12491256
)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ def self.add_ndebug_flag_to_pods_in_release(installer)
664664

665665
installer.aggregate_targets.each do |aggregate_target|
666666
aggregate_target.xcconfigs.each do |config_name, config_file|
667-
is_release = config_name.downcase.include?("release") || config_name.downcase.include?("production")
667+
is_release = aggregate_target.user_build_configurations[config_name] == :release
668668
unless is_release
669669
next
670670
end
@@ -678,7 +678,7 @@ def self.add_ndebug_flag_to_pods_in_release(installer)
678678

679679
installer.target_installation_results.pod_target_installation_results.each do |pod_name, target_installation_result|
680680
target_installation_result.native_target.build_configurations.each do |config|
681-
is_release = config.name.downcase.include?("release") || config.name.downcase.include?("production")
681+
is_release = config.type == :release
682682
unless is_release
683683
next
684684
end

0 commit comments

Comments
 (0)