formula: add preset pour_bottle? symbols
This commit is contained in:
parent
d45832bbfc
commit
5e9fcafbd8
@ -2918,8 +2918,34 @@ class Formula
|
||||
#
|
||||
# If `satisfy` returns `false` then a bottle will not be used and instead
|
||||
# the {Formula} will be built from source and `reason` will be printed.
|
||||
def pour_bottle?(&block)
|
||||
#
|
||||
# Alternatively, a preset reason can be passed as a symbol:
|
||||
# <pre>pour_bottle? :default_prefix_required</pre>
|
||||
# <pre>pour_bottle? :clt_required</pre>
|
||||
def pour_bottle?(requirement = nil, &block)
|
||||
@pour_bottle_check = PourBottleCheck.new(self)
|
||||
|
||||
block ||= case requirement
|
||||
when :default_prefix_required
|
||||
lambda do |_|
|
||||
T.cast(self, PourBottleCheck).reason(+<<~EOS)
|
||||
The bottle needs to be installed into #{Homebrew::DEFAULT_PREFIX}.
|
||||
EOS
|
||||
T.cast(self, PourBottleCheck).satisfy { HOMEBREW_PREFIX.to_s == Homebrew::DEFAULT_PREFIX }
|
||||
end
|
||||
when :clt_required
|
||||
lambda do |_|
|
||||
on_macos do
|
||||
T.cast(self, PourBottleCheck).reason(+<<~EOS)
|
||||
The bottle needs the Apple Command Line Tools to be installed.
|
||||
You can install them, if desired, with:
|
||||
xcode-select --install
|
||||
EOS
|
||||
T.cast(self, PourBottleCheck).satisfy { MacOS::CLT.installed? }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@pour_bottle_check.instance_eval(&block)
|
||||
end
|
||||
|
||||
|
||||
@ -995,6 +995,31 @@ describe Formula do
|
||||
|
||||
expect(f).to pour_bottle
|
||||
end
|
||||
|
||||
it "returns false when set with a symbol" do
|
||||
f = formula "foo" do
|
||||
url "foo-1.0"
|
||||
|
||||
pour_bottle? :default_prefix_required
|
||||
end
|
||||
|
||||
# Homebrew::DEFAULT_PREFIX is still /usr/local or /opt/homebrew
|
||||
# and HOMEBREW_PREFIX is a temporary test directory
|
||||
expect(f).not_to pour_bottle
|
||||
end
|
||||
|
||||
it "returns true when set with a symbol" do
|
||||
# Ensure that prefix matches the default
|
||||
stub_const "Homebrew::DEFAULT_PREFIX", HOMEBREW_PREFIX.to_s
|
||||
|
||||
f = formula "foo" do
|
||||
url "foo-1.0"
|
||||
|
||||
pour_bottle? :default_prefix_required
|
||||
end
|
||||
|
||||
expect(f).to pour_bottle
|
||||
end
|
||||
end
|
||||
|
||||
describe "alias changes" do
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user