From 93fdcbaed0f69b268e1ae708a52df9463aae2d53 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Fri, 24 Feb 2023 02:05:32 -0800 Subject: [PATCH] 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 --- .../__tests__/new_architecture-test.rb | 42 +++---------------- scripts/cocoapods/new_architecture.rb | 20 +++++---- scripts/react_native_pods.rb | 2 +- 3 files changed, 20 insertions(+), 44 deletions(-) diff --git a/scripts/cocoapods/__tests__/new_architecture-test.rb b/scripts/cocoapods/__tests__/new_architecture-test.rb index b9fef9c43d8..a29bfb31502 100644 --- a/scripts/cocoapods/__tests__/new_architecture-test.rb +++ b/scripts/cocoapods/__tests__/new_architecture-test.rb @@ -81,7 +81,7 @@ class NewArchitectureTests < Test::Unit::TestCase 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") @@ -102,47 +102,17 @@ class NewArchitectureTests < Test::Unit::TestCase # 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 diff --git a/scripts/cocoapods/new_architecture.rb b/scripts/cocoapods/new_architecture.rb index 8cadc93b21d..207c79c2eb5 100644 --- a/scripts/cocoapods/new_architecture.rb +++ b/scripts/cocoapods/new_architecture.rb @@ -38,16 +38,20 @@ class NewArchitectureHelper 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) @@ -63,9 +67,11 @@ class NewArchitectureHelper 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 diff --git a/scripts/react_native_pods.rb b/scripts/react_native_pods.rb index c83df4f397d..16439ba72f9 100644 --- a/scripts/react_native_pods.rb +++ b/scripts/react_native_pods.rb @@ -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