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: add --lost option #16115

Merged
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
70 changes: 69 additions & 1 deletion Library/Homebrew/dev-cmd/unbottled.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
description: "Skip getting analytics data and sort by number of dependents instead."
switch "--total",
description: "Print the number of unbottled and total formulae."
switch "--lost",
description: "Print the `homebrew/core` commits where bottles were lost in the last week."
switch "--eval-all",
description: "Evaluate all available formulae and casks, whether installed or not, to check them. " \
"Implied if `HOMEBREW_EVAL_ALL` is set."

conflicts "--dependents", "--total"
conflicts "--dependents", "--total", "--lost"

named_args :formula
end
Expand All @@ -43,6 +45,17 @@
Utils::Bottles.tag
end

if args.lost?
if args.named.present?
raise UsageError, "`brew unbottled --lost` cannot be used with formula arguments!"
elsif !CoreTap.instance.installed?
raise UsageError, "`brew unbottled --lost` requires `homebrew/core` to be tapped locally!"
else
output_lost_bottles
return

Check warning on line 55 in Library/Homebrew/dev-cmd/unbottled.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/unbottled.rb#L55

Added line #L55 was not covered by tests
end
end

os = @bottle_tag.system
arch = if Hardware::CPU::INTEL_ARCHS.include?(@bottle_tag.arch)
:intel
Expand Down Expand Up @@ -243,4 +256,59 @@

puts "No unbottled dependencies found!"
end

def output_lost_bottles
ohai ":#{@bottle_tag} lost bottles"

Check warning on line 261 in Library/Homebrew/dev-cmd/unbottled.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/unbottled.rb#L261

Added line #L261 was not covered by tests

bottle_tag_regex_fragment = " +sha256.* #{@bottle_tag}: "

Check warning on line 263 in Library/Homebrew/dev-cmd/unbottled.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/unbottled.rb#L263

Added line #L263 was not covered by tests

# $ git log --patch --no-ext-diff -G'^ +sha256.* sonoma:' --since=@{'1 week ago'}
git_log = %w[git log --patch --no-ext-diff]
git_log << "-G^#{bottle_tag_regex_fragment}"
git_log << "--since=@{'1 week ago'}"

Check warning on line 268 in Library/Homebrew/dev-cmd/unbottled.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/unbottled.rb#L266-L268

Added lines #L266 - L268 were not covered by tests
MikeMcQuaid marked this conversation as resolved.
Show resolved Hide resolved

bottle_tag_sha_regex = /^[+-]#{bottle_tag_regex_fragment}/

Check warning on line 270 in Library/Homebrew/dev-cmd/unbottled.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/unbottled.rb#L270

Added line #L270 was not covered by tests

processed_formulae = Set.new
commit = T.let(nil, T.nilable(String))
formula = T.let(nil, T.nilable(String))
lost_bottles = 0

Check warning on line 275 in Library/Homebrew/dev-cmd/unbottled.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/unbottled.rb#L272-L275

Added lines #L272 - L275 were not covered by tests

CoreTap.instance.path.cd do
Utils.safe_popen_read(*git_log) do |io|
io.each_line do |line|

Check warning on line 279 in Library/Homebrew/dev-cmd/unbottled.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/unbottled.rb#L277-L279

Added lines #L277 - L279 were not covered by tests
case line
when /^commit [0-9a-f]{40}$/
# Example match: `commit 7289b409b96a752540befef1a56b8a818baf1db7`
if commit && formula && lost_bottles.positive? && processed_formulae.exclude?(formula)
puts "#{commit}: bottle lost for #{formula}"
end
processed_formulae << formula
commit = line.split.last
formula = nil

Check warning on line 288 in Library/Homebrew/dev-cmd/unbottled.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/unbottled.rb#L286-L288

Added lines #L286 - L288 were not covered by tests
when %r{^diff --git a/Formula/}
# Example match: `diff --git a/Formula/a/aws-cdk.rb b/Formula/a/aws-cdk.rb`
formula = line.split("/").last.chomp(".rb\n")
apainintheneck marked this conversation as resolved.
Show resolved Hide resolved
formula = CoreTap.instance.formula_renames.fetch(formula, formula)
lost_bottles = 0

Check warning on line 293 in Library/Homebrew/dev-cmd/unbottled.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/unbottled.rb#L292-L293

Added lines #L292 - L293 were not covered by tests
when bottle_tag_sha_regex
# Example match: `- sha256 cellar: :any_skip_relocation, sonoma: "f0a4..."`
next if processed_formulae.include?(formula)

case line.chr
when "+" then lost_bottles -= 1
when "-" then lost_bottles += 1
end
when /^[+] +sha256.* all: /
# Example match: `+ sha256 cellar: :any_skip_relocation, all: "9e35..."`
lost_bottles -= 1
end
end
end
end

return if !commit || !formula || !lost_bottles.positive? || processed_formulae.include?(formula)

puts "#{commit}: bottle lost for #{formula}"

Check warning on line 312 in Library/Homebrew/dev-cmd/unbottled.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/unbottled.rb#L312

Added line #L312 was not covered by tests
end
end
1 change: 1 addition & 0 deletions completions/bash/brew
Original file line number Diff line number Diff line change
Expand Up @@ -2258,6 +2258,7 @@ _brew_unbottled() {
--dependents
--eval-all
--help
--lost
--quiet
--tag
--total
Expand Down
1 change: 1 addition & 0 deletions completions/fish/brew.fish
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,7 @@ __fish_brew_complete_arg 'unbottled' -l debug -d 'Display any debugging informat
__fish_brew_complete_arg 'unbottled' -l dependents -d 'Skip getting analytics data and sort by number of dependents instead'
__fish_brew_complete_arg 'unbottled' -l eval-all -d 'Evaluate all available formulae and casks, whether installed or not, to check them. Implied if `HOMEBREW_EVAL_ALL` is set'
__fish_brew_complete_arg 'unbottled' -l help -d 'Show this message'
__fish_brew_complete_arg 'unbottled' -l lost -d 'Print the `homebrew/core` commits where bottles were lost in the last week'
__fish_brew_complete_arg 'unbottled' -l quiet -d 'Make some output more quiet'
__fish_brew_complete_arg 'unbottled' -l tag -d 'Use the specified bottle tag (e.g. `big_sur`) instead of the current OS'
__fish_brew_complete_arg 'unbottled' -l total -d 'Print the number of unbottled and total formulae'
Expand Down
5 changes: 3 additions & 2 deletions completions/zsh/_brew
Original file line number Diff line number Diff line change
Expand Up @@ -1846,12 +1846,13 @@ _brew_typecheck() {
_brew_unbottled() {
_arguments \
'--debug[Display any debugging information]' \
'(--total)--dependents[Skip getting analytics data and sort by number of dependents instead]' \
'(--total --lost)--dependents[Skip getting analytics data and sort by number of dependents instead]' \
'--eval-all[Evaluate all available formulae and casks, whether installed or not, to check them. Implied if `HOMEBREW_EVAL_ALL` is set]' \
'--help[Show this message]' \
'(--dependents --total)--lost[Print the `homebrew/core` commits where bottles were lost in the last week]' \
'--quiet[Make some output more quiet]' \
'--tag[Use the specified bottle tag (e.g. `big_sur`) instead of the current OS]' \
'(--dependents)--total[Print the number of unbottled and total formulae]' \
'(--dependents --lost)--total[Print the number of unbottled and total formulae]' \
'--verbose[Make some output more verbose]' \
- formula \
'*::formula:__brew_formulae'
Expand Down
2 changes: 2 additions & 0 deletions docs/Manpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -1626,6 +1626,8 @@ Show the unbottled dependents of formulae.
Skip getting analytics data and sort by number of dependents instead.
* `--total`:
Print the number of unbottled and total formulae.
* `--lost`:
Print the `homebrew/core` commits where bottles were lost in the last week.
* `--eval-all`:
Evaluate all available formulae and casks, whether installed or not, to check them. Implied if `HOMEBREW_EVAL_ALL` is set.

Expand Down
4 changes: 4 additions & 0 deletions manpages/brew.1
Original file line number Diff line number Diff line change
Expand Up @@ -2339,6 +2339,10 @@ Skip getting analytics data and sort by number of dependents instead\.
Print the number of unbottled and total formulae\.
.
.TP
\fB\-\-lost\fR
Print the \fBhomebrew/core\fR commits where bottles were lost in the last week\.
.
.TP
\fB\-\-eval\-all\fR
Evaluate all available formulae and casks, whether installed or not, to check them\. Implied if \fBHOMEBREW_EVAL_ALL\fR is set\.
.
Expand Down