From 552dcdc7035d7114d47751d93630e37ae6d5bf24 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Wed, 7 Mar 2012 21:30:03 -0500 Subject: [PATCH] Move most bottle stuff to a bottles.rb file. --- Library/Homebrew/bottles.rb | 49 +++++++++++++++++++++++++++ Library/Homebrew/cmd/bottle.rb | 9 ++--- Library/Homebrew/extend/ARGV.rb | 6 ++-- Library/Homebrew/extend/pathname.rb | 5 +-- Library/Homebrew/formula.rb | 12 +------ Library/Homebrew/formula_installer.rb | 3 +- Library/Homebrew/utils.rb | 4 --- 7 files changed, 62 insertions(+), 26 deletions(-) create mode 100644 Library/Homebrew/bottles.rb diff --git a/Library/Homebrew/bottles.rb b/Library/Homebrew/bottles.rb new file mode 100644 index 0000000000..13ed775901 --- /dev/null +++ b/Library/Homebrew/bottles.rb @@ -0,0 +1,49 @@ +require 'tab' +require 'extend/ARGV' + +def bottle_filename f + "#{f.name}-#{f.version}#{bottle_native_suffix}" +end + +def bottles_supported? + HOMEBREW_PREFIX.to_s == '/usr/local' and HOMEBREW_CELLAR.to_s == '/usr/local/Cellar' +end + +def install_bottle? f + !ARGV.build_from_source? && bottle_current?(f) && bottle_native?(f) +end + +def bottle_native? f + return true if bottle_native_regex.match(f.bottle_url) + # old brew bottle style + return true if MacOS.lion? && old_bottle_regex.match(f.bottle_url) + return false +end + +def built_bottle? f + Tab.for_formula(f).built_bottle +end + +def bottle_current? f + !f.bottle_url.nil? && Pathname.new(f.bottle_url).version == f.version +end + +def bottle_native_suffix + ".#{MacOS.cat}#{bottle_suffix}" +end + +def bottle_suffix + ".bottle.tar.gz" +end + +def bottle_native_regex + /(\.#{MacOS.cat}\.bottle\.tar\.gz)$/ +end + +def bottle_regex + /(\.[a-z]+\.bottle\.tar\.gz)$/ +end + +def old_bottle_regex + /(-bottle\.tar\.gz)$/ +end \ No newline at end of file diff --git a/Library/Homebrew/cmd/bottle.rb b/Library/Homebrew/cmd/bottle.rb index 25160b5c6e..4a1cd0f36a 100755 --- a/Library/Homebrew/cmd/bottle.rb +++ b/Library/Homebrew/cmd/bottle.rb @@ -1,17 +1,14 @@ require 'formula' +require 'bottles' require 'tab' module Homebrew extend self - def formula_bottle_name f - "#{f.name}-#{f.version}.#{MacOS.cat}.bottle.tar.gz" - end - def bottle_formula f return onoe "Formula not installed: #{f.name}" unless f.installed? - return onoe "Formula not installed with '--build-bottle': #{f.name}" unless Tab.for_formula(f).built_bottle + return onoe "Formula not installed with '--build-bottle': #{f.name}" unless built_bottle? f directory = Pathname.pwd - filename = formula_bottle_name f + filename = bottle_filename f HOMEBREW_CELLAR.cd do ohai "Bottling #{f.name} #{f.version}..." diff --git a/Library/Homebrew/extend/ARGV.rb b/Library/Homebrew/extend/ARGV.rb index 59a5087e73..25d19e2e7f 100644 --- a/Library/Homebrew/extend/ARGV.rb +++ b/Library/Homebrew/extend/ARGV.rb @@ -1,3 +1,5 @@ +require 'bottles' + module HomebrewArgvExtension def named @named ||= reject{|arg| arg[0..0] == '-'} @@ -94,12 +96,12 @@ module HomebrewArgvExtension end def build_bottle? - MacOS.bottles_supported? and include? '--build-bottle' + bottles_supported? and include? '--build-bottle' end def build_from_source? flag? '--build-from-source' or ENV['HOMEBREW_BUILD_FROM_SOURCE'] \ - or not MacOS.bottles_supported? or not options_only.empty? + or not bottles_supported? or not options_only.empty? end def flag? flag diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index f05fc9f5f3..34f692f28c 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -1,4 +1,5 @@ require 'pathname' +require 'bottles' # we enhance pathname to make our code more readable class Pathname @@ -100,9 +101,9 @@ class Pathname # extended to support common double extensions def extname - return $1 if to_s =~ /(\.[a-z]+\.bottle\.tar\.gz)$/ + return $1 if to_s =~ bottle_regex # old brew bottle style - return $1 if to_s =~ /(-bottle\.tar\.gz)$/ + return $1 if to_s =~ old_bottle_regex /(\.(tar|cpio)\.(gz|bz2|xz|Z))$/.match to_s return $1 if $1 return File.extname(to_s) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index b3623b336c..b1cb3dc0e6 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1,6 +1,7 @@ require 'download_strategy' require 'formula_support' require 'hardware' +require 'bottles' require 'extend/fileutils' @@ -64,17 +65,6 @@ class Formula return false end - def bottle_for_current_osx_version? - return true if /#{MacOS.cat}\.bottle\.tar\.gz$/.match(bottle_url) - # old brew bottle style - return true if MacOS.lion? && /-bottle\.tar\.gz$/.match(bottle_url) - return false - end - - def bottle_up_to_date? - !bottle_url.nil? && Pathname.new(bottle_url).version == version - end - def explicitly_requested? # `ARGV.formulae` will throw an exception if it comes up with an empty list. # FIXME: `ARGV.formulae` shouldn't be throwing exceptions, see issue #8823 diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 82c58c9d03..cc6d61b8e0 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -3,6 +3,7 @@ require 'formula' require 'keg' require 'set' require 'tab' +require 'bottles' class FormulaInstaller attr :f @@ -15,7 +16,7 @@ class FormulaInstaller @f = ff @show_header = true @ignore_deps = ARGV.include? '--ignore-dependencies' || ARGV.interactive? - @install_bottle = !ARGV.build_from_source? && ff.bottle_up_to_date? && ff.bottle_for_current_osx_version? + @install_bottle = install_bottle? ff check_install_sanity end diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index f18b908b2f..4ef0a5a674 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -503,10 +503,6 @@ module MacOS extend self def prefer_64_bit? Hardware.is_64_bit? and not leopard? end - - def bottles_supported? - HOMEBREW_PREFIX.to_s == '/usr/local' and HOMEBREW_CELLAR.to_s == '/usr/local/Cellar' - end end module GitHub extend self