Merge pull request #6803 from MikeMcQuaid/latest_version_installed

Rename Formula#installed? to Formula#latest_version_installed?
This commit is contained in:
Mike McQuaid 2019-12-03 12:09:01 +00:00 committed by GitHub
commit 6decac5875
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 57 additions and 41 deletions

View File

@ -2,3 +2,4 @@
require "compat/cask/dsl/version" require "compat/cask/dsl/version"
require "compat/requirements/macos_requirement" require "compat/requirements/macos_requirement"
require "compat/formula"

View File

@ -0,0 +1,13 @@
# frozen_string_literal: true
class Formula
module Compat
def installed?
# odeprecated "Formula#installed?",
# "Formula#latest_version_installed? (or Formula#any_version_installed? )"
latest_version_installed?
end
end
prepend Compat
end

View File

@ -39,7 +39,9 @@ class Dependency
formula formula
end end
delegate installed?: :to_formula def installed?
to_formula.latest_version_installed?
end
def satisfied?(inherited_options) def satisfied?(inherited_options)
installed? && missing_options(inherited_options).empty? installed? && missing_options(inherited_options).empty?

View File

@ -95,7 +95,7 @@ module Homebrew
def ensure_relocation_formulae_installed! def ensure_relocation_formulae_installed!
Keg.relocation_formulae.each do |f| Keg.relocation_formulae.each do |f|
next if Formula[f].installed? next if Formula[f].latest_version_installed?
ohai "Installing #{f}..." ohai "Installing #{f}..."
safe_system HOMEBREW_BREW_FILE, "install", f safe_system HOMEBREW_BREW_FILE, "install", f
@ -205,7 +205,7 @@ module Homebrew
end end
def bottle_formula(f) def bottle_formula(f)
return ofail "Formula not installed or up-to-date: #{f.full_name}" unless f.installed? return ofail "Formula not installed or up-to-date: #{f.full_name}" unless f.latest_version_installed?
unless tap = f.tap unless tap = f.tap
return ofail "Formula not from core or any installed taps: #{f.full_name}" unless args.force_core_tap? return ofail "Formula not from core or any installed taps: #{f.full_name}" unless args.force_core_tap?

View File

@ -40,7 +40,7 @@ module Homebrew
ARGV.resolved_formulae.each do |f| ARGV.resolved_formulae.each do |f|
# Cannot test uninstalled formulae # Cannot test uninstalled formulae
unless f.installed? unless f.latest_version_installed?
ofail "Testing requires the latest version of #{f.full_name}" ofail "Testing requires the latest version of #{f.full_name}"
next next
end end

View File

@ -33,7 +33,7 @@ module Homebrew
ohai "git add vendor/bundle" ohai "git add vendor/bundle"
system "git", "add", "vendor/bundle" system "git", "add", "vendor/bundle"
if Formula["gpg"].installed? if Formula["gpg"].optlinked?
ENV["PATH"] = PATH.new(ENV["PATH"]) ENV["PATH"] = PATH.new(ENV["PATH"])
.prepend(Formula["gpg"].opt_bin) .prepend(Formula["gpg"].opt_bin)
end end

View File

@ -6,7 +6,7 @@ class OsxfuseRequirement < Requirement
download "https://github.com/libfuse/libfuse" download "https://github.com/libfuse/libfuse"
satisfy(build_env: false) do satisfy(build_env: false) do
next true if libfuse_formula_exists? && Formula["libfuse"].installed? next true if libfuse_formula_exists? && Formula["libfuse"].latest_version_installed?
includedirs = %w[ includedirs = %w[
/usr/include /usr/include

View File

@ -463,7 +463,7 @@ class Formula
# This is actually just a check for if the {#installed_prefix} directory # This is actually just a check for if the {#installed_prefix} directory
# exists and is not empty. # exists and is not empty.
# @private # @private
def installed? def latest_version_installed?
(dir = installed_prefix).directory? && !dir.children.empty? (dir = installed_prefix).directory? && !dir.children.empty?
end end
@ -1211,7 +1211,7 @@ class Formula
end end
def new_formula_available? def new_formula_available?
installed_alias_target_changed? && !latest_formula.installed? installed_alias_target_changed? && !latest_formula.latest_version_installed?
end end
def current_installed_alias_target def current_installed_alias_target
@ -1932,7 +1932,7 @@ class Formula
# @private # @private
def eligible_kegs_for_cleanup(quiet: false) def eligible_kegs_for_cleanup(quiet: false)
eligible_for_cleanup = [] eligible_for_cleanup = []
if installed? if latest_version_installed?
eligible_kegs = if head? && (head_prefix = latest_head_prefix) eligible_kegs = if head? && (head_prefix = latest_head_prefix)
installed_kegs - [Keg.new(head_prefix)] installed_kegs - [Keg.new(head_prefix)]
else else

View File

@ -343,7 +343,7 @@ class FormulaInstaller
build_bottle_postinstall if build_bottle? build_bottle_postinstall if build_bottle?
opoo "Nothing was installed to #{formula.prefix}" unless formula.installed? opoo "Nothing was installed to #{formula.prefix}" unless formula.latest_version_installed?
end_time = Time.now end_time = Time.now
Homebrew.messages.formula_installed(formula, end_time - start_time) Homebrew.messages.formula_installed(formula, end_time - start_time)
end end

View File

@ -124,17 +124,17 @@ describe Homebrew::Cleanup do
Tab.create(f, DevelopmentTools.default_compiler, :libcxx).write Tab.create(f, DevelopmentTools.default_compiler, :libcxx).write
end end
expect(f1).to be_installed expect(f1).to be_latest_version_installed
expect(f2).to be_installed expect(f2).to be_latest_version_installed
expect(f3).to be_installed expect(f3).to be_latest_version_installed
expect(f4).to be_installed expect(f4).to be_latest_version_installed
subject.cleanup_formula f3 subject.cleanup_formula f3
expect(f1).not_to be_installed expect(f1).not_to be_latest_version_installed
expect(f2).not_to be_installed expect(f2).not_to be_latest_version_installed
expect(f3).to be_installed expect(f3).to be_latest_version_installed
expect(f4).to be_installed expect(f4).to be_latest_version_installed
end end
describe "#cleanup_cask", :cask do describe "#cleanup_cask", :cask do

View File

@ -15,19 +15,19 @@ describe FormulaInstaller do
end end
def temporarily_install_bottle(formula) def temporarily_install_bottle(formula)
expect(formula).not_to be_installed expect(formula).not_to be_latest_version_installed
expect(formula).to be_bottled expect(formula).to be_bottled
expect(formula).to pour_bottle expect(formula).to pour_bottle
stub_formula_loader formula stub_formula_loader formula
stub_formula_loader formula("gcc") { url "gcc-1.0" } stub_formula_loader formula("gcc") { url "gcc-1.0" }
stub_formula_loader formula("patchelf") { url "patchelf-1.0" } stub_formula_loader formula("patchelf") { url "patchelf-1.0" }
allow(Formula["patchelf"]).to receive(:installed?).and_return(true) allow(Formula["patchelf"]).to receive(:latest_version_installed?).and_return(true)
described_class.new(formula).install described_class.new(formula).install
keg = Keg.new(formula.prefix) keg = Keg.new(formula.prefix)
expect(formula).to be_installed expect(formula).to be_latest_version_installed
begin begin
expect(Tab.for_keg(keg)).to be_poured_from_bottle expect(Tab.for_keg(keg)).to be_poured_from_bottle
@ -41,7 +41,7 @@ describe FormulaInstaller do
end end
expect(keg).not_to exist expect(keg).not_to exist
expect(formula).not_to be_installed expect(formula).not_to be_latest_version_installed
end end
specify "basic bottle install" do specify "basic bottle install" do
@ -73,13 +73,13 @@ describe FormulaInstaller do
# Testball doesn't have a bottle block, so use it to test this behavior # Testball doesn't have a bottle block, so use it to test this behavior
formula = Testball.new formula = Testball.new
expect(formula).not_to be_installed expect(formula).not_to be_latest_version_installed
expect(formula).not_to be_bottled expect(formula).not_to be_bottled
expect { expect {
described_class.new(formula).install described_class.new(formula).install
}.to raise_error(BuildToolsError) }.to raise_error(BuildToolsError)
expect(formula).not_to be_installed expect(formula).not_to be_latest_version_installed
end end
end end

View File

@ -17,7 +17,7 @@ describe FormulaInstaller do
end end
def temporary_install(formula) def temporary_install(formula)
expect(formula).not_to be_installed expect(formula).not_to be_latest_version_installed
installer = described_class.new(formula) installer = described_class.new(formula)
@ -25,7 +25,7 @@ describe FormulaInstaller do
keg = Keg.new(formula.prefix) keg = Keg.new(formula.prefix)
expect(formula).to be_installed expect(formula).to be_latest_version_installed
begin begin
Tab.clear_cache Tab.clear_cache
@ -42,7 +42,7 @@ describe FormulaInstaller do
end end
expect(keg).not_to exist expect(keg).not_to exist
expect(formula).not_to be_installed expect(formula).not_to be_latest_version_installed
end end
specify "basic installation" do specify "basic installation" do
@ -84,7 +84,7 @@ describe FormulaInstaller do
expect(formula).to have_disabled_bottle expect(formula).to have_disabled_bottle
temporary_install(formula) do |f| temporary_install(formula) do |f|
expect(f).to be_installed expect(f).to be_latest_version_installed
end end
end end

View File

@ -279,22 +279,22 @@ describe Formula do
expect(f).not_to need_migration expect(f).not_to need_migration
end end
describe "#installed?" do describe "#latest_version_installed?" do
let(:f) { Testball.new } let(:f) { Testball.new }
it "returns false if the #installed_prefix is not a directory" do it "returns false if the #installed_prefix is not a directory" do
allow(f).to receive(:installed_prefix).and_return(double(directory?: false)) allow(f).to receive(:installed_prefix).and_return(double(directory?: false))
expect(f).not_to be_installed expect(f).not_to be_latest_version_installed
end end
it "returns false if the #installed_prefix does not have children" do it "returns false if the #installed_prefix does not have children" do
allow(f).to receive(:installed_prefix).and_return(double(directory?: true, children: [])) allow(f).to receive(:installed_prefix).and_return(double(directory?: true, children: []))
expect(f).not_to be_installed expect(f).not_to be_latest_version_installed
end end
it "returns true if the #installed_prefix has children" do it "returns true if the #installed_prefix has children" do
allow(f).to receive(:installed_prefix).and_return(double(directory?: true, children: [double])) allow(f).to receive(:installed_prefix).and_return(double(directory?: true, children: [double]))
expect(f).to be_installed expect(f).to be_latest_version_installed
end end
end end
@ -871,10 +871,10 @@ describe Formula do
Tab.create(f, DevelopmentTools.default_compiler, :libcxx).write Tab.create(f, DevelopmentTools.default_compiler, :libcxx).write
end end
expect(f1).to be_installed expect(f1).to be_latest_version_installed
expect(f2).to be_installed expect(f2).to be_latest_version_installed
expect(f3).to be_installed expect(f3).to be_latest_version_installed
expect(f4).to be_installed expect(f4).to be_latest_version_installed
expect(f3.eligible_kegs_for_cleanup.sort_by(&:version)) expect(f3.eligible_kegs_for_cleanup.sort_by(&:version))
.to eq([f2, f1].map { |f| Keg.new(f.prefix) }) .to eq([f2, f1].map { |f| Keg.new(f.prefix) })
end end
@ -890,9 +890,9 @@ describe Formula do
f3.brew { f3.install } f3.brew { f3.install }
expect(f1.prefix).to eq((HOMEBREW_PINNED_KEGS/f1.name).resolved_path) expect(f1.prefix).to eq((HOMEBREW_PINNED_KEGS/f1.name).resolved_path)
expect(f1).to be_installed expect(f1).to be_latest_version_installed
expect(f2).to be_installed expect(f2).to be_latest_version_installed
expect(f3).to be_installed expect(f3).to be_latest_version_installed
expect(f3.eligible_kegs_for_cleanup).to eq([Keg.new(f2.prefix)]) expect(f3.eligible_kegs_for_cleanup).to eq([Keg.new(f2.prefix)])
end end

View File

@ -142,7 +142,7 @@ describe Formulary do
allow(described_class).to receive(:loader_for).and_call_original allow(described_class).to receive(:loader_for).and_call_original
stub_formula_loader formula("gcc") { url "gcc-1.0" } stub_formula_loader formula("gcc") { url "gcc-1.0" }
stub_formula_loader formula("patchelf") { url "patchelf-1.0" } stub_formula_loader formula("patchelf") { url "patchelf-1.0" }
allow(Formula["patchelf"]).to receive(:installed?).and_return(true) allow(Formula["patchelf"]).to receive(:latest_version_installed?).and_return(true)
end end
let(:installed_formula) { described_class.factory(formula_path) } let(:installed_formula) { described_class.factory(formula_path) }

View File

@ -11,7 +11,7 @@ module Utils
end end
def built_as?(f) def built_as?(f)
return false unless f.installed? return false unless f.latest_version_installed?
tab = Tab.for_keg(f.installed_prefix) tab = Tab.for_keg(f.installed_prefix)
tab.built_as_bottle tab.built_as_bottle