brew/Library/Homebrew/requirements/xcode_requirement.rb
Patrick Linnane 4513a43d53
Fix RuboCop failures.
Co-authored-by: Patrick Linnane <patrick@linnane.io>
Co-authored-by: Carlo Cabrera <github@carlo.cab>
Co-authored-by: Thierry Moisan <thierry.moisan@gmail.com>
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
2025-07-14 19:12:38 +01:00

68 lines
1.6 KiB
Ruby

# typed: strict
# frozen_string_literal: true
require "requirement"
# A requirement on Xcode.
class XcodeRequirement < Requirement
fatal true
sig { returns(T.nilable(String)) }
attr_reader :version
satisfy(build_env: false) do
T.bind(self, XcodeRequirement)
xcode_installed_version!
end
sig { params(tags: T::Array[String]).void }
def initialize(tags = [])
version = tags.shift if tags.first.to_s.match?(/(\d\.)+\d/)
@version = T.let(version, T.nilable(String))
super
end
sig { returns(T::Boolean) }
def xcode_installed_version!
return false unless MacOS::Xcode.installed?
return true unless @version
MacOS::Xcode.version >= @version
end
sig { returns(String) }
def message
version = " #{@version}" if @version
message = <<~EOS
A full installation of Xcode.app#{version} is required to compile
this software. Installing just the Command Line Tools is not sufficient.
EOS
if @version && Version.new(MacOS::Xcode.latest_version) < Version.new(@version)
message + <<~EOS
Xcode#{version} cannot be installed on macOS #{MacOS.version}.
You must upgrade your version of macOS.
EOS
else
message + <<~EOS
Xcode can be installed from the App Store.
EOS
end
end
sig { returns(String) }
def inspect
"#<#{self.class.name}: version>=#{@version.inspect} #{tags.inspect}>"
end
sig { returns(String) }
def display_s
return "#{name.capitalize} (on macOS)" unless @version
"#{name.capitalize} >= #{@version} (on macOS)"
end
end
require "extend/os/requirements/xcode_requirement"