Move most bottle stuff to a bottles.rb file.

This commit is contained in:
Mike McQuaid 2012-03-07 21:30:03 -05:00
parent 4a306f32f4
commit 552dcdc703
7 changed files with 62 additions and 26 deletions

View File

@ -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

View File

@ -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}..."

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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