From 20ec595cb2e661336cf2100a071c52cc48072314 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 11 Jul 2018 16:39:17 +0200 Subject: [PATCH] Fix `Installer` not supporting plain executables. --- .../cask/lib/hbc/artifact/installer.rb | 33 ++++++++++++++----- Library/Homebrew/test/cask/dsl_spec.rb | 2 +- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/artifact/installer.rb b/Library/Homebrew/cask/lib/hbc/artifact/installer.rb index 93f1c9df96..a3a84164e0 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/installer.rb @@ -14,16 +14,32 @@ module Hbc To complete the installation of Cask #{cask}, you must also run the installer at - '#{path}' + '#{cask.staged_path.join(path)}' EOS end end module ScriptInstaller def install_phase(command: nil, **_) - ohai "Running #{self.class.dsl_key} script '#{path.relative_path_from(cask.staged_path)}'" - FileUtils.chmod "+x", path unless path.executable? - command.run!(path, **args, env: { "PATH" => PATH.new(HOMEBREW_PREFIX/"bin", HOMEBREW_PREFIX/"sbin", ENV["PATH"]) }) + ohai "Running #{self.class.dsl_key} script '#{path}'" + + absolute_path = if path.absolute? + path + else + cask.staged_path.join(path) + end + + if absolute_path.exist? && !absolute_path.executable? + FileUtils.chmod "+x", absolute_path + end + + executable = if absolute_path.exist? + absolute_path + else + path + end + + command.run!(executable, **args, env: { "PATH" => PATH.new(HOMEBREW_PREFIX/"bin", HOMEBREW_PREFIX/"sbin", ENV["PATH"]) }) end end @@ -54,7 +70,7 @@ module Hbc super(cask) if args.key?(:manual) - @path = cask.staged_path.join(args[:manual]) + @path = Pathname(args[:manual]) @args = [] extend(ManualInstaller) return @@ -65,17 +81,16 @@ module Hbc ) raise CaskInvalidError.new(cask, "#{self.class.dsl_key} missing executable") if path.nil? - path = Pathname(path) - @path = path.absolute? ? path : cask.staged_path.join(path) + @path = Pathname(path) extend(ScriptInstaller) end def summarize - path.relative_path_from(cask.staged_path).to_s + path.to_s end def to_h - { path: path.relative_path_from(cask.staged_path).to_s }.tap do |h| + { path: path }.tap do |h| h[:args] = args unless is_a?(ManualInstaller) end end diff --git a/Library/Homebrew/test/cask/dsl_spec.rb b/Library/Homebrew/test/cask/dsl_spec.rb index 2500a53fa3..6ce40502a6 100644 --- a/Library/Homebrew/test/cask/dsl_spec.rb +++ b/Library/Homebrew/test/cask/dsl_spec.rb @@ -520,7 +520,7 @@ describe Hbc::DSL, :cask do it "allows installer manual to be specified" do installer = cask.artifacts.first expect(installer).to be_a(Hbc::Artifact::Installer::ManualInstaller) - expect(installer.path).to eq(cask.staged_path.join("Caffeine.app")) + expect(installer.path).to eq(Pathname("Caffeine.app")) end end end