Skip to content

Commit

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

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

Differential Revision: D55149636
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Mar 20, 2024
1 parent 0267ca0 commit fd083e9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .circleci/configurations/executors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ executors:
reactnativeios-lts:
<<: *defaults
macos:
xcode: '14.3.1'
xcode: '14.2.0'
resource_class: macos.x86.medium.gen2
environment:
- RCT_BUILD_HERMES_FROM_SOURCE: true
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

0 comments on commit fd083e9

Please sign in to comment.