Merge pull request #18806 from Homebrew/rm-uses-ostruct
Remove OpenStruct from Uses cmd
This commit is contained in:
commit
56780f3355
@ -55,7 +55,7 @@ module Homebrew
|
|||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
only: T.nilable(Symbol),
|
only: T.nilable(Symbol),
|
||||||
ignore_unavailable: T.nilable(T::Boolean),
|
ignore_unavailable: T::Boolean,
|
||||||
method: T.nilable(Symbol),
|
method: T.nilable(Symbol),
|
||||||
uniq: T::Boolean,
|
uniq: T::Boolean,
|
||||||
warn: T::Boolean,
|
warn: T::Boolean,
|
||||||
@ -63,7 +63,7 @@ module Homebrew
|
|||||||
}
|
}
|
||||||
def to_formulae_and_casks(
|
def to_formulae_and_casks(
|
||||||
only: parent&.only_formula_or_cask,
|
only: parent&.only_formula_or_cask,
|
||||||
ignore_unavailable: nil,
|
ignore_unavailable: false,
|
||||||
method: T.unsafe(nil),
|
method: T.unsafe(nil),
|
||||||
uniq: true,
|
uniq: true,
|
||||||
warn: T.unsafe(nil)
|
warn: T.unsafe(nil)
|
||||||
@ -367,10 +367,10 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig {
|
sig {
|
||||||
params(only: T.nilable(Symbol), ignore_unavailable: T.nilable(T::Boolean), all_kegs: T.nilable(T::Boolean))
|
params(only: T.nilable(Symbol), ignore_unavailable: T::Boolean, all_kegs: T.nilable(T::Boolean))
|
||||||
.returns([T::Array[Keg], T::Array[Cask::Cask]])
|
.returns([T::Array[Keg], T::Array[Cask::Cask]])
|
||||||
}
|
}
|
||||||
def to_kegs_to_casks(only: parent&.only_formula_or_cask, ignore_unavailable: nil, all_kegs: nil)
|
def to_kegs_to_casks(only: parent&.only_formula_or_cask, ignore_unavailable: false, all_kegs: nil)
|
||||||
method = all_kegs ? :kegs : :default_kegs
|
method = all_kegs ? :kegs : :default_kegs
|
||||||
@to_kegs_to_casks ||= {}
|
@to_kegs_to_casks ||= {}
|
||||||
@to_kegs_to_casks[method] ||=
|
@to_kegs_to_casks[method] ||=
|
||||||
|
|||||||
@ -5,7 +5,6 @@ require "abstract_command"
|
|||||||
require "formula"
|
require "formula"
|
||||||
require "cask/caskroom"
|
require "cask/caskroom"
|
||||||
require "dependencies_helpers"
|
require "dependencies_helpers"
|
||||||
require "ostruct"
|
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
module Cmd
|
module Cmd
|
||||||
@ -15,6 +14,11 @@ module Homebrew
|
|||||||
class Uses < AbstractCommand
|
class Uses < AbstractCommand
|
||||||
include DependenciesHelpers
|
include DependenciesHelpers
|
||||||
|
|
||||||
|
class UnavailableFormula < T::Struct
|
||||||
|
const :name, String
|
||||||
|
const :full_name, String
|
||||||
|
end
|
||||||
|
|
||||||
cmd_args do
|
cmd_args do
|
||||||
description <<~EOS
|
description <<~EOS
|
||||||
Show formulae and casks that specify <formula> as a dependency; that is, show dependents
|
Show formulae and casks that specify <formula> as a dependency; that is, show dependents
|
||||||
@ -64,10 +68,7 @@ module Homebrew
|
|||||||
opoo e
|
opoo e
|
||||||
used_formulae_missing = true
|
used_formulae_missing = true
|
||||||
# If the formula doesn't exist: fake the needed formula object name.
|
# If the formula doesn't exist: fake the needed formula object name.
|
||||||
# This is a legacy use of OpenStruct that should be refactored.
|
args.named.map { |name| UnavailableFormula.new name:, full_name: name }
|
||||||
# rubocop:disable Style/OpenStructUse
|
|
||||||
args.named.map { |name| OpenStruct.new name:, full_name: name }
|
|
||||||
# rubocop:enable Style/OpenStructUse
|
|
||||||
end
|
end
|
||||||
|
|
||||||
use_runtime_dependents = args.installed? &&
|
use_runtime_dependents = args.installed? &&
|
||||||
@ -87,7 +88,10 @@ module Homebrew
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
sig { params(use_runtime_dependents: T::Boolean, used_formulae: T::Array[Formula]).returns(T::Array[Formula]) }
|
sig {
|
||||||
|
params(use_runtime_dependents: T::Boolean, used_formulae: T::Array[T.any(Formula, UnavailableFormula)])
|
||||||
|
.returns(T::Array[Formula])
|
||||||
|
}
|
||||||
def intersection_of_dependents(use_runtime_dependents, used_formulae)
|
def intersection_of_dependents(use_runtime_dependents, used_formulae)
|
||||||
recursive = args.recursive?
|
recursive = args.recursive?
|
||||||
show_formulae_and_casks = !args.formula? && !args.cask?
|
show_formulae_and_casks = !args.formula? && !args.cask?
|
||||||
@ -95,6 +99,8 @@ module Homebrew
|
|||||||
|
|
||||||
deps = []
|
deps = []
|
||||||
if use_runtime_dependents
|
if use_runtime_dependents
|
||||||
|
# We can only get here if `used_formulae_missing` is false, thus there are no UnavailableFormula.
|
||||||
|
used_formulae = T.cast(used_formulae, T::Array[Formula])
|
||||||
if show_formulae_and_casks || args.formula?
|
if show_formulae_and_casks || args.formula?
|
||||||
deps += used_formulae.map(&:runtime_installed_formula_dependents)
|
deps += used_formulae.map(&:runtime_installed_formula_dependents)
|
||||||
.reduce(&:&)
|
.reduce(&:&)
|
||||||
@ -140,8 +146,8 @@ module Homebrew
|
|||||||
|
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
dependents: T::Array[Formula], used_formulae: T::Array[Formula], recursive: T::Boolean,
|
dependents: T::Array[Formula], used_formulae: T::Array[T.any(Formula, UnavailableFormula)],
|
||||||
includes: T::Array[Symbol], ignores: T::Array[Symbol]
|
recursive: T::Boolean, includes: T::Array[Symbol], ignores: T::Array[Symbol]
|
||||||
).returns(
|
).returns(
|
||||||
T::Array[Formula],
|
T::Array[Formula],
|
||||||
)
|
)
|
||||||
|
|||||||
@ -2886,7 +2886,7 @@ class Formula
|
|||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def test_defined?
|
def test_defined?
|
||||||
false
|
method(:test).owner != Formula
|
||||||
end
|
end
|
||||||
|
|
||||||
def test; end
|
def test; end
|
||||||
@ -3348,12 +3348,6 @@ class Formula
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def method_added(method)
|
|
||||||
super
|
|
||||||
|
|
||||||
define_method(:test_defined?) { true } if method == :test
|
|
||||||
end
|
|
||||||
|
|
||||||
def freeze
|
def freeze
|
||||||
specs.each(&:freeze)
|
specs.each(&:freeze)
|
||||||
@livecheck.freeze
|
@livecheck.freeze
|
||||||
|
|||||||
@ -1,9 +1,6 @@
|
|||||||
# typed: strict
|
# typed: strict
|
||||||
|
|
||||||
# This file provides definitions for Forwardable#delegate, which is currently not supported by Sorbet.
|
|
||||||
|
|
||||||
class Formula
|
class Formula
|
||||||
def self.on_system_blocks_exist?; end
|
|
||||||
# This method is included by `OnSystem`
|
# This method is included by `OnSystem`
|
||||||
def self.on_macos(&block); end
|
def self.on_macos(&block); end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "cli/named_args"
|
||||||
require "cmd/shared_examples/args_parse"
|
require "cmd/shared_examples/args_parse"
|
||||||
require "cmd/uses"
|
require "cmd/uses"
|
||||||
require "fileutils"
|
require "fileutils"
|
||||||
@ -44,4 +45,22 @@ RSpec.describe Homebrew::Cmd::Uses do
|
|||||||
.and not_to_output.to_stderr
|
.and not_to_output.to_stderr
|
||||||
.and be_a_success
|
.and be_a_success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "handles unavailable formula", :integration_test do
|
||||||
|
setup_test_formula "foo"
|
||||||
|
setup_test_formula "bar"
|
||||||
|
setup_test_formula "optional", <<~RUBY
|
||||||
|
url "https://brew.sh/optional-1.0"
|
||||||
|
depends_on "bar" => :optional
|
||||||
|
RUBY
|
||||||
|
|
||||||
|
expect_any_instance_of(Homebrew::CLI::NamedArgs)
|
||||||
|
.to receive(:to_formulae)
|
||||||
|
.and_raise(FormulaUnavailableError, "foo")
|
||||||
|
cmd = described_class.new(%w[foo --eval-all --include-optional --recursive])
|
||||||
|
expect { cmd.run }
|
||||||
|
.to output(/^(bar\noptional|optional\nbar)$/).to_stdout
|
||||||
|
.and output(/Error: Missing formulae should not have dependents!\n/).to_stderr
|
||||||
|
.and raise_error SystemExit
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user