Skip to content

Commit 93fdcba

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Drop the requirement to use PRODUCTION=1 to add -NDEBUG
Summary: The previous fix for -DNDEBUG required to install the pods with PRODUCTION=1 in order to add the flag. The flag was added also to Debug configurations, which is not ideal. With this change, we remove the requirement of running `PRODUCTION=1 pod install` and we install the -DNDEBUG flag to all the release configurations. ## Changelog: [iOS][Changed] - Install the -DNDEBUG flag on Release configurations, without requiring PRODUCTION=1 flag Reviewed By: cortinico Differential Revision: D43535620 fbshipit-source-id: af97bef06f267dddd5ce13a466bbc8d9a5eb2b0b
1 parent c1304d9 commit 93fdcba

File tree

3 files changed

+20
-44
lines changed

3 files changed

+20
-44
lines changed

scripts/cocoapods/__tests__/new_architecture-test.rb

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def test_modifyFlagsForNewArch_whenOnOldArch_doNothing
8181
assert_equal(yoga_release_config.build_settings["OTHER_CPLUSPLUSFLAGS"], "$(inherited)")
8282
end
8383

84-
def test_modifyFlagsForNewArch_whenOnNewArch_updateFlags
84+
def test_modifyFlagsForNewArch_whenOnNewArchAndIsRelease_updateFlags
8585
# Arrange
8686
first_xcconfig = prepare_xcconfig("First")
8787
second_xcconfig = prepare_xcconfig("Second")
@@ -102,47 +102,17 @@ def test_modifyFlagsForNewArch_whenOnNewArch_updateFlags
102102

103103
# Assert
104104
assert_equal(first_xcconfig.attributes["OTHER_CPLUSPLUSFLAGS"], "$(inherited) -DRCT_NEW_ARCH_ENABLED=1 -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1")
105+
assert_nil(first_xcconfig.attributes["OTHER_CFLAGS"])
105106
assert_equal(first_xcconfig.save_as_invocation, ["a/path/First.xcconfig"])
106107
assert_equal(second_xcconfig.attributes["OTHER_CPLUSPLUSFLAGS"], "$(inherited) -DRCT_NEW_ARCH_ENABLED=1 -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1")
108+
assert_nil(second_xcconfig.attributes["OTHER_CFLAGS"])
107109
assert_equal(second_xcconfig.save_as_invocation, ["a/path/Second.xcconfig"])
108110
assert_equal(react_core_debug_config.build_settings["OTHER_CPLUSPLUSFLAGS"], "$(inherited) -DRCT_NEW_ARCH_ENABLED=1 -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1")
109-
assert_equal(react_core_release_config.build_settings["OTHER_CPLUSPLUSFLAGS"], "$(inherited) -DRCT_NEW_ARCH_ENABLED=1 -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1")
110-
assert_equal(yoga_debug_config.build_settings["OTHER_CPLUSPLUSFLAGS"], "$(inherited)")
111-
assert_equal(yoga_release_config.build_settings["OTHER_CPLUSPLUSFLAGS"], "$(inherited)")
112-
end
113-
114-
def test_modifyFlagsForNewArch_whenOnNewArchAndIsRelease_updateFlags
115-
# Arrange
116-
first_xcconfig = prepare_xcconfig("First")
117-
second_xcconfig = prepare_xcconfig("Second")
118-
react_core_debug_config = prepare_CXX_Flags_build_configuration("Debug")
119-
react_core_release_config = prepare_CXX_Flags_build_configuration("Release")
120-
yoga_debug_config = prepare_CXX_Flags_build_configuration("Debug")
121-
yoga_release_config = prepare_CXX_Flags_build_configuration("Release")
122-
123-
installer = prepare_installer_for_cpp_flags(
124-
[ first_xcconfig, second_xcconfig ],
125-
{
126-
"React-Core" => [ react_core_debug_config, react_core_release_config ],
127-
"Yoga" => [ yoga_debug_config, yoga_release_config ],
128-
}
129-
)
130-
# Act
131-
NewArchitectureHelper.modify_flags_for_new_architecture(installer, true, is_release: true)
132-
133-
# Assert
134-
assert_equal(first_xcconfig.attributes["OTHER_CPLUSPLUSFLAGS"], "$(inherited) -DRCT_NEW_ARCH_ENABLED=1 -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -DNDEBUG")
135-
assert_equal(first_xcconfig.attributes["OTHER_CFLAGS"], "$(inherited) -DNDEBUG")
136-
assert_equal(first_xcconfig.save_as_invocation, ["a/path/First.xcconfig"])
137-
assert_equal(second_xcconfig.attributes["OTHER_CPLUSPLUSFLAGS"], "$(inherited) -DRCT_NEW_ARCH_ENABLED=1 -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -DNDEBUG")
138-
assert_equal(second_xcconfig.attributes["OTHER_CFLAGS"], "$(inherited) -DNDEBUG")
139-
assert_equal(second_xcconfig.save_as_invocation, ["a/path/Second.xcconfig"])
140-
assert_equal(react_core_debug_config.build_settings["OTHER_CPLUSPLUSFLAGS"], "$(inherited) -DRCT_NEW_ARCH_ENABLED=1 -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -DNDEBUG")
141-
assert_equal(react_core_debug_config.build_settings["OTHER_CFLAGS"], "$(inherited) -DNDEBUG")
111+
assert_nil(react_core_debug_config.build_settings["OTHER_CFLAGS"])
142112
assert_equal(react_core_release_config.build_settings["OTHER_CPLUSPLUSFLAGS"], "$(inherited) -DRCT_NEW_ARCH_ENABLED=1 -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -DNDEBUG")
143113
assert_equal(react_core_release_config.build_settings["OTHER_CFLAGS"], "$(inherited) -DNDEBUG")
144-
assert_equal(yoga_debug_config.build_settings["OTHER_CPLUSPLUSFLAGS"], "$(inherited) -DNDEBUG")
145-
assert_equal(yoga_debug_config.build_settings["OTHER_CFLAGS"], "$(inherited) -DNDEBUG")
114+
assert_equal(yoga_debug_config.build_settings["OTHER_CPLUSPLUSFLAGS"], "$(inherited)")
115+
assert_nil(yoga_debug_config.build_settings["OTHER_CFLAGS"])
146116
assert_equal(yoga_release_config.build_settings["OTHER_CPLUSPLUSFLAGS"], "$(inherited) -DNDEBUG")
147117
assert_equal(yoga_release_config.build_settings["OTHER_CFLAGS"], "$(inherited) -DNDEBUG")
148118
end

scripts/cocoapods/new_architecture.rb

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,20 @@ def self.set_clang_cxx_language_standard_if_needed(installer)
3838
end
3939
end
4040

41-
def self.modify_flags_for_new_architecture(installer, is_new_arch_enabled, is_release: false)
41+
def self.modify_flags_for_new_architecture(installer, is_new_arch_enabled)
4242
unless is_new_arch_enabled
4343
return
4444
end
45-
ndebug_flag = (is_release ? " -DNDEBUG" : "")
45+
ndebug_flag = " -DNDEBUG"
4646
# Add RCT_NEW_ARCH_ENABLED to Target pods xcconfig
4747
installer.aggregate_targets.each do |aggregate_target|
4848
aggregate_target.xcconfigs.each do |config_name, config_file|
49-
config_file.attributes['OTHER_CPLUSPLUSFLAGS'] = @@new_arch_cpp_flags + ndebug_flag
50-
config_file.attributes['OTHER_CFLAGS'] = "$(inherited)" + ndebug_flag
49+
config_file.attributes['OTHER_CPLUSPLUSFLAGS'] = @@new_arch_cpp_flags
50+
51+
if config_name == "Release"
52+
config_file.attributes['OTHER_CPLUSPLUSFLAGS'] = config_file.attributes['OTHER_CPLUSPLUSFLAGS'] + ndebug_flag
53+
config_file.attributes['OTHER_CFLAGS'] = "$(inherited)" + ndebug_flag
54+
end
5155

5256
xcconfig_path = aggregate_target.xcconfig_path(config_name)
5357
config_file.save_as(xcconfig_path)
@@ -63,9 +67,11 @@ def self.modify_flags_for_new_architecture(installer, is_new_arch_enabled, is_re
6367
end
6468

6569
target_installation_result.native_target.build_configurations.each do |config|
66-
current_flags = config.build_settings['OTHER_CPLUSPLUSFLAGS'] != nil ? config.build_settings['OTHER_CPLUSPLUSFLAGS'] : ""
67-
config.build_settings['OTHER_CPLUSPLUSFLAGS'] = current_flags + ndebug_flag
68-
config.build_settings['OTHER_CFLAGS'] = "$(inherited)" + ndebug_flag
70+
if config.name == "Release"
71+
current_flags = config.build_settings['OTHER_CPLUSPLUSFLAGS'] != nil ? config.build_settings['OTHER_CPLUSPLUSFLAGS'] : ""
72+
config.build_settings['OTHER_CPLUSPLUSFLAGS'] = current_flags + ndebug_flag
73+
config.build_settings['OTHER_CFLAGS'] = "$(inherited)" + ndebug_flag
74+
end
6975
end
7076
end
7177
end

scripts/react_native_pods.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def react_native_post_install(installer, react_native_path = "../node_modules/re
222222

223223
NewArchitectureHelper.set_clang_cxx_language_standard_if_needed(installer)
224224
is_new_arch_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == "1"
225-
NewArchitectureHelper.modify_flags_for_new_architecture(installer, is_new_arch_enabled, is_release: ENV['PRODUCTION'] == "1")
225+
NewArchitectureHelper.modify_flags_for_new_architecture(installer, is_new_arch_enabled)
226226

227227
Pod::UI.puts "Pod install took #{Time.now.to_i - $START_TIME} [s] to run".green
228228
end

0 commit comments

Comments
 (0)