Skip to content

Commit 7ed0792

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Automate setting the RCTNewArchEnabled flag (#49927)
Summary: This change automates updating App's Info.plist with the new `RCTNewArchEnabled` boolean entry. The value depends on how the pod install is set up. In this way, we maintain the previous UX to enable/disable the New Arch. ## Context The RCT_NEW_ARCH_ENABLE flag is a compile time flag we used for almost two years to configure the iOS apps and to determine whether the app should build with the New Arch or not. However, given that we are looking into prebuilding React Native, we have to get rid of all the compilation flags, because they would require us to prebuild a combinatorial number of artifacts for react native. For example: - New Arch / Hermes - Old Arch / Hermes - New Arch / JSC - Old Arch / JSC - ... ## Backward compatibility We are going to keep adding the RCT_NEW_ARCH_ENABLED flag in all the dependencies, through the cocoapods inrastructure, so libraries, which are not prebuilt, will be build for the right architecture by the app itself. ## Changelog: [iOS][Added] - Reviewed By: cortinico Differential Revision: D70888212
1 parent 51a3c73 commit 7ed0792

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

packages/react-native/scripts/cocoapods/new_architecture.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
require_relative "./helpers.rb"
1010
require_relative "./jsengine.rb"
1111

12+
1213
class NewArchitectureHelper
1314
@@NewArchWarningEmitted = false # Used not to spam warnings to the user.
1415

@@ -159,4 +160,40 @@ def self.extract_react_native_version(react_native_path, file_manager: File, jso
159160
def self.new_arch_enabled
160161
return ENV["RCT_NEW_ARCH_ENABLED"] == '0' ? false : true
161162
end
163+
164+
def self.set_RCTNewArchEnabled_in_info_plist(installer, new_arch_enabled)
165+
projectPaths = installer.aggregate_targets
166+
.map{ |t| t.user_project }
167+
.uniq{ |p| p.path }
168+
.map{ |p| p.path }
169+
170+
excluded_info_plist = ["/Pods", "Tests", "metainternal", ".bundle"]
171+
projectPaths.each do |projectPath|
172+
projectFolderPath = File.dirname(projectPath)
173+
infoPlistFiles = `find #{projectFolderPath} -name "Info.plist"`
174+
infoPlistFiles = infoPlistFiles.split("\n").map { |f| f.strip }
175+
176+
infoPlistFiles.each do |infoPlistFile|
177+
# If infoPlistFile contains Pods or tests, skip it
178+
should_skip = false
179+
excluded_info_plist.each do |excluded|
180+
if infoPlistFile.include? excluded
181+
should_skip = true
182+
end
183+
end
184+
next if should_skip
185+
186+
# Read the file as a plist
187+
info_plist = Xcodeproj::Plist.read_from_path(infoPlistFile)
188+
# Check if it contains the RCTNewArchEnabled key
189+
if info_plist["RCTNewArchEnabled"] and info_plist["RCTNewArchEnabled"] == new_arch_enabled
190+
next
191+
end
192+
193+
# Add the key and value to the plist
194+
info_plist["RCTNewArchEnabled"] = new_arch_enabled ? true : false
195+
Xcodeproj::Plist.write_to_path(info_plist, infoPlistFile)
196+
end
197+
end
198+
end
162199
end

packages/react-native/scripts/react_native_pods.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ def react_native_post_install(
451451

452452
NewArchitectureHelper.set_clang_cxx_language_standard_if_needed(installer)
453453
NewArchitectureHelper.modify_flags_for_new_architecture(installer, NewArchitectureHelper.new_arch_enabled)
454+
NewArchitectureHelper.set_RCTNewArchEnabled_in_info_plist(installer, NewArchitectureHelper.new_arch_enabled)
454455

455456
if ENV['USE_HERMES'] == '0' && ENV['USE_THIRD_PARTY_JSC'] != '1'
456457
print_jsc_removal_message()

0 commit comments

Comments
 (0)