Merge pull request #18011 from Homebrew/more-srb-strict-cmd

This commit is contained in:
Mike McQuaid 2024-08-12 14:21:18 +01:00 committed by GitHub
commit fd14deaebd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 77 additions and 21 deletions

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require "abstract_command"
@ -91,6 +91,7 @@ module Homebrew
private
sig { void }
def list_unbrewed
dirs = HOMEBREW_PREFIX.subdirs.map { |dir| dir.basename.to_s }
dirs -= %w[Library Cellar Caskroom .git]

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require "abstract_command"
@ -33,11 +33,14 @@ module Homebrew
def run
Install.perform_preinstall_checks(all_fatal: true)
Install.perform_build_from_source_checks(all_fatal: true)
gistify_logs(args.named.to_resolved_formulae.first)
return unless (formula = args.named.to_resolved_formulae.first)
gistify_logs(formula)
end
private
sig { params(formula: Formula).void }
def gistify_logs(formula)
files = load_logs(formula.logs)
build_time = formula.logs.ctime
@ -86,6 +89,7 @@ module Homebrew
puts url if url
end
sig { params(formula: Formula, with_hostname: T::Boolean).returns(String) }
def brief_build_info(formula, with_hostname:)
build_time_string = formula.logs.ctime.strftime("%Y-%m-%d %H:%M:%S")
string = +<<~EOS
@ -100,6 +104,7 @@ module Homebrew
end
# Causes some terminals to display secure password entry indicators.
sig { void }
def noecho_gets
system "stty", "-echo"
result = $stdin.gets
@ -108,6 +113,7 @@ module Homebrew
result
end
sig { params(dir: Pathname, basedir: Pathname).returns(T::Hash[String, T::Hash[Symbol, String]]) }
def load_logs(dir, basedir = dir)
logs = {}
if dir.exist?

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require "abstract_command"
@ -41,6 +41,7 @@ module Homebrew
private
sig { params(formula_or_cask: T.any(Formula, Cask::Cask)).returns(String) }
def name_of(formula_or_cask)
if formula_or_cask.is_a? Formula
"Formula #{formula_or_cask.name}"

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require "abstract_command"
@ -39,12 +39,14 @@ module Homebrew
private
sig { params(formula: Formula).returns(T::Boolean) }
def installed_on_request?(formula)
formula.any_installed_keg.tab.installed_on_request
formula.any_installed_keg&.tab&.installed_on_request
end
sig { params(formula: Formula).returns(T::Boolean) }
def installed_as_dependency?(formula)
formula.any_installed_keg.tab.installed_as_dependency
formula.any_installed_keg&.tab&.installed_as_dependency
end
end
end

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require "abstract_command"
@ -123,6 +123,7 @@ module Homebrew
private
sig { params(keg: Keg).void }
def puts_keg_only_path_message(keg)
bin = keg/"bin"
sbin = keg/"sbin"

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require "abstract_command"
@ -160,6 +160,7 @@ module Homebrew
private
sig { void }
def filtered_list
names = if args.no_named?
Formula.racks
@ -189,6 +190,7 @@ module Homebrew
end
end
sig { void }
def list_casks
casks = if args.no_named?
Cask::Caskroom.casks
@ -212,6 +214,7 @@ module Homebrew
end
class PrettyListing
sig { params(path: T.any(String, Pathname, Keg)).void }
def initialize(path)
Pathname.new(path).children.sort_by { |p| p.to_s.downcase }.each do |pn|
case pn.basename.to_s
@ -240,7 +243,8 @@ module Homebrew
private
def print_dir(root)
sig { params(root: Pathname, block: T.nilable(T.proc.params(arg0: Pathname).returns(T::Boolean))).void }
def print_dir(root, &block)
dirs = []
remaining_root_files = []
other = ""
@ -248,7 +252,7 @@ module Homebrew
root.children.sort.each do |pn|
if pn.directory?
dirs << pn
elsif block_given? && yield(pn)
elsif block && yield(pn)
puts pn
other = "other "
elsif pn.basename.to_s != ".DS_Store"
@ -265,6 +269,7 @@ module Homebrew
print_remaining_files remaining_root_files, root, other
end
sig { params(files: T::Array[Pathname], root: Pathname, other: String).void }
def print_remaining_files(files, root, other = "")
if files.length == 1
puts files

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require "abstract_command"
@ -54,6 +54,7 @@ module Homebrew
private
sig { params(formulae: T::Array[Formula]).void }
def puts_options(formulae)
formulae.each do |f|
next if f.options.empty?

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require "abstract_command"
@ -86,6 +86,7 @@ module Homebrew
private
sig { params(formulae_or_casks: T::Array[T.any(Formula, Cask::Cask)]).void }
def print_outdated(formulae_or_casks)
formulae_or_casks.each do |formula_or_cask|
if formula_or_cask.is_a?(Formula)
@ -124,6 +125,13 @@ module Homebrew
end
end
sig {
params(
formulae_or_casks: T::Array[T.any(Formula, Cask::Cask)],
).returns(
T::Array[T.any(T::Hash[String, T.untyped], T::Hash[String, T.untyped])],
)
}
def json_info(formulae_or_casks)
formulae_or_casks.map do |formula_or_cask|
if formula_or_cask.is_a?(Formula)
@ -149,10 +157,12 @@ module Homebrew
end
end
sig { returns(T::Boolean) }
def verbose?
($stdout.tty? || Context.current.verbose?) && !Context.current.quiet?
end
sig { params(version: T.nilable(T.any(TrueClass, String))).returns(T.nilable(Symbol)) }
def json_version(version)
version_hash = {
nil => nil,
@ -166,18 +176,26 @@ module Homebrew
version_hash[version]
end
sig { returns(T::Array[Formula]) }
def outdated_formulae
select_outdated((args.named.to_resolved_formulae.presence || Formula.installed)).sort
T.cast(
select_outdated((args.named.to_resolved_formulae.presence || Formula.installed)).sort,
T::Array[Formula],
)
end
sig { returns(T::Array[Cask::Cask]) }
def outdated_casks
if args.named.present?
outdated = if args.named.present?
select_outdated(args.named.to_casks)
else
select_outdated(Cask::Caskroom.casks)
end
T.cast(outdated, T::Array[Cask::Cask])
end
sig { returns([T::Array[T.any(Formula, Cask::Cask)], T::Array[T.any(Formula, Cask::Cask)]]) }
def outdated_formulae_casks
formulae, casks = args.named.to_resolved_formulae_to_casks
@ -189,6 +207,9 @@ module Homebrew
[select_outdated(formulae).sort, select_outdated(casks)]
end
sig {
params(formulae_or_casks: T::Array[T.any(Formula, Cask::Cask)]).returns(T::Array[T.any(Formula, Cask::Cask)])
}
def select_outdated(formulae_or_casks)
formulae_or_casks.select do |formula_or_cask|
if formula_or_cask.is_a?(Formula)

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require "abstract_command"
@ -10,7 +10,7 @@ require "search"
module Homebrew
module Cmd
class SearchCmd < AbstractCommand
PACKAGE_MANAGERS = {
PACKAGE_MANAGERS = T.let({
repology: ->(query) { "https://repology.org/projects/?search=#{query}" },
macports: ->(query) { "https://ports.macports.org/search/?q=#{query}" },
fink: ->(query) { "https://pdb.finkproject.org/pdb/browse.php?summary=#{query}" },
@ -23,7 +23,7 @@ module Homebrew
ubuntu: lambda { |query|
"https://packages.ubuntu.com/search?keywords=#{query}&searchon=names&suite=all&section=all"
},
}.freeze
}.freeze, T::Hash[Symbol, T.proc.params(query: String).returns(String)])
cmd_args do
description <<~EOS
@ -89,6 +89,7 @@ module Homebrew
private
sig { void }
def print_regex_help
return unless $stdout.tty?
@ -105,6 +106,7 @@ module Homebrew
EOS
end
sig { returns(T::Boolean) }
def search_package_manager
package_manager = PACKAGE_MANAGERS.find { |name,| args[:"#{name}?"] }
return false if package_manager.nil?
@ -114,6 +116,7 @@ module Homebrew
true
end
sig { params(query: String).returns(String) }
def search_pull_requests(query)
only = if args.open? && !args.closed?
"open"
@ -124,6 +127,7 @@ module Homebrew
GitHub.print_pull_requests_matching(query, only)
end
sig { params(all_formulae: T::Array[String], all_casks: T::Array[String], query: String).void }
def print_results(all_formulae, all_casks, query)
count = all_formulae.size + all_casks.size
@ -148,6 +152,7 @@ module Homebrew
odie "No formulae or casks found for #{query.inspect}." if count.zero?
end
sig { params(query: String, found_matches: T::Boolean).void }
def print_missing_formula_help(query, found_matches)
return unless $stdout.tty?

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require "abstract_command"
@ -42,6 +42,7 @@ module Homebrew
private
sig { params(taps: T::Array[Tap]).void }
def print_tap_info(taps)
if taps.none?
tap_count = 0
@ -83,6 +84,7 @@ module Homebrew
end
end
sig { params(taps: T::Array[Tap]).void }
def print_tap_json(taps)
puts JSON.pretty_generate(taps.map(&:to_hash))
end

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require "abstract_command"
@ -87,6 +87,7 @@ module Homebrew
private
sig { params(use_runtime_dependents: T::Boolean, used_formulae: T::Array[Formula]).returns(T::Array[Formula]) }
def intersection_of_dependents(use_runtime_dependents, used_formulae)
recursive = args.recursive?
show_formulae_and_casks = !args.formula? && !args.cask?
@ -137,6 +138,14 @@ module Homebrew
end
end
sig {
params(
dependents: T::Array[Formula], used_formulae: T::Array[Formula], recursive: T::Boolean,
includes: T::Array[Symbol], ignores: T::Array[Symbol]
).returns(
T::Array[Formula],
)
}
def select_used_dependents(dependents, used_formulae, recursive, includes, ignores)
dependents.select do |d|
deps = if recursive

View File

@ -1,13 +1,15 @@
# typed: true
# typed: strict
# frozen_string_literal: true
module Homebrew
module_function
sig { returns(String) }
def no_changes_message
"No changes to formulae."
end
sig { void }
def migrate_gcc_dependents_if_needed
return if Settings.read("gcc-rpaths.fixed") == "true"