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

Rename Formula#installed? to Formula#latest_version_installed? #6803

Merged
merged 1 commit into from Dec 3, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Library/Homebrew/compat.rb
Expand Up @@ -2,3 +2,4 @@

require "compat/cask/dsl/version"
require "compat/requirements/macos_requirement"
require "compat/formula"
13 changes: 13 additions & 0 deletions Library/Homebrew/compat/formula.rb
@@ -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
4 changes: 3 additions & 1 deletion Library/Homebrew/dependency.rb
Expand Up @@ -39,7 +39,9 @@ def to_formula
formula
end

delegate installed?: :to_formula
def installed?
to_formula.latest_version_installed?
end

def satisfied?(inherited_options)
installed? && missing_options(inherited_options).empty?
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/dev-cmd/bottle.rb
Expand Up @@ -95,7 +95,7 @@ def bottle

def ensure_relocation_formulae_installed!
Keg.relocation_formulae.each do |f|
next if Formula[f].installed?
next if Formula[f].latest_version_installed?

ohai "Installing #{f}..."
safe_system HOMEBREW_BREW_FILE, "install", f
Expand Down Expand Up @@ -205,7 +205,7 @@ def bottle_output(bottle)
end

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
return ofail "Formula not from core or any installed taps: #{f.full_name}" unless args.force_core_tap?
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/test.rb
Expand Up @@ -40,7 +40,7 @@ def test

ARGV.resolved_formulae.each do |f|
# Cannot test uninstalled formulae
unless f.installed?
unless f.latest_version_installed?
ofail "Testing requires the latest version of #{f.full_name}"
next
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/vendor-gems.rb
Expand Up @@ -33,7 +33,7 @@ def vendor_gems
ohai "git add vendor/bundle"
system "git", "add", "vendor/bundle"

if Formula["gpg"].installed?
if Formula["gpg"].optlinked?
ENV["PATH"] = PATH.new(ENV["PATH"])
.prepend(Formula["gpg"].opt_bin)
end
Expand Down
Expand Up @@ -6,7 +6,7 @@ class OsxfuseRequirement < Requirement
download "https://github.com/libfuse/libfuse"

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[
/usr/include
Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/formula.rb
Expand Up @@ -463,7 +463,7 @@ def aliases
# This is actually just a check for if the {#installed_prefix} directory
# exists and is not empty.
# @private
def installed?
def latest_version_installed?
(dir = installed_prefix).directory? && !dir.children.empty?
end

Expand Down Expand Up @@ -1211,7 +1211,7 @@ def outdated_kegs(fetch_head: false)
end

def new_formula_available?
installed_alias_target_changed? && !latest_formula.installed?
installed_alias_target_changed? && !latest_formula.latest_version_installed?
end

def current_installed_alias_target
Expand Down Expand Up @@ -1932,7 +1932,7 @@ def system(cmd, *args)
# @private
def eligible_kegs_for_cleanup(quiet: false)
eligible_for_cleanup = []
if installed?
if latest_version_installed?
eligible_kegs = if head? && (head_prefix = latest_head_prefix)
installed_kegs - [Keg.new(head_prefix)]
else
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/formula_installer.rb
Expand Up @@ -343,7 +343,7 @@ def install

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
Homebrew.messages.formula_installed(formula, end_time - start_time)
end
Expand Down
16 changes: 8 additions & 8 deletions Library/Homebrew/test/cleanup_spec.rb
Expand Up @@ -124,17 +124,17 @@
Tab.create(f, DevelopmentTools.default_compiler, :libcxx).write
end

expect(f1).to be_installed
expect(f2).to be_installed
expect(f3).to be_installed
expect(f4).to be_installed
expect(f1).to be_latest_version_installed
expect(f2).to be_latest_version_installed
expect(f3).to be_latest_version_installed
expect(f4).to be_latest_version_installed

subject.cleanup_formula f3

expect(f1).not_to be_installed
expect(f2).not_to be_installed
expect(f3).to be_installed
expect(f4).to be_installed
expect(f1).not_to be_latest_version_installed
expect(f2).not_to be_latest_version_installed
expect(f3).to be_latest_version_installed
expect(f4).to be_latest_version_installed
end

describe "#cleanup_cask", :cask do
Expand Down
12 changes: 6 additions & 6 deletions Library/Homebrew/test/formula_installer_bottle_spec.rb
Expand Up @@ -15,19 +15,19 @@
end

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 pour_bottle

stub_formula_loader formula
stub_formula_loader formula("gcc") { url "gcc-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

keg = Keg.new(formula.prefix)

expect(formula).to be_installed
expect(formula).to be_latest_version_installed

begin
expect(Tab.for_keg(keg)).to be_poured_from_bottle
Expand All @@ -41,7 +41,7 @@ def temporarily_install_bottle(formula)
end

expect(keg).not_to exist
expect(formula).not_to be_installed
expect(formula).not_to be_latest_version_installed
end

specify "basic bottle install" do
Expand Down Expand Up @@ -73,13 +73,13 @@ def temporarily_install_bottle(formula)
# Testball doesn't have a bottle block, so use it to test this behavior
formula = Testball.new

expect(formula).not_to be_installed
expect(formula).not_to be_latest_version_installed
expect(formula).not_to be_bottled

expect {
described_class.new(formula).install
}.to raise_error(BuildToolsError)

expect(formula).not_to be_installed
expect(formula).not_to be_latest_version_installed
end
end
8 changes: 4 additions & 4 deletions Library/Homebrew/test/formula_installer_spec.rb
Expand Up @@ -17,15 +17,15 @@
end

def temporary_install(formula)
expect(formula).not_to be_installed
expect(formula).not_to be_latest_version_installed

installer = described_class.new(formula)

installer.install

keg = Keg.new(formula.prefix)

expect(formula).to be_installed
expect(formula).to be_latest_version_installed

begin
Tab.clear_cache
Expand All @@ -42,7 +42,7 @@ def temporary_install(formula)
end

expect(keg).not_to exist
expect(formula).not_to be_installed
expect(formula).not_to be_latest_version_installed
end

specify "basic installation" do
Expand Down Expand Up @@ -84,7 +84,7 @@ def temporary_install(formula)
expect(formula).to have_disabled_bottle

temporary_install(formula) do |f|
expect(f).to be_installed
expect(f).to be_latest_version_installed
end
end

Expand Down
22 changes: 11 additions & 11 deletions Library/Homebrew/test/formula_spec.rb
Expand Up @@ -279,22 +279,22 @@
expect(f).not_to need_migration
end

describe "#installed?" do
describe "#latest_version_installed?" do
let(:f) { Testball.new }

it "returns false if the #installed_prefix is not a directory" do
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

it "returns false if the #installed_prefix does not have children" do
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

it "returns true if the #installed_prefix has children" do
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

Expand Down Expand Up @@ -871,10 +871,10 @@ def test
Tab.create(f, DevelopmentTools.default_compiler, :libcxx).write
end

expect(f1).to be_installed
expect(f2).to be_installed
expect(f3).to be_installed
expect(f4).to be_installed
expect(f1).to be_latest_version_installed
expect(f2).to be_latest_version_installed
expect(f3).to be_latest_version_installed
expect(f4).to be_latest_version_installed
expect(f3.eligible_kegs_for_cleanup.sort_by(&:version))
.to eq([f2, f1].map { |f| Keg.new(f.prefix) })
end
Expand All @@ -890,9 +890,9 @@ def test
f3.brew { f3.install }

expect(f1.prefix).to eq((HOMEBREW_PINNED_KEGS/f1.name).resolved_path)
expect(f1).to be_installed
expect(f2).to be_installed
expect(f3).to be_installed
expect(f1).to be_latest_version_installed
expect(f2).to be_latest_version_installed
expect(f3).to be_latest_version_installed
expect(f3.eligible_kegs_for_cleanup).to eq([Keg.new(f2.prefix)])
end

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/formulary_spec.rb
Expand Up @@ -142,7 +142,7 @@ class Wrong#{described_class.class_s(formula_name)} < Formula
allow(described_class).to receive(:loader_for).and_call_original
stub_formula_loader formula("gcc") { url "gcc-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

let(:installed_formula) { described_class.factory(formula_path) }
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/utils/bottles.rb
Expand Up @@ -11,7 +11,7 @@ def tag
end

def built_as?(f)
return false unless f.installed?
return false unless f.latest_version_installed?

tab = Tab.for_keg(f.installed_prefix)
tab.built_as_bottle
Expand Down