Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev-cmd/unbottled: various improvements #10679

Merged
merged 1 commit into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 38 additions & 7 deletions Library/Homebrew/dev-cmd/unbottled.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def formulae_all_installs_from_args(args)
elsif args.dependents?
formulae = all_formulae = Formula.to_a

@sort = " (sorted by installs in the last 90 days)"
@sort = " (sorted by number of dependents)"
else
formula_installs = {}

Expand All @@ -103,7 +103,7 @@ def formulae_all_installs_from_args(args)
nil
end
end.compact
@sort = " (sorted by installs in the last 90 days)"
@sort = " (sorted by installs in the last 90 days; top 10,000 only)"

all_formulae = Formula
end
Expand Down Expand Up @@ -154,20 +154,51 @@ def output_unbottled(formulae, deps_hash, noun, hash, any_named_args)

formulae.each do |f|
name = f.name.downcase
if f.bottle_specification.tag?(@bottle_tag)
if f.bottle_specification.tag?(@bottle_tag, exact: true)
puts "#{Tty.bold}#{Tty.green}#{name}#{Tty.reset}: already bottled" if any_named_args
next
end

requirement_classes = f.recursive_requirements.map(&:class)
if f.disabled?
puts "#{Tty.bold}#{Tty.green}#{name}#{Tty.reset}: formula disabled" if any_named_args
next
end

requirements = f.recursive_requirements
if @bottle_tag.to_s.end_with?("_linux")
if requirement_classes.include?(MacOSRequirement)
if requirements.any? { |r| r.is_a?(MacOSRequirement) }
puts "#{Tty.bold}#{Tty.red}#{name}#{Tty.reset}: requires macOS" if any_named_args
next
end
elsif requirement_classes.include?(LinuxRequirement)
elsif requirements.any? { |r| r.is_a?(LinuxRequirement) }
puts "#{Tty.bold}#{Tty.red}#{name}#{Tty.reset}: requires Linux" if any_named_args
next
else
macos_version = MacOS::Version.from_symbol(@bottle_tag)
macos_satisfied = requirements.all? do |r|
case r
when MacOSRequirement
next true unless r.version_specified?

macos_version.public_send(r.comparator, r.version)
when XcodeRequirement
next true unless r.version

Version.new(MacOS::Xcode.latest_version(macos: macos_version)) >= r.version
when ArchRequirement
arch = r.arch
arch = :intel if arch == :x86_64
arch = :arm64 if arch == :arm

arch == macos_version.arch
else
true
end
end
unless macos_satisfied
puts "#{Tty.bold}#{Tty.red}#{name}#{Tty.reset}: doesn't support this macOS" if any_named_args
next
end
end

if f.bottle_unneeded? || f.bottle_disabled?
Expand All @@ -181,7 +212,7 @@ def output_unbottled(formulae, deps_hash, noun, hash, any_named_args)
end

deps = Array(deps_hash[f.name]).reject do |dep|
dep.bottle_specification.tag?(@bottle_tag) || dep.bottle_unneeded?
dep.bottle_specification.tag?(@bottle_tag, exact: true) || dep.bottle_unneeded?
end

if deps.blank?
Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/extend/os/mac/utils/bottles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class Collector

alias generic_find_matching_tag find_matching_tag

def find_matching_tag(tag)
def find_matching_tag(tag, exact: false)
# Used primarily by developers testing beta macOS releases.
if OS::Mac.prerelease? && Homebrew::EnvConfig.developer? &&
Homebrew::EnvConfig.skip_or_later_bottles?
if exact || (OS::Mac.prerelease? && Homebrew::EnvConfig.developer? &&
Homebrew::EnvConfig.skip_or_later_bottles?)
generic_find_matching_tag(tag)
else
generic_find_matching_tag(tag) ||
Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/os/mac/xcode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ module Xcode
# Bump these when a new version is available from the App Store and our
# CI systems have been updated.
# This may be a beta version for a beta macOS.
sig { returns(String) }
def latest_version
sig { params(macos: MacOS::Version).returns(String) }
def latest_version(macos: MacOS.version)
latest_stable = "12.4"
case MacOS.version
case macos
when "11" then latest_stable
when "10.15" then "12.4"
when "10.14" then "11.3.1"
Expand Down
12 changes: 6 additions & 6 deletions Library/Homebrew/software_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,9 @@ def skip_relocation?
cellar == :any_skip_relocation
end

sig { params(tag: Symbol).returns(T::Boolean) }
def tag?(tag)
checksum_for(tag) ? true : false
sig { params(tag: Symbol, exact: T::Boolean).returns(T::Boolean) }
def tag?(tag, exact: false)
checksum_for(tag, exact: exact) ? true : false
end

# Checksum methods in the DSL's bottle block take
Expand Down Expand Up @@ -444,9 +444,9 @@ def sha256(hash)
collector[tag] = { checksum: Checksum.new(digest), cellar: cellar }
end

sig { params(tag: Symbol).returns(T.nilable([Checksum, Symbol, T.any(Symbol, String)])) }
def checksum_for(tag)
collector.fetch_checksum_for(tag)
sig { params(tag: Symbol, exact: T::Boolean).returns(T.nilable([Checksum, Symbol, T.any(Symbol, String)])) }
def checksum_for(tag, exact: false)
collector.fetch_checksum_for(tag, exact: exact)
end

def checksums
Expand Down
8 changes: 4 additions & 4 deletions Library/Homebrew/utils/bottles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ def initialize
@checksums = {}
end

sig { params(tag: Symbol).returns(T.nilable([Checksum, Symbol, T.any(Symbol, String)])) }
def fetch_checksum_for(tag)
tag = find_matching_tag(tag)
sig { params(tag: Symbol, exact: T::Boolean).returns(T.nilable([Checksum, Symbol, T.any(Symbol, String)])) }
def fetch_checksum_for(tag, exact: false)
tag = find_matching_tag(tag, exact: exact)
return self[tag][:checksum], tag, self[tag][:cellar] if tag
end

private

def find_matching_tag(tag)
def find_matching_tag(tag, exact: false)
tag if key?(tag)
end
end
Expand Down