Pass along CLI::Binaries.

This commit is contained in:
Markus Reiter 2017-05-19 19:13:23 +02:00
parent 8f068a356d
commit 9e821863d0
6 changed files with 33 additions and 28 deletions

View File

@ -3,10 +3,6 @@ require "hbc/artifact/symlinked"
module Hbc module Hbc
module Artifact module Artifact
class Binary < Symlinked class Binary < Symlinked
def install_phase
super if CLI.binaries?
end
def link def link
super super
return if source.executable? return if source.executable?

View File

@ -19,10 +19,10 @@ module Hbc
cask_tokens.each do |cask_token| cask_tokens.each do |cask_token|
begin begin
cask = CaskLoader.load(cask_token) cask = CaskLoader.load(cask_token)
Installer.new(cask, Installer.new(cask, binaries: CLI.binaries?,
force: force, force: force,
skip_cask_deps: skip_cask_deps, skip_cask_deps: skip_cask_deps,
require_sha: require_sha).install require_sha: require_sha).install
count += 1 count += 1
rescue CaskAlreadyInstalledError => e rescue CaskAlreadyInstalledError => e
opoo e.message opoo e.message

View File

@ -8,6 +8,7 @@ module Hbc
cask = CaskLoader.load(cask_token) cask = CaskLoader.load(cask_token)
Installer.new(cask, Installer.new(cask,
binaries: CLI.binaries?,
force: force, force: force,
skip_cask_deps: skip_cask_deps, skip_cask_deps: skip_cask_deps,
require_sha: require_sha).reinstall require_sha: require_sha).reinstall

View File

@ -17,7 +17,7 @@ module Hbc
cask = CaskLoader.load_from_file(cask.installed_caskfile) if cask.installed_caskfile.exist? cask = CaskLoader.load_from_file(cask.installed_caskfile) if cask.installed_caskfile.exist?
end end
Installer.new(cask, force: force).uninstall Installer.new(cask, binaries: CLI.binaries?, force: force).uninstall
next if (versions = cask.versions).empty? next if (versions = cask.versions).empty?

View File

@ -18,15 +18,20 @@ module Hbc
PERSISTENT_METADATA_SUBDIRS = ["gpg"].freeze PERSISTENT_METADATA_SUBDIRS = ["gpg"].freeze
def initialize(cask, command: SystemCommand, force: false, skip_cask_deps: false, require_sha: false) def initialize(cask, command: SystemCommand, force: false, skip_cask_deps: false, binaries: true, require_sha: false)
@cask = cask @cask = cask
@command = command @command = command
@force = force @force = force
@skip_cask_deps = skip_cask_deps @skip_cask_deps = skip_cask_deps
@binaries = binaries
@require_sha = require_sha @require_sha = require_sha
@reinstall = false @reinstall = false
end end
def binaries?
@binaries
end
def self.print_caveats(cask) def self.print_caveats(cask)
odebug "Printing caveats" odebug "Printing caveats"
return if cask.caveats.empty? return if cask.caveats.empty?
@ -108,7 +113,7 @@ module Hbc
installed_cask = installed_caskfile.exist? ? CaskLoader.load_from_file(installed_caskfile) : @cask installed_cask = installed_caskfile.exist? ? CaskLoader.load_from_file(installed_caskfile) : @cask
# Always force uninstallation, ignore method parameter # Always force uninstallation, ignore method parameter
Installer.new(installed_cask, force: true).uninstall Installer.new(installed_cask, binaries: binaries?, force: true).uninstall
end end
def summary def summary
@ -162,6 +167,11 @@ module Hbc
artifacts.each do |artifact| artifacts.each do |artifact|
next unless artifact.respond_to?(:install_phase) next unless artifact.respond_to?(:install_phase)
odebug "Installing artifact of class #{artifact.class}" odebug "Installing artifact of class #{artifact.class}"
if artifact.is_a?(Artifact::Binary)
next unless binaries?
end
artifact.install_phase artifact.install_phase
already_installed_artifacts.unshift(artifact) already_installed_artifacts.unshift(artifact)
end end
@ -254,7 +264,7 @@ module Hbc
if dep.installed? if dep.installed?
puts "already installed" puts "already installed"
else else
Installer.new(dep, force: false, skip_cask_deps: true).install Installer.new(dep, force: false, binaries: binaries?, skip_cask_deps: true).install
puts "done" puts "done"
end end
end end

View File

@ -16,6 +16,20 @@ describe Hbc::Artifact::Binary, :cask do
FileUtils.rm expected_path if expected_path.exist? FileUtils.rm expected_path if expected_path.exist?
end end
context "when --no-binaries is specified" do
let(:cask) {
Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-binary.rb")
}
it "doesn't link the binary when --no-binaries is specified" do
shutup do
Hbc::Installer.new(cask, binaries: false).install
end
expect(expected_path).not_to exist
end
end
it "links the binary to the proper directory" do it "links the binary to the proper directory" do
shutup do shutup do
Hbc::Artifact::Binary.new(cask).install_phase Hbc::Artifact::Binary.new(cask).install_phase
@ -70,22 +84,6 @@ describe Hbc::Artifact::Binary, :cask do
expect(File.readlink(expected_path)).not_to eq("/tmp") expect(File.readlink(expected_path)).not_to eq("/tmp")
end end
it "respects --no-binaries flag" do
begin
Hbc::CLI.binaries = false
expect(Hbc::CLI).not_to be_binaries
shutup do
Hbc::Artifact::Binary.new(cask).install_phase
end
expect(expected_path.exist?).to be false
ensure
Hbc::CLI.binaries = true
end
end
it "creates parent directory if it doesn't exist" do it "creates parent directory if it doesn't exist" do
FileUtils.rmdir Hbc.binarydir FileUtils.rmdir Hbc.binarydir