Skip to content

Commit

Permalink
Warn users during "pod install" if XCode is too old (#43583)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #43583

Fail during `pod install` if user's version of XCode is too old to avoid cryptic errors (e.g. reactwg/react-native-releases#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
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Mar 21, 2024
1 parent 7d180d7 commit 1021448
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
4 changes: 4 additions & 0 deletions packages/react-native/scripts/cocoapods/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
32 changes: 26 additions & 6 deletions packages/react-native/scripts/cocoapods/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native/scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

1 comment on commit 1021448

@dipo1
Copy link

@dipo1 dipo1 commented on 1021448 Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit removes React Native development support on MacOS Monterey and any MacBook before 2017.
See #44384

Please sign in to comment.