mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Read the React Native version and set the new arch flag properly (#39388)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39388 This change prepare the infra to release and work properly in the dual release mode, making sure that the new architecture is turned on with some versions of react native. It connects the diffs in the previous changes in the stack. ## Changelog: [iOS][Changed] - Set the new arch flag based on the React Native version. Reviewed By: dmytrorykun Differential Revision: D49149212 fbshipit-source-id: 4d97cc2fbf64d217aec60c0d71de6ed1802ef793
This commit is contained in:
committed by
Facebook GitHub Bot
parent
f60b9f695e
commit
a8d268593a
@@ -14,6 +14,7 @@ class NewArchitectureTests < Test::Unit::TestCase
|
||||
def teardown
|
||||
Pod::UI.reset()
|
||||
FileMock.reset()
|
||||
ENV["RCT_NEW_ARCH_ENABLED"] = nil
|
||||
end
|
||||
|
||||
# ============================= #
|
||||
@@ -184,87 +185,87 @@ class NewArchitectureTests < Test::Unit::TestCase
|
||||
)
|
||||
end
|
||||
|
||||
# ========================== #
|
||||
# Test - Is New Arch Enabled #
|
||||
# ========================== #
|
||||
# =============================== #
|
||||
# Test - Compute New Arch Enabled #
|
||||
# =============================== #
|
||||
|
||||
def test_isNewArchEnabled_whenOnMainAndFlagTrue_returnTrue
|
||||
def test_computeNewArchEnabled_whenOnMainAndFlagTrue_returnTrue
|
||||
version = '1000.0.0'
|
||||
new_arch_enabled = true
|
||||
|
||||
isEnabled = NewArchitectureHelper.is_new_arch_enabled(new_arch_enabled, version)
|
||||
isEnabled = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, version)
|
||||
|
||||
assert_equal("1", isEnabled)
|
||||
end
|
||||
|
||||
def test_isNewArchEnabled_whenOnMainAndFlagFalse_returnFalse
|
||||
def test_computeNewArchEnabled_whenOnMainAndFlagFalse_returnFalse
|
||||
version = '1000.0.0'
|
||||
new_arch_enabled = false
|
||||
|
||||
isEnabled = NewArchitectureHelper.is_new_arch_enabled(new_arch_enabled, version)
|
||||
isEnabled = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, version)
|
||||
|
||||
assert_equal("0", isEnabled)
|
||||
end
|
||||
|
||||
def test_isNewArchEnabled_whenOnStableAndFlagTrue_returnTrue
|
||||
def test_computeNewArchEnabled_whenOnStableAndFlagTrue_returnTrue
|
||||
version = '0.73.0'
|
||||
new_arch_enabled = true
|
||||
|
||||
isEnabled = NewArchitectureHelper.is_new_arch_enabled(new_arch_enabled, version)
|
||||
isEnabled = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, version)
|
||||
|
||||
assert_equal("1", isEnabled)
|
||||
end
|
||||
|
||||
def test_isNewArchEnabled_whenOnStableAndFlagFalse_returnFalse
|
||||
def test_computeNewArchEnabled_whenOnStableAndFlagFalse_returnFalse
|
||||
version = '0.73.0'
|
||||
new_arch_enabled = false
|
||||
|
||||
isEnabled = NewArchitectureHelper.is_new_arch_enabled(new_arch_enabled, version)
|
||||
isEnabled = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, version)
|
||||
|
||||
assert_equal("0", isEnabled)
|
||||
end
|
||||
|
||||
def test_isNewArchEnabled_whenOn100AndFlagTrue_returnTrue
|
||||
def test_computeNewArchEnabled_whenOn100AndFlagTrue_returnTrue
|
||||
version = '1.0.0-prealpha.0'
|
||||
new_arch_enabled = true
|
||||
|
||||
isEnabled = NewArchitectureHelper.is_new_arch_enabled(new_arch_enabled, version)
|
||||
isEnabled = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, version)
|
||||
|
||||
assert_equal("1", isEnabled)
|
||||
end
|
||||
|
||||
def test_isNewArchEnabled_whenOn100PrealphaWithDotsAndFlagFalse_returnTrue
|
||||
def test_computeNewArchEnabled_whenOn100PrealphaWithDotsAndFlagFalse_returnTrue
|
||||
version = '1.0.0-prealpha.0'
|
||||
new_arch_enabled = false
|
||||
|
||||
isEnabled = NewArchitectureHelper.is_new_arch_enabled(new_arch_enabled, version)
|
||||
isEnabled = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, version)
|
||||
|
||||
assert_equal("1", isEnabled)
|
||||
end
|
||||
|
||||
def test_isNewArchEnabled_whenOn100PrealphaWithDashAndFlagFalse_returnTrue
|
||||
def test_computeNewArchEnabled_whenOn100PrealphaWithDashAndFlagFalse_returnTrue
|
||||
version = '1.0.0-prealpha-0'
|
||||
new_arch_enabled = false
|
||||
|
||||
isEnabled = NewArchitectureHelper.is_new_arch_enabled(new_arch_enabled, version)
|
||||
isEnabled = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, version)
|
||||
|
||||
assert_equal("1", isEnabled)
|
||||
end
|
||||
|
||||
def test_isNewArchEnabled_whenOn100PrealphaOnlyWordsAndFlagFalse_returnTrue
|
||||
def test_computeNewArchEnabled_whenOn100PrealphaOnlyWordsAndFlagFalse_returnTrue
|
||||
version = '1.0.0-prealpha0'
|
||||
new_arch_enabled = false
|
||||
|
||||
isEnabled = NewArchitectureHelper.is_new_arch_enabled(new_arch_enabled, version)
|
||||
isEnabled = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, version)
|
||||
|
||||
assert_equal("1", isEnabled)
|
||||
end
|
||||
|
||||
def test_isNewArchEnabled_whenOnGreaterThan100AndFlagFalse_returnTrue
|
||||
def test_computeNewArchEnabled_whenOnGreaterThan100AndFlagFalse_returnTrue
|
||||
version = '3.2.1'
|
||||
new_arch_enabled = false
|
||||
|
||||
isEnabled = NewArchitectureHelper.is_new_arch_enabled(new_arch_enabled, version)
|
||||
isEnabled = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, version)
|
||||
|
||||
assert_equal("1", isEnabled)
|
||||
end
|
||||
@@ -296,6 +297,28 @@ class NewArchitectureTests < Test::Unit::TestCase
|
||||
assert_equal("1.0.0-prealpha.0", version)
|
||||
end
|
||||
|
||||
# =============================== #
|
||||
# Test - New Architecture Enabled #
|
||||
# =============================== #
|
||||
def test_newArchEnabled_whenRCTNewArchEnabledIsSetTo1_returnTrue
|
||||
ENV["RCT_NEW_ARCH_ENABLED"] = "1"
|
||||
is_enabled = NewArchitectureHelper.new_arch_enabled
|
||||
assert_true(is_enabled)
|
||||
end
|
||||
|
||||
def test_newArchEnabled_whenRCTNewArchEnabledIsSetTo0_returnFalse
|
||||
ENV["RCT_NEW_ARCH_ENABLED"] = "0"
|
||||
is_enabled = NewArchitectureHelper.new_arch_enabled
|
||||
assert_false(is_enabled)
|
||||
end
|
||||
|
||||
def test_newArchEnabled_whenRCTNewArchEnabledIsNotSet_returnFalse
|
||||
ENV["RCT_NEW_ARCH_ENABLED"] = nil
|
||||
is_enabled = NewArchitectureHelper.new_arch_enabled
|
||||
assert_false(is_enabled)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
# ================ #
|
||||
|
||||
@@ -74,6 +74,7 @@ class NewArchitectureHelper
|
||||
# Set "RCT_DYNAMIC_FRAMEWORKS=1" if pod are installed with USE_FRAMEWORKS=dynamic
|
||||
# This helps with backward compatibility.
|
||||
if pod_name == 'React-RCTFabric' && ENV['USE_FRAMEWORKS'] == 'dynamic'
|
||||
Pod::UI.puts "Setting -DRCT_DYNAMIC_FRAMEWORKS=1 to React-RCTFabric".green
|
||||
rct_dynamic_framework_flag = " -DRCT_DYNAMIC_FRAMEWORKS=1"
|
||||
target_installation_result.native_target.build_configurations.each do |config|
|
||||
prev_build_settings = config.build_settings['OTHER_CPLUSPLUSFLAGS'] != nil ? config.build_settings['OTHER_CPLUSPLUSFLAGS'] : "$(inherithed)"
|
||||
@@ -170,7 +171,7 @@ class NewArchitectureHelper
|
||||
return package["version"]
|
||||
end
|
||||
|
||||
def self.is_new_arch_enabled(new_arch_enabled, react_native_version)
|
||||
def self.compute_new_arch_enabled(new_arch_enabled, react_native_version)
|
||||
# Regex that identify a version with the syntax `<major>.<minor>.<patch>[-<prerelease>[.-]k]
|
||||
# where
|
||||
# - major is a number
|
||||
@@ -192,4 +193,8 @@ class NewArchitectureHelper
|
||||
end
|
||||
return new_arch_enabled ? "1" : "0"
|
||||
end
|
||||
|
||||
def self.new_arch_enabled
|
||||
return ENV["RCT_NEW_ARCH_ENABLED"] == "1"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -72,7 +72,7 @@ end
|
||||
def use_react_native! (
|
||||
path: "../node_modules/react-native",
|
||||
fabric_enabled: false,
|
||||
new_arch_enabled: ENV['RCT_NEW_ARCH_ENABLED'] == '1',
|
||||
new_arch_enabled: NewArchitectureHelper.new_arch_enabled,
|
||||
production: false, # deprecated
|
||||
hermes_enabled: ENV['USE_HERMES'] && ENV['USE_HERMES'] == '0' ? false : true,
|
||||
flipper_configuration: FlipperConfiguration.disabled,
|
||||
@@ -93,8 +93,11 @@ def use_react_native! (
|
||||
|
||||
# We are relying on this flag also in third parties libraries to proper install dependencies.
|
||||
# Better to rely and enable this environment flag if the new architecture is turned on using flags.
|
||||
ENV['RCT_NEW_ARCH_ENABLED'] = new_arch_enabled ? "1" : "0"
|
||||
fabric_enabled = fabric_enabled || new_arch_enabled
|
||||
relative_path_from_current = Pod::Config.instance.installation_root.relative_path_from(Pathname.pwd)
|
||||
react_native_version = NewArchitectureHelper.extract_react_native_version(File.join(relative_path_from_current, path))
|
||||
ENV['RCT_NEW_ARCH_ENABLED'] = NewArchitectureHelper.compute_new_arch_enabled(new_arch_enabled, react_native_version)
|
||||
|
||||
fabric_enabled = fabric_enabled || NewArchitectureHelper.new_arch_enabled
|
||||
ENV['RCT_FABRIC_ENABLED'] = fabric_enabled ? "1" : "0"
|
||||
ENV['USE_HERMES'] = hermes_enabled ? "1" : "0"
|
||||
|
||||
@@ -104,7 +107,7 @@ def use_react_native! (
|
||||
|
||||
# The Pods which should be included in all projects
|
||||
pod 'FBLazyVector', :path => "#{prefix}/Libraries/FBLazyVector"
|
||||
pod 'FBReactNativeSpec', :path => "#{prefix}/React/FBReactNativeSpec" if !new_arch_enabled
|
||||
pod 'FBReactNativeSpec', :path => "#{prefix}/React/FBReactNativeSpec" if !NewArchitectureHelper.new_arch_enabled
|
||||
pod 'RCTRequired', :path => "#{prefix}/Libraries/RCTRequired"
|
||||
pod 'RCTTypeSafety', :path => "#{prefix}/Libraries/TypeSafety", :modular_headers => true
|
||||
pod 'React', :path => "#{prefix}/"
|
||||
@@ -156,7 +159,7 @@ def use_react_native! (
|
||||
run_codegen!(
|
||||
app_path,
|
||||
config_file_dir,
|
||||
:new_arch_enabled => new_arch_enabled,
|
||||
:new_arch_enabled => NewArchitectureHelper.new_arch_enabled,
|
||||
:disable_codegen => ENV['DISABLE_CODEGEN'] == '1',
|
||||
:react_native_path => prefix,
|
||||
:fabric_enabled => fabric_enabled,
|
||||
@@ -172,14 +175,14 @@ def use_react_native! (
|
||||
# If the New Arch is turned off, we will use the Old Renderer, though.
|
||||
# RNTester always installed Fabric, this change is required to make the template work.
|
||||
setup_fabric!(:react_native_path => prefix)
|
||||
checkAndGenerateEmptyThirdPartyProvider!(prefix, new_arch_enabled)
|
||||
checkAndGenerateEmptyThirdPartyProvider!(prefix, NewArchitectureHelper.new_arch_enabled)
|
||||
|
||||
if !fabric_enabled
|
||||
relative_installation_root = Pod::Config.instance.installation_root.relative_path_from(Pathname.pwd)
|
||||
build_codegen!(prefix, relative_installation_root)
|
||||
end
|
||||
|
||||
if new_arch_enabled
|
||||
if NewArchitectureHelper.new_arch_enabled
|
||||
setup_bridgeless!(:react_native_path => prefix, :use_hermes => hermes_enabled)
|
||||
end
|
||||
|
||||
@@ -212,7 +215,7 @@ end
|
||||
# Parameters:
|
||||
# - spec: The spec that has to be configured with the New Architecture code
|
||||
# - new_arch_enabled: Whether the module should install dependencies for the new architecture
|
||||
def install_modules_dependencies(spec, new_arch_enabled: ENV['RCT_NEW_ARCH_ENABLED'] == "1")
|
||||
def install_modules_dependencies(spec, new_arch_enabled: NewArchitectureHelper.new_arch_enabled)
|
||||
NewArchitectureHelper.install_modules_dependencies(spec, new_arch_enabled, $FOLLY_VERSION)
|
||||
end
|
||||
|
||||
@@ -271,8 +274,7 @@ def react_native_post_install(
|
||||
ReactNativePodsUtils.apply_ats_config(installer)
|
||||
|
||||
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)
|
||||
NewArchitectureHelper.modify_flags_for_new_architecture(installer, NewArchitectureHelper.new_arch_enabled)
|
||||
|
||||
Pod::UI.puts "Pod install took #{Time.now.to_i - $START_TIME} [s] to run".green
|
||||
end
|
||||
@@ -281,7 +283,7 @@ end
|
||||
# We need to keep this while we continue to support the old architecture.
|
||||
# =====================
|
||||
def use_react_native_codegen!(spec, options={})
|
||||
return if ENV['RCT_NEW_ARCH_ENABLED'] == "1"
|
||||
return if NewArchitectureHelper.new_arch_enabled
|
||||
# TODO: Once the new codegen approach is ready for use, we should output a warning here to let folks know to migrate.
|
||||
|
||||
# The prefix to react-native
|
||||
|
||||
@@ -44,11 +44,6 @@ def pods(target_name, options = {}, use_flipper: $shouldUseFlipper)
|
||||
hermes_enabled = !ENV.has_key?('USE_HERMES') || ENV['USE_HERMES'] == '1'
|
||||
puts "Configuring #{target_name} with Fabric #{fabric_enabled ? "enabled" : "disabled"}.#{hermes_enabled ? " Using Hermes engine." : ""}"
|
||||
|
||||
if ENV['RCT_NEW_ARCH_ENABLED'] == '1'
|
||||
# Custom fabric component is only supported when using codegen discovery.
|
||||
pod 'MyNativeView', :path => "NativeComponentExample"
|
||||
end
|
||||
|
||||
use_react_native!(
|
||||
path: @prefix_path,
|
||||
fabric_enabled: fabric_enabled,
|
||||
@@ -68,7 +63,9 @@ def pods(target_name, options = {}, use_flipper: $shouldUseFlipper)
|
||||
|
||||
# RNTester native modules and components
|
||||
pod 'ScreenshotManager', :path => "NativeModuleExample"
|
||||
|
||||
if ENV['RCT_NEW_ARCH_ENABLED'] == '1'
|
||||
pod 'MyNativeView', :path => "NativeComponentExample"
|
||||
pod 'NativeCxxModuleExample', :path => "NativeCxxModuleExample"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user