From 1021448d7cf462d5280ce82f484f029fd29e40a6 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Thu, 21 Mar 2024 13:55:11 -0700 Subject: [PATCH] Warn users during "pod install" if XCode is too old (#43583) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43583 Fail during `pod install` if user's version of XCode is too old to avoid cryptic errors (e.g. https://github.com/reactwg/react-native-releases/issues/163). I reused existing mechanism for version detection, though it may not be reliable for future versions of XCode. Changelog: [iOS][Changed] - Warn users during "pod install" if XCode is too old Reviewed By: dmytrorykun Differential Revision: D55149636 fbshipit-source-id: 78387ff19a6eb10f3ca0d4aa78e6b934ae3b0711 --- .../react-native/scripts/cocoapods/helpers.rb | 4 +++ .../react-native/scripts/cocoapods/utils.rb | 32 +++++++++++++++---- .../react-native/scripts/react_native_pods.rb | 2 ++ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/packages/react-native/scripts/cocoapods/helpers.rb b/packages/react-native/scripts/cocoapods/helpers.rb index 1e115ef1755528..68017d1f0cc535 100644 --- a/packages/react-native/scripts/cocoapods/helpers.rb +++ b/packages/react-native/scripts/cocoapods/helpers.rb @@ -41,6 +41,10 @@ def self.min_ios_version_supported return '13.4' end + def self.min_xcode_version_supported + return '14.3' + end + def self.folly_config return { :version => '2024.01.01.00', diff --git a/packages/react-native/scripts/cocoapods/utils.rb b/packages/react-native/scripts/cocoapods/utils.rb index ffe6a70c7e95ca..8873af4860440c 100644 --- a/packages/react-native/scripts/cocoapods/utils.rb +++ b/packages/react-native/scripts/cocoapods/utils.rb @@ -407,19 +407,39 @@ def self.remove_value_from_setting_if_present(config, setting_name, value) def self.is_using_xcode15_0(xcodebuild_manager: Xcodebuild) xcodebuild_version = xcodebuild_manager.version + if version = self.parse_xcode_version(xcodebuild_version) + return version["major"] == 15 && version["minor"] == 0 + end + + return false + end + + def self.parse_xcode_version(version_string) # The output of xcodebuild -version is something like # Xcode 15.0 # or # Xcode 14.3.1 # We want to capture the version digits - regex = /(\d+)\.(\d+)(?:\.(\d+))?/ - if match_data = xcodebuild_version.match(regex) - major = match_data[1].to_i - minor = match_data[2].to_i - return major == 15 && minor == 0 + match = version_string.match(/(\d+)\.(\d+)(?:\.(\d+))?/) + return nil if match.nil? + + return {"str" => match[0], "major" => match[1].to_i, "minor" => match[2].to_i}; + end + + def self.check_minimum_required_xcode(xcodebuild_manager: Xcodebuild) + version = self.parse_xcode_version(xcodebuild_manager.version) + if (version.nil? || !Gem::Version::correct?(version["str"])) + Pod::UI.warn "Unexpected XCode version string '#{xcodebuild_manager.version}'" + return end - return false + current = version["str"] + min_required = Helpers::Constants.min_xcode_version_supported + + if Gem::Version::new(current) < Gem::Version::new(min_required) + Pod::UI.puts "React Native requires XCode >= #{min_required}. Found #{current}.".red + raise "Please upgrade XCode" + end end def self.add_compiler_flag_to_project(installer, flag, configuration: nil) diff --git a/packages/react-native/scripts/react_native_pods.rb b/packages/react-native/scripts/react_native_pods.rb index e60920404de575..462048d89962ca 100644 --- a/packages/react-native/scripts/react_native_pods.rb +++ b/packages/react-native/scripts/react_native_pods.rb @@ -80,6 +80,8 @@ def use_react_native! ( ENV['APP_PATH'] = app_path ENV['REACT_NATIVE_PATH'] = path + ReactNativePodsUtils.check_minimum_required_xcode() + # Current target definition is provided by Cocoapods and it refers to the target # that has invoked the `use_react_native!` function. ReactNativePodsUtils.detect_use_frameworks(current_target_definition)