Skip to content

Commit

Permalink
Merge pull request #967 from dawidd6/homebrew_brew_file
Browse files Browse the repository at this point in the history
bundle: use HOMEBREW_BREW_FILE
  • Loading branch information
Bo98 authored May 28, 2021
2 parents 932fdbe + 21c63c7 commit 916be52
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 49 deletions.
14 changes: 7 additions & 7 deletions lib/bundle/brew_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,20 @@ def link_change_state!(verbose: false)
when true
unless linked_and_keg_only?
puts "Force-linking #{@name} formula." if verbose
Bundle.system("brew", "link", "--force", @name, verbose: verbose)
Bundle.system(HOMEBREW_BREW_FILE, "link", "--force", @name, verbose: verbose)
end
when false
unless unlinked_and_not_keg_only?
puts "Unlinking #{@name} formula." if verbose
Bundle.system("brew", "unlink", @name, verbose: verbose)
Bundle.system(HOMEBREW_BREW_FILE, "unlink", @name, verbose: verbose)
end
when nil
if unlinked_and_not_keg_only?
puts "Linking #{@name} formula." if verbose
Bundle.system("brew", "link", @name, verbose: verbose)
Bundle.system(HOMEBREW_BREW_FILE, "link", @name, verbose: verbose)
elsif linked_and_keg_only?
puts "Unlinking #{@name} formula." if verbose
Bundle.system("brew", "unlink", @name, verbose: verbose)
Bundle.system(HOMEBREW_BREW_FILE, "unlink", @name, verbose: verbose)
end
end
end
Expand Down Expand Up @@ -204,7 +204,7 @@ def resolve_conflicts!(verbose:)
It is currently installed and conflicts with #{@name}.
EOS
end
return false unless Bundle.system("brew", "unlink", conflict, verbose: verbose)
return false unless Bundle.system(HOMEBREW_BREW_FILE, "unlink", conflict, verbose: verbose)

if @restart_service
puts "Stopping #{conflict} service (if it is running)." if verbose
Expand All @@ -217,7 +217,7 @@ def resolve_conflicts!(verbose:)

def install!(verbose:)
puts "Installing #{@name} formula. It is not currently installed." if verbose
unless Bundle.system("brew", "install", "--formula", @full_name, *@args, verbose: verbose)
unless Bundle.system(HOMEBREW_BREW_FILE, "install", "--formula", @full_name, *@args, verbose: verbose)
@changed = nil
return :failed
end
Expand All @@ -235,7 +235,7 @@ def upgrade!(verbose:)
end

puts "Upgrading #{@name} formula. It is installed but not up-to-date." if verbose
unless Bundle.system("brew", "upgrade", "--formula", @name, verbose: verbose)
unless Bundle.system(HOMEBREW_BREW_FILE, "upgrade", "--formula", @name, verbose: verbose)
@changed = nil
return :failed
end
Expand Down
4 changes: 2 additions & 2 deletions lib/bundle/brew_services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ def reset!
def stop(name, verbose: false)
return true unless started?(name)

return unless Bundle.system "brew", "services", "stop", name, verbose: verbose
return unless Bundle.system HOMEBREW_BREW_FILE, "services", "stop", name, verbose: verbose

started_services.delete(name)
true
end

def restart(name, verbose: false)
return unless Bundle.system "brew", "services", "restart", name, verbose: verbose
return unless Bundle.system HOMEBREW_BREW_FILE, "services", "restart", name, verbose: verbose

started_services << name
true
Expand Down
4 changes: 2 additions & 2 deletions lib/bundle/cask_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def install(name, no_upgrade: false, verbose: false, **options)
if !no_upgrade && (outdated_casks.include?(name) || all_outdated_casks.include?(name) && greedy)
status = "#{greedy ? "may not be" : "not"} up-to-date"
puts "Upgrading #{name} cask. It is installed but #{status}." if verbose
return :failed unless Bundle.system "brew", "upgrade", "--cask", full_name, verbose: verbose
return :failed unless Bundle.system HOMEBREW_BREW_FILE, "upgrade", "--cask", full_name, verbose: verbose

return :success
end
Expand All @@ -38,7 +38,7 @@ def install(name, no_upgrade: false, verbose: false, **options)

puts "Installing #{name} cask. It is not currently installed." if verbose

return :failed unless Bundle.system "brew", "install", "--cask", full_name, *args, verbose: verbose
return :failed unless Bundle.system HOMEBREW_BREW_FILE, "install", "--cask", full_name, *args, verbose: verbose

installed_casks << name
:success
Expand Down
10 changes: 5 additions & 5 deletions lib/bundle/commands/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ def run(global: false, file: nil, force: false, zap: false)
if force
if casks.any?
args = zap ? ["--zap"] : []
Kernel.system "brew", "uninstall", "--cask", *args, "--force", *casks
Kernel.system HOMEBREW_BREW_FILE, "uninstall", "--cask", *args, "--force", *casks
puts "Uninstalled #{casks.size} cask#{(casks.size == 1) ? "" : "s"}"
end

if formulae.any?
Kernel.system "brew", "uninstall", "--formula", "--force", *formulae
Kernel.system HOMEBREW_BREW_FILE, "uninstall", "--formula", "--force", *formulae
puts "Uninstalled #{formulae.size} formula#{(formulae.size == 1) ? "" : "e"}"
end

Kernel.system "brew", "untap", *taps if taps.any?
Kernel.system HOMEBREW_BREW_FILE, "untap", *taps if taps.any?

cleanup = system_output_no_stderr("brew", "cleanup")
cleanup = system_output_no_stderr(HOMEBREW_BREW_FILE, "cleanup")
puts cleanup unless cleanup.empty?
else
if casks.any?
Expand All @@ -53,7 +53,7 @@ def run(global: false, file: nil, force: false, zap: false)
puts Formatter.columns taps
end

cleanup = system_output_no_stderr("brew", "cleanup", "--dry-run")
cleanup = system_output_no_stderr(HOMEBREW_BREW_FILE, "cleanup", "--dry-run")
unless cleanup.empty?
puts "Would `brew cleanup`:"
puts cleanup
Expand Down
2 changes: 1 addition & 1 deletion lib/bundle/mac_app_store_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def reset!
def install(name, id, no_upgrade: false, verbose: false)
unless Bundle.mas_installed?
puts "Installing mas. It is not currently installed." if verbose
Bundle.system "brew", "install", "mas", verbose: verbose
Bundle.system HOMEBREW_BREW_FILE, "install", "mas", verbose: verbose
raise "Unable to install #{name} app. mas installation failed." unless Bundle.mas_installed?
end

Expand Down
4 changes: 2 additions & 2 deletions lib/bundle/tap_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ def install(name, verbose: false, **options)

puts "Installing #{name} tap. It is not currently installed." if verbose
success = if options[:clone_target]
Bundle.system "brew", "tap", name, options[:clone_target], verbose: verbose
Bundle.system HOMEBREW_BREW_FILE, "tap", name, options[:clone_target], verbose: verbose
else
Bundle.system "brew", "tap", name, verbose: verbose
Bundle.system HOMEBREW_BREW_FILE, "tap", name, verbose: verbose
end

return :failed unless success
Expand Down
2 changes: 1 addition & 1 deletion lib/bundle/whalebrew_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def reset!
def install(name, verbose: false, **_options)
unless Bundle.whalebrew_installed?
puts "Installing whalebrew. It is not currently installed." if verbose
Bundle.system "brew", "install", "whalebrew", verbose: verbose
Bundle.system HOMEBREW_BREW_FILE, "install", "whalebrew", verbose: verbose
raise "Unable to install #{name} app. Whalebrew installation failed." unless Bundle.whalebrew_installed?
end

Expand Down
26 changes: 15 additions & 11 deletions spec/bundle/brew_installer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def do_install
end

it "links formula" do
expect(Bundle).to receive(:system).with("brew", "link", "--force", "mysql", verbose: false).and_return(true)
expect(Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "link", "--force", "mysql",
verbose: false).and_return(true)
described_class.install(formula, link: true)
end
end
Expand All @@ -53,7 +54,7 @@ def do_install
end

it "unlinks formula" do
expect(Bundle).to receive(:system).with("brew", "unlink", "mysql", verbose: false).and_return(true)
expect(Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "unlink", "mysql", verbose: false).and_return(true)
described_class.install(formula, link: false)
end
end
Expand All @@ -65,7 +66,7 @@ def do_install

it "links formula" do
allow_any_instance_of(described_class).to receive(:unlinked_and_not_keg_only?).and_return(true)
expect(Bundle).to receive(:system).with("brew", "link", "mysql", verbose: false).and_return(true)
expect(Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "link", "mysql", verbose: false).and_return(true)
described_class.install(formula, link: nil)
end
end
Expand All @@ -77,7 +78,7 @@ def do_install

it "unlinks formula" do
allow_any_instance_of(described_class).to receive(:linked_and_keg_only?).and_return(true)
expect(Bundle).to receive(:system).with("brew", "unlink", "mysql", verbose: false).and_return(true)
expect(Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "unlink", "mysql", verbose: false).and_return(true)
described_class.install(formula, link: nil)
end
end
Expand All @@ -93,8 +94,10 @@ def do_install
end

def sane?(verbose:)
expect(Bundle).to receive(:system).with("brew", "unlink", "mysql55", verbose: verbose).and_return(true)
expect(Bundle).to receive(:system).with("brew", "unlink", "mysql56", verbose: verbose).and_return(true)
expect(Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "unlink", "mysql55",
verbose: verbose).and_return(true)
expect(Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "unlink", "mysql56",
verbose: verbose).and_return(true)
expect(Bundle::BrewServices).to receive(:stop).with("mysql55", verbose: verbose).and_return(true)
expect(Bundle::BrewServices).to receive(:stop).with("mysql56", verbose: verbose).and_return(true)
expect(Bundle::BrewServices).to receive(:restart).with(formula, verbose: verbose).and_return(true)
Expand Down Expand Up @@ -185,14 +188,14 @@ def sane?(verbose:)

it "install formula" do
expect(Bundle).to receive(:system)
.with("brew", "install", "--formula", formula, "--with-option", verbose: false)
.with(HOMEBREW_BREW_FILE, "install", "--formula", formula, "--with-option", verbose: false)
.and_return(true)
expect(do_install).to be(:success)
end

it "reports a failure" do
expect(Bundle).to receive(:system)
.with("brew", "install", "--formula", formula, "--with-option", verbose: false)
.with(HOMEBREW_BREW_FILE, "install", "--formula", formula, "--with-option", verbose: false)
.and_return(false)
expect(do_install).to be(:failed)
end
Expand All @@ -211,13 +214,13 @@ def sane?(verbose:)
end

it "upgrade formula" do
expect(Bundle).to receive(:system).with("brew", "upgrade", "--formula", formula, verbose: false)
expect(Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "upgrade", "--formula", formula, verbose: false)
.and_return(true)
expect(do_install).to be(:success)
end

it "reports a failure" do
expect(Bundle).to receive(:system).with("brew", "upgrade", "--formula", formula, verbose: false)
expect(Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "upgrade", "--formula", formula, verbose: false)
.and_return(false)
expect(do_install).to be(:failed)
end
Expand All @@ -228,7 +231,8 @@ def sane?(verbose:)
end

it "does not upgrade formula" do
expect(Bundle).not_to receive(:system).with("brew", "upgrade", "--formula", formula, verbose: false)
expect(Bundle).not_to receive(:system).with(HOMEBREW_BREW_FILE, "upgrade", "--formula", formula,
verbose: false)
expect(do_install).to be(:skipped)
end
end
Expand Down
8 changes: 5 additions & 3 deletions spec/bundle/brew_services_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,24 @@
context "when the service is stopped" do
it "when the service is started" do
allow(described_class).to receive(:started_services).and_return(%w[nginx])
expect(Bundle).to receive(:system).with("brew", "services", "stop", "nginx", verbose: false).and_return(true)
expect(Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "services", "stop", "nginx",
verbose: false).and_return(true)
expect(described_class.stop("nginx")).to be(true)
expect(described_class.started_services).not_to include("nginx")
end

it "when the service is already stopped" do
allow(described_class).to receive(:started_services).and_return(%w[])
expect(Bundle).not_to receive(:system).with("brew", "services", "stop", "nginx", verbose: false)
expect(Bundle).not_to receive(:system).with(HOMEBREW_BREW_FILE, "services", "stop", "nginx", verbose: false)
expect(described_class.stop("nginx")).to be(true)
expect(described_class.started_services).not_to include("nginx")
end
end

it "restarts the service" do
allow(described_class).to receive(:started_services).and_return([])
expect(Bundle).to receive(:system).with("brew", "services", "restart", "nginx", verbose: false).and_return(true)
expect(Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "services", "restart", "nginx",
verbose: false).and_return(true)
expect(described_class.restart("nginx")).to be(true)
expect(described_class.started_services).to include("nginx")
end
Expand Down
19 changes: 12 additions & 7 deletions spec/bundle/cask_installer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def do_greedy_install
end

it "upgrades" do
expect(Bundle).to receive(:system).with("brew", "upgrade", "--cask", "google-chrome", verbose: false)
expect(Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "upgrade", "--cask", "google-chrome",
verbose: false)
.and_return(true)
expect(do_install).to be(:success)
end
Expand All @@ -86,7 +87,7 @@ def do_greedy_install
end

it "upgrades" do
expect(Bundle).to receive(:system).with("brew", "upgrade", "--cask", "opera", verbose: false)
expect(Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "upgrade", "--cask", "opera", verbose: false)
.and_return(true)
expect(do_greedy_install).to be(:success)
end
Expand All @@ -98,33 +99,37 @@ def do_greedy_install
end

it "installs cask" do
expect(Bundle).to receive(:system).with("brew", "install", "--cask", "google-chrome", verbose: false)
expect(Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "install", "--cask", "google-chrome",
verbose: false)
.and_return(true)
expect(do_install).to be(:success)
end

it "installs cask with arguments" do
expect(Bundle).to \
receive(:system).with("brew", "install", "--cask", "firefox", "--appdir=/Applications", verbose: false)
receive(:system).with(HOMEBREW_BREW_FILE, "install", "--cask", "firefox", "--appdir=/Applications",
verbose: false)
.and_return(true)
expect(described_class.install("firefox", args: { appdir: "/Applications" })).to eq(:success)
end

it "reports a failure" do
expect(Bundle).to receive(:system).with("brew", "install", "--cask", "google-chrome", verbose: false)
expect(Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "install", "--cask", "google-chrome",
verbose: false)
.and_return(false)
expect(do_install).to be(:failed)
end

context "with boolean arguments" do
it "includes a flag if true" do
expect(Bundle).to receive(:system).with("brew", "install", "--cask", "iterm", "--force", verbose: false)
expect(Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "install", "--cask", "iterm", "--force",
verbose: false)
.and_return(true)
expect(described_class.install("iterm", args: { force: true })).to eq(:success)
end

it "does not include a flag if false" do
expect(Bundle).to receive(:system).with("brew", "install", "--cask", "iterm", verbose: false)
expect(Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "install", "--cask", "iterm", verbose: false)
.and_return(true)
expect(described_class.install("iterm", args: { force: false })).to eq(:success)
end
Expand Down
8 changes: 4 additions & 4 deletions spec/bundle/commands/cleanup_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
end

it "uninstalls casks" do
expect(Kernel).to receive(:system).with("brew", "uninstall", "--cask", "--force", "a", "b")
expect(Kernel).to receive(:system).with(HOMEBREW_BREW_FILE, "uninstall", "--cask", "--force", "a", "b")
expect(described_class).to receive(:system_output_no_stderr).and_return("")
expect { described_class.run(force: true) }.to output(/Uninstalled 2 casks/).to_stdout
end
Expand All @@ -110,7 +110,7 @@
end

it "uninstalls casks" do
expect(Kernel).to receive(:system).with("brew", "uninstall", "--cask", "--zap", "--force", "a", "b")
expect(Kernel).to receive(:system).with(HOMEBREW_BREW_FILE, "uninstall", "--cask", "--zap", "--force", "a", "b")
expect(described_class).to receive(:system_output_no_stderr).and_return("")
expect { described_class.run(force: true, zap: true) }.to output(/Uninstalled 2 casks/).to_stdout
end
Expand All @@ -125,7 +125,7 @@
end

it "uninstalls formulae" do
expect(Kernel).to receive(:system).with("brew", "uninstall", "--formula", "--force", "a", "b")
expect(Kernel).to receive(:system).with(HOMEBREW_BREW_FILE, "uninstall", "--formula", "--force", "a", "b")
expect(described_class).to receive(:system_output_no_stderr).and_return("")
expect { described_class.run(force: true) }.to output(/Uninstalled 2 formulae/).to_stdout
end
Expand All @@ -140,7 +140,7 @@
end

it "untaps taps" do
expect(Kernel).to receive(:system).with("brew", "untap", "a", "b")
expect(Kernel).to receive(:system).with(HOMEBREW_BREW_FILE, "untap", "a", "b")
expect(described_class).to receive(:system_output_no_stderr).and_return("")
described_class.run(force: true)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/bundle/mac_app_store_installer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def do_install
end

it "tries to install mas" do
expect(Bundle).to receive(:system).with("brew", "install", "mas", verbose: false).and_return(true)
expect(Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "install", "mas", verbose: false).and_return(true)
expect { do_install }.to raise_error(RuntimeError)
end

Expand Down
6 changes: 4 additions & 2 deletions spec/bundle/tap_installer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ def do_install(**options)
end

it "taps" do
expect(Bundle).to receive(:system).with("brew", "tap", "homebrew/cask", verbose: false).and_return(true)
expect(Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "tap", "homebrew/cask",
verbose: false).and_return(true)
expect(do_install).to be(:success)
end

context "with clone target" do
it "taps" do
expect(Bundle).to receive(:system).with("brew", "tap", "homebrew/cask", "clone_target_path", verbose: false)
expect(Bundle).to receive(:system).with(HOMEBREW_BREW_FILE, "tap", "homebrew/cask", "clone_target_path",
verbose: false)
.and_return(true)
expect(do_install(clone_target: "clone_target_path")).to be(:success)
end
Expand Down
Loading

0 comments on commit 916be52

Please sign in to comment.