brew/Library/Homebrew/requirements/xcode_requirement.rb

64 lines
1.5 KiB
Ruby
Raw Permalink Normal View History

rubocop: Use `Sorbet/StrictSigil` as it's better than comments - Previously I thought that comments were fine to discourage people from wasting their time trying to bump things that used `undef` that Sorbet didn't support. But RuboCop is better at this since it'll complain if the comments are unnecessary. - Suggested in https://github.com/Homebrew/brew/pull/18018#issuecomment-2283369501. - I've gone for a mixture of `rubocop:disable` for the files that can't be `typed: strict` (use of undef, required before everything else, etc) and `rubocop:todo` for everything else that should be tried to make strictly typed. There's no functional difference between the two as `rubocop:todo` is `rubocop:disable` with a different name. - And I entirely disabled the cop for the docs/ directory since `typed: strict` isn't going to gain us anything for some Markdown linting config files. - This means that now it's easier to track what needs to be done rather than relying on checklists of files in our big Sorbet issue: ```shell $ git grep 'typed: true # rubocop:todo Sorbet/StrictSigil' | wc -l 268 ``` - And this is confirmed working for new files: ```shell $ git status On branch use-rubocop-for-sorbet-strict-sigils Untracked files: (use "git add <file>..." to include in what will be committed) Library/Homebrew/bad.rb Library/Homebrew/good.rb nothing added to commit but untracked files present (use "git add" to track) $ brew style Offenses: bad.rb:1:1: C: Sorbet/StrictSigil: Sorbet sigil should be at least strict got true. ^^^^^^^^^^^^^ 1340 files inspected, 1 offense detected ```
2024-08-12 10:30:59 +01:00
# typed: true # rubocop:todo Sorbet/StrictSigil
# frozen_string_literal: true
require "requirement"
2020-08-19 06:51:52 +02:00
# A requirement on Xcode.
class XcodeRequirement < Requirement
fatal true
attr_reader :version
2023-02-14 15:39:32 -08:00
satisfy(build_env: false) do
T.bind(self, XcodeRequirement)
xcode_installed_version
end
2017-12-30 18:58:30 +00:00
def initialize(tags = [])
@version = tags.shift if tags.first.to_s.match?(/(\d\.)+\d/)
2024-05-23 17:08:41 +01:00
super
end
2020-11-25 17:03:23 +01:00
sig { returns(T::Boolean) }
def xcode_installed_version
return false unless MacOS::Xcode.installed?
return true unless @version
2018-09-17 02:45:00 +02:00
MacOS::Xcode.version >= @version
end
2020-10-20 12:03:48 +02:00
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
2020-10-20 12:03:48 +02:00
sig { returns(String) }
def inspect
"#<#{self.class.name}: version>=#{@version.inspect} #{tags.inspect}>"
end
def display_s
2023-03-02 23:28:00 -05:00
return "#{name.capitalize} (on macOS)" unless @version
2023-03-02 23:28:00 -05:00
"#{name.capitalize} >= #{@version} (on macOS)"
end
end
xcode_requirement: support linux 2020-10-12T21:29:03.7866574Z [31mError:[0m undefined method `latest_version' for OS::Mac::Xcode:Module 2020-10-12T21:29:03.7867686Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/requirements/xcode_requirement.rb:33:in `message' 2020-10-12T21:29:03.7868902Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-test-bot/lib/tests/formulae.rb:199:in `map' 2020-10-12T21:29:03.7870227Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-test-bot/lib/tests/formulae.rb:199:in `satisfied_requirements?' 2020-10-12T21:29:03.7871547Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-test-bot/lib/tests/formulae.rb:593:in `formula!' 2020-10-12T21:29:03.7873156Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-test-bot/lib/tests/formulae.rb:20:in `block in run!' 2020-10-12T21:29:03.7875029Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-test-bot/lib/tests/formulae.rb:19:in `each' 2020-10-12T21:29:03.7876299Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-test-bot/lib/tests/formulae.rb:19:in `run!' 2020-10-12T21:29:03.7877495Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-test-bot/lib/test_runner.rb:119:in `run_tests' 2020-10-12T21:29:03.7878705Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-test-bot/lib/test_runner.rb:36:in `block in run!' 2020-10-12T21:29:03.7879908Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.3_2/lib/ruby/2.6.0/delegate.rb:83:in `each' 2020-10-12T21:29:03.7881136Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.3_2/lib/ruby/2.6.0/delegate.rb:83:in `method_missing' 2020-10-12T21:29:03.7882519Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-test-bot/lib/test_runner.rb:25:in `run!' 2020-10-12T21:29:03.7883735Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-test-bot/lib/test_bot.rb:126:in `run!' 2020-10-12T21:29:03.7884875Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-test-bot/cmd/test-bot.rb:75:in `test_bot' 2020-10-12T21:29:03.7885882Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/brew.rb:119:in `<main>'
2020-10-13 07:50:40 +02:00
require "extend/os/requirements/xcode_requirement"