diff --git a/Library/Homebrew/cask/lib/hbc/artifact/binary.rb b/Library/Homebrew/cask/lib/hbc/artifact/binary.rb index 21d123ab90..7178c2af69 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/binary.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/binary.rb @@ -3,10 +3,6 @@ require "hbc/artifact/symlinked" module Hbc module Artifact class Binary < Symlinked - def install_phase - super if CLI.binaries? - end - def link super return if source.executable? diff --git a/Library/Homebrew/cask/lib/hbc/cli/install.rb b/Library/Homebrew/cask/lib/hbc/cli/install.rb index 438f860c1c..5b5ef82c45 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/install.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/install.rb @@ -19,10 +19,10 @@ module Hbc cask_tokens.each do |cask_token| begin cask = CaskLoader.load(cask_token) - Installer.new(cask, - force: force, - skip_cask_deps: skip_cask_deps, - require_sha: require_sha).install + Installer.new(cask, binaries: CLI.binaries?, + force: force, + skip_cask_deps: skip_cask_deps, + require_sha: require_sha).install count += 1 rescue CaskAlreadyInstalledError => e opoo e.message diff --git a/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb index c2ed8f4625..662899d5fe 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb @@ -8,6 +8,7 @@ module Hbc cask = CaskLoader.load(cask_token) Installer.new(cask, + binaries: CLI.binaries?, force: force, skip_cask_deps: skip_cask_deps, require_sha: require_sha).reinstall diff --git a/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb b/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb index 1ee3230ad8..7fc40daafa 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb @@ -17,7 +17,7 @@ module Hbc cask = CaskLoader.load_from_file(cask.installed_caskfile) if cask.installed_caskfile.exist? end - Installer.new(cask, force: force).uninstall + Installer.new(cask, binaries: CLI.binaries?, force: force).uninstall next if (versions = cask.versions).empty? diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index f02f07806e..d9addd6040 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -18,15 +18,20 @@ module Hbc 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 @command = command @force = force @skip_cask_deps = skip_cask_deps + @binaries = binaries @require_sha = require_sha @reinstall = false end + def binaries? + @binaries + end + def self.print_caveats(cask) odebug "Printing caveats" return if cask.caveats.empty? @@ -108,7 +113,7 @@ module Hbc installed_cask = installed_caskfile.exist? ? CaskLoader.load_from_file(installed_caskfile) : @cask # Always force uninstallation, ignore method parameter - Installer.new(installed_cask, force: true).uninstall + Installer.new(installed_cask, binaries: binaries?, force: true).uninstall end def summary @@ -162,6 +167,11 @@ module Hbc artifacts.each do |artifact| next unless artifact.respond_to?(:install_phase) odebug "Installing artifact of class #{artifact.class}" + + if artifact.is_a?(Artifact::Binary) + next unless binaries? + end + artifact.install_phase already_installed_artifacts.unshift(artifact) end @@ -254,7 +264,7 @@ module Hbc if dep.installed? puts "already installed" 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" end end diff --git a/Library/Homebrew/test/cask/artifact/binary_spec.rb b/Library/Homebrew/test/cask/artifact/binary_spec.rb index ee62e6439c..f9b5f5b424 100644 --- a/Library/Homebrew/test/cask/artifact/binary_spec.rb +++ b/Library/Homebrew/test/cask/artifact/binary_spec.rb @@ -16,6 +16,20 @@ describe Hbc::Artifact::Binary, :cask do FileUtils.rm expected_path if expected_path.exist? 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 shutup do 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") 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 FileUtils.rmdir Hbc.binarydir