Skip to content

Commit

Permalink
Drop the requirement to use PRODUCTION=1 to add -NDEBUG
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cipolleschi authored and facebook-github-bot committed Feb 24, 2023
1 parent c1304d9 commit 93fdcba
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 44 deletions.
42 changes: 6 additions & 36 deletions scripts/cocoapods/__tests__/new_architecture-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_modifyFlagsForNewArch_whenOnOldArch_doNothing
assert_equal(yoga_release_config.build_settings["OTHER_CPLUSPLUSFLAGS"], "$(inherited)")
end

def test_modifyFlagsForNewArch_whenOnNewArch_updateFlags
def test_modifyFlagsForNewArch_whenOnNewArchAndIsRelease_updateFlags
# Arrange
first_xcconfig = prepare_xcconfig("First")
second_xcconfig = prepare_xcconfig("Second")
Expand All @@ -102,47 +102,17 @@ def test_modifyFlagsForNewArch_whenOnNewArch_updateFlags

# Assert
assert_equal(first_xcconfig.attributes["OTHER_CPLUSPLUSFLAGS"], "$(inherited) -DRCT_NEW_ARCH_ENABLED=1 -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1")
assert_nil(first_xcconfig.attributes["OTHER_CFLAGS"])
assert_equal(first_xcconfig.save_as_invocation, ["a/path/First.xcconfig"])
assert_equal(second_xcconfig.attributes["OTHER_CPLUSPLUSFLAGS"], "$(inherited) -DRCT_NEW_ARCH_ENABLED=1 -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1")
assert_nil(second_xcconfig.attributes["OTHER_CFLAGS"])
assert_equal(second_xcconfig.save_as_invocation, ["a/path/Second.xcconfig"])
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")
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")
assert_equal(yoga_debug_config.build_settings["OTHER_CPLUSPLUSFLAGS"], "$(inherited)")
assert_equal(yoga_release_config.build_settings["OTHER_CPLUSPLUSFLAGS"], "$(inherited)")
end

def test_modifyFlagsForNewArch_whenOnNewArchAndIsRelease_updateFlags
# Arrange
first_xcconfig = prepare_xcconfig("First")
second_xcconfig = prepare_xcconfig("Second")
react_core_debug_config = prepare_CXX_Flags_build_configuration("Debug")
react_core_release_config = prepare_CXX_Flags_build_configuration("Release")
yoga_debug_config = prepare_CXX_Flags_build_configuration("Debug")
yoga_release_config = prepare_CXX_Flags_build_configuration("Release")

installer = prepare_installer_for_cpp_flags(
[ first_xcconfig, second_xcconfig ],
{
"React-Core" => [ react_core_debug_config, react_core_release_config ],
"Yoga" => [ yoga_debug_config, yoga_release_config ],
}
)
# Act
NewArchitectureHelper.modify_flags_for_new_architecture(installer, true, is_release: true)

# Assert
assert_equal(first_xcconfig.attributes["OTHER_CPLUSPLUSFLAGS"], "$(inherited) -DRCT_NEW_ARCH_ENABLED=1 -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -DNDEBUG")
assert_equal(first_xcconfig.attributes["OTHER_CFLAGS"], "$(inherited) -DNDEBUG")
assert_equal(first_xcconfig.save_as_invocation, ["a/path/First.xcconfig"])
assert_equal(second_xcconfig.attributes["OTHER_CPLUSPLUSFLAGS"], "$(inherited) -DRCT_NEW_ARCH_ENABLED=1 -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -DNDEBUG")
assert_equal(second_xcconfig.attributes["OTHER_CFLAGS"], "$(inherited) -DNDEBUG")
assert_equal(second_xcconfig.save_as_invocation, ["a/path/Second.xcconfig"])
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")
assert_equal(react_core_debug_config.build_settings["OTHER_CFLAGS"], "$(inherited) -DNDEBUG")
assert_nil(react_core_debug_config.build_settings["OTHER_CFLAGS"])
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")
assert_equal(react_core_release_config.build_settings["OTHER_CFLAGS"], "$(inherited) -DNDEBUG")
assert_equal(yoga_debug_config.build_settings["OTHER_CPLUSPLUSFLAGS"], "$(inherited) -DNDEBUG")
assert_equal(yoga_debug_config.build_settings["OTHER_CFLAGS"], "$(inherited) -DNDEBUG")
assert_equal(yoga_debug_config.build_settings["OTHER_CPLUSPLUSFLAGS"], "$(inherited)")
assert_nil(yoga_debug_config.build_settings["OTHER_CFLAGS"])
assert_equal(yoga_release_config.build_settings["OTHER_CPLUSPLUSFLAGS"], "$(inherited) -DNDEBUG")
assert_equal(yoga_release_config.build_settings["OTHER_CFLAGS"], "$(inherited) -DNDEBUG")
end
Expand Down
20 changes: 13 additions & 7 deletions scripts/cocoapods/new_architecture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,20 @@ def self.set_clang_cxx_language_standard_if_needed(installer)
end
end

def self.modify_flags_for_new_architecture(installer, is_new_arch_enabled, is_release: false)
def self.modify_flags_for_new_architecture(installer, is_new_arch_enabled)
unless is_new_arch_enabled
return
end
ndebug_flag = (is_release ? " -DNDEBUG" : "")
ndebug_flag = " -DNDEBUG"
# Add RCT_NEW_ARCH_ENABLED to Target pods xcconfig
installer.aggregate_targets.each do |aggregate_target|
aggregate_target.xcconfigs.each do |config_name, config_file|
config_file.attributes['OTHER_CPLUSPLUSFLAGS'] = @@new_arch_cpp_flags + ndebug_flag
config_file.attributes['OTHER_CFLAGS'] = "$(inherited)" + ndebug_flag
config_file.attributes['OTHER_CPLUSPLUSFLAGS'] = @@new_arch_cpp_flags

if config_name == "Release"
config_file.attributes['OTHER_CPLUSPLUSFLAGS'] = config_file.attributes['OTHER_CPLUSPLUSFLAGS'] + ndebug_flag
config_file.attributes['OTHER_CFLAGS'] = "$(inherited)" + ndebug_flag
end

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

target_installation_result.native_target.build_configurations.each do |config|
current_flags = config.build_settings['OTHER_CPLUSPLUSFLAGS'] != nil ? config.build_settings['OTHER_CPLUSPLUSFLAGS'] : ""
config.build_settings['OTHER_CPLUSPLUSFLAGS'] = current_flags + ndebug_flag
config.build_settings['OTHER_CFLAGS'] = "$(inherited)" + ndebug_flag
if config.name == "Release"
current_flags = config.build_settings['OTHER_CPLUSPLUSFLAGS'] != nil ? config.build_settings['OTHER_CPLUSPLUSFLAGS'] : ""
config.build_settings['OTHER_CPLUSPLUSFLAGS'] = current_flags + ndebug_flag
config.build_settings['OTHER_CFLAGS'] = "$(inherited)" + ndebug_flag
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def react_native_post_install(installer, react_native_path = "../node_modules/re

NewArchitectureHelper.set_clang_cxx_language_standard_if_needed(installer)
is_new_arch_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == "1"
NewArchitectureHelper.modify_flags_for_new_architecture(installer, is_new_arch_enabled, is_release: ENV['PRODUCTION'] == "1")
NewArchitectureHelper.modify_flags_for_new_architecture(installer, is_new_arch_enabled)

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

0 comments on commit 93fdcba

Please sign in to comment.