From c4fb2b73e2602c07e02a78360ef9de59d417ca37 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sun, 25 Nov 2012 14:33:52 +0000 Subject: [PATCH] Support installing bottles from local files. --- Library/Homebrew/bottles.rb | 1 + Library/Homebrew/download_strategy.rb | 14 +++++++++----- Library/Homebrew/formula.rb | 11 +++++++++++ Library/Homebrew/formula_installer.rb | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/bottles.rb b/Library/Homebrew/bottles.rb index a060d671e7..ff316f9253 100644 --- a/Library/Homebrew/bottles.rb +++ b/Library/Homebrew/bottles.rb @@ -11,6 +11,7 @@ end def install_bottle? f return true if ARGV.include? '--install-bottle' + return true if f.downloader and f.downloader.local_bottle_path not ARGV.build_from_source? \ and MacOS.bottles_supported? \ and ARGV.used_options(f).empty? \ diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 3a1e0e64c5..f9df839d10 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -32,7 +32,8 @@ class AbstractDownloadStrategy end class CurlDownloadStrategy < AbstractDownloadStrategy - attr_reader :tarball_path + attr_reader :tarball_path, :local_bottle_path + attr_writer :local_bottle_path def initialize name, package super @@ -55,6 +56,11 @@ class CurlDownloadStrategy < AbstractDownloadStrategy end def fetch + if @local_bottle_path + @tarball_path = @local_bottle_path + return @local_bottle_path + end + ohai "Downloading #{@url}" unless @tarball_path.exist? begin @@ -79,6 +85,8 @@ class CurlDownloadStrategy < AbstractDownloadStrategy end def stage + ohai "Pouring #{File.basename(@tarball_path)}" if @tarball_path.to_s.match bottle_regex + case @tarball_path.compression_type when :zip quiet_safe_system '/usr/bin/unzip', {:quiet_flag => '-qq'}, @tarball_path @@ -204,10 +212,6 @@ class CurlBottleDownloadStrategy < CurlDownloadStrategy FileUtils.mv old_bottle_path, @tarball_path if old_bottle_path.exist? end end - def stage - ohai "Pouring #{File.basename(@tarball_path)}" - super - end end class SubversionDownloadStrategy < AbstractDownloadStrategy diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index d553846e3c..3563badecc 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -355,6 +355,11 @@ class Formula end install_type = :from_url + elsif name.match bottle_regex + bottle_filename = Pathname(name).realpath + name = name.split('-').first + path = Formula.path(name) + install_type = :from_local_bottle else name = Formula.canonical_name(name) @@ -395,6 +400,12 @@ class Formula raise LoadError end + if install_type == :from_local_bottle + formula = klass.new(name) + formula.downloader.local_bottle_path = bottle_filename + return formula + end + raise NameError if !klass.ancestors.include? Formula return klass.new(name) if install_type == :from_name diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 4d25ead56d..8f3670c6b4 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -364,7 +364,7 @@ class FormulaInstaller def pour fetched, downloader = f.fetch - f.verify_download_integrity fetched + f.verify_download_integrity fetched unless downloader.local_bottle_path HOMEBREW_CELLAR.cd do downloader.stage end