From 7a85b911254dbae9fac4c6d8a862a20c33e0b36a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Mon, 6 Jan 2025 02:31:42 -0800 Subject: [PATCH] Fix ruby unit tests (#48498) Summary: As a prerequisite of enabling running unit tests on CI again, this PR suggests changes needed to the Ruby unit tests. I've added comments on the code below, justifying changes where I deem a justification might be needed. For use internally, I suggest accessing the folly_config and boost_config directly via the `Helpers` class instead of the `get_folly_config` and `get_boost_config` because these global functions are defined in `react_native_pods` which would be result in circular requires. An alternative would be to move these global functions to a separate file. ## Changelog: [INTERNAL] [FIXED] - Fix Ruby unit tests. Pull Request resolved: https://github.com/facebook/react-native/pull/48498 Test Plan: - `cd packages/react-native` - `./scripts/run_ruby_tests.sh` Reviewed By: rshest Differential Revision: D67852809 Pulled By: cipolleschi fbshipit-source-id: 54d8bd708a9e3fd9aef3569ac89ec6ddcd244437 --- .../cocoapods/__tests__/codegen_utils-test.rb | 15 ++++++++++++++- .../cocoapods/__tests__/new_architecture-test.rb | 4 ---- .../scripts/cocoapods/codegen_utils.rb | 8 ++++---- .../scripts/cocoapods/new_architecture.rb | 6 +++--- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/packages/react-native/scripts/cocoapods/__tests__/codegen_utils-test.rb b/packages/react-native/scripts/cocoapods/__tests__/codegen_utils-test.rb index 48317e230256b7..f4c8e5fb6fd9f5 100644 --- a/packages/react-native/scripts/cocoapods/__tests__/codegen_utils-test.rb +++ b/packages/react-native/scripts/cocoapods/__tests__/codegen_utils-test.rb @@ -513,9 +513,10 @@ def get_podspec_no_fabric_no_script 'source' => { :git => '' }, 'header_mappings_dir' => './', 'platforms' => { - :ios => '13.4', + :ios => '15.1', }, 'source_files' => "**/*.{h,mm,cpp}", + 'exclude_files' => "RCTAppDependencyProvider.{h,mm}", 'pod_target_xcconfig' => { "FRAMEWORK_SEARCH_PATHS" => [], "HEADER_SEARCH_PATHS" => @@ -530,6 +531,17 @@ def get_podspec_no_fabric_no_script "\"$(PODS_ROOT)/Headers/Private/React-RCTFabric\"", "\"$(PODS_ROOT)/Headers/Private/Yoga\"", "\"$(PODS_TARGET_SRCROOT)\"", + ].join(' '), + 'OTHER_CPLUSPLUSFLAGS' => [ + '$(inherited)', + '-DFOLLY_NO_CONFIG', + '-DFOLLY_MOBILE=1', + '-DFOLLY_USE_LIBCPP=1', + '-DFOLLY_CFG_NO_COROUTINES=1', + '-DFOLLY_HAVE_CLOCK_GETTIME=1', + '-Wno-comma', + '-Wno-shorten-64-to-32', + '-Wno-documentation' ].join(' ') }, 'dependencies': { @@ -544,6 +556,7 @@ def get_podspec_no_fabric_no_script "ReactCommon/turbomodule/core": [], "hermes-engine": [], "React-NativeModulesApple": [], + 'React-RCTAppDelegate': [], "glog": [], } } 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 c5cadd975d594e..397a3c60a34802 100644 --- a/packages/react-native/scripts/cocoapods/__tests__/new_architecture-test.rb +++ b/packages/react-native/scripts/cocoapods/__tests__/new_architecture-test.rb @@ -11,10 +11,6 @@ require_relative "./test_utils/SpecMock.rb" require_relative "./test_utils/FileMock.rb" -def get_folly_config() - return Helpers::Constants.folly_config -end - ## Monkey patching to reset properly static props of the Helper. class NewArchitectureHelper def self.reset diff --git a/packages/react-native/scripts/cocoapods/codegen_utils.rb b/packages/react-native/scripts/cocoapods/codegen_utils.rb index d71c02e40eb8d2..204e8503d7b8f3 100644 --- a/packages/react-native/scripts/cocoapods/codegen_utils.rb +++ b/packages/react-native/scripts/cocoapods/codegen_utils.rb @@ -69,13 +69,13 @@ def generate_react_codegen_podspec!(spec, codegen_output_dir, file_manager: File # - hermes_enabled: whether hermes is enabled or not. # - script_phases: whether we want to add some build script phases or not. # - file_manager: a class that implements the `File` interface. Defaults to `File`, the Dependency can be injected for testing purposes. - def get_react_codegen_spec(package_json_file, folly_version: get_folly_config()[:version], hermes_enabled: true, script_phases: nil, file_manager: File, logger: CodegenUtils::UI) + def get_react_codegen_spec(package_json_file, folly_version: Helpers::Constants.folly_config[:version], hermes_enabled: true, script_phases: nil, file_manager: File, logger: CodegenUtils::UI) package = JSON.parse(file_manager.read(package_json_file)) version = package['version'] use_frameworks = ENV['USE_FRAMEWORKS'] != nil - folly_compiler_flags = get_folly_config()[:compiler_flags] - boost_compiler_flags = get_boost_config()[:compiler_flags] + folly_compiler_flags = Helpers::Constants.folly_config[:compiler_flags] + boost_compiler_flags = Helpers::Constants.boost_config[:compiler_flags] header_search_paths = [ "\"$(PODS_ROOT)/boost\"", @@ -282,7 +282,7 @@ def use_react_native_codegen_discovery!( config_file_dir: '', codegen_output_dir: 'build/generated/ios', config_key: 'codegenConfig', - folly_version: get_folly_config()[:version], + folly_version: Helpers::Constants.folly_config[:version], codegen_utils: CodegenUtils.new(), file_manager: File, logger: CodegenUtils::UI diff --git a/packages/react-native/scripts/cocoapods/new_architecture.rb b/packages/react-native/scripts/cocoapods/new_architecture.rb index 802f6416c768a8..e7e97f613874b8 100644 --- a/packages/react-native/scripts/cocoapods/new_architecture.rb +++ b/packages/react-native/scripts/cocoapods/new_architecture.rb @@ -68,10 +68,10 @@ def self.modify_flags_for_new_architecture(installer, is_new_arch_enabled) end end - def self.install_modules_dependencies(spec, new_arch_enabled, folly_version = get_folly_config()[:version]) + def self.install_modules_dependencies(spec, new_arch_enabled, folly_version = Helpers::Constants.folly_config[:version]) # Pod::Specification does not have getters so, we have to read # the existing values from a hash representation of the object. - folly_config = get_folly_config() + folly_config = Helpers::Constants.folly_config folly_compiler_flags = folly_config[:compiler_flags] hash = spec.to_hash @@ -145,7 +145,7 @@ def self.install_modules_dependencies(spec, new_arch_enabled, folly_version = ge end def self.folly_compiler_flags - folly_config = get_folly_config() + folly_config = Helpers::Constants.folly_config return folly_config[:compiler_flags] end