Decouple spec selection from ARGV

This commit is contained in:
Jack Nagel 2014-06-19 21:35:47 -05:00
parent 5beaa512e6
commit 10fda9e9b9
6 changed files with 55 additions and 50 deletions

View File

@ -40,7 +40,8 @@ def main
# can be inconvenient for the user. But we need to be safe.
system "/usr/bin/sudo", "-k"
Build.new(Formula.factory($0)).install
formula = Formulary.factory($0, ARGV.spec)
Build.new(formula).install
rescue Exception => e
unless error_pipe.nil?
e.continuation = nil if ARGV.debug?

View File

@ -8,9 +8,8 @@ module HomebrewArgvExtension
end
def formulae
require 'formula'
@formulae ||= downcased_unique_named.map{ |name| Formula.factory name }
return @formulae
require "formula"
@formulae ||= downcased_unique_named.map { |name| Formulary.factory(name, spec) }
end
def kegs
@ -179,6 +178,16 @@ module HomebrewArgvExtension
value 'env'
end
def spec
if include?("--HEAD")
:head
elsif include?("--devel")
:devel
else
:stable
end
end
private
def downcased_unique_named

View File

@ -36,7 +36,7 @@ class Formula
set_spec :devel
set_spec :head
@active_spec = determine_active_spec
@active_spec = determine_active_spec(spec)
validate_attributes :url, :name, :version
@build = determine_build_options
@pkg_version = PkgVersion.new(version, revision)
@ -52,16 +52,9 @@ class Formula
end
end
def determine_active_spec
case
when head && ARGV.build_head? then head # --HEAD
when devel && ARGV.build_devel? then devel # --devel
when stable then stable
when devel then devel
when head then head # head-only
else
raise FormulaSpecificationError, "formulae require at least a URL"
end
def determine_active_spec(requested)
spec = send(requested) || stable || devel || head
spec or raise FormulaSpecificationError, "formulae require at least a URL"
end
def validate_attributes(*attrs)

View File

@ -471,8 +471,11 @@ class FormulaInstaller
args << "--debug" if debug?
args << "--cc=#{ARGV.cc}" if ARGV.cc
args << "--env=#{ARGV.env}" if ARGV.env
args << "--HEAD" if ARGV.build_head?
args << "--devel" if ARGV.build_devel?
case f.active_spec
when f.head then args << "--HEAD"
when f.devel then args << "--devel"
end
f.build.each do |opt, _|
name = opt.name[/\A(.+)=\z$/, 1]

View File

@ -92,9 +92,7 @@ class FormulaTests < Homebrew::TestCase
end
def test_installed_prefix_head_active_spec
ARGV.stubs(:build_head? => true)
f = formula do
f = formula("test", Pathname.new(__FILE__).expand_path, :head) do
head 'foo'
devel do
url 'foo'
@ -106,9 +104,7 @@ class FormulaTests < Homebrew::TestCase
end
def test_installed_prefix_devel_active_spec
ARGV.stubs(:build_devel? => true)
f = formula do
f = formula("test", Pathname.new(__FILE__).expand_path, :devel) do
head 'foo'
devel do
url 'foo'
@ -244,9 +240,7 @@ class FormulaTests < Homebrew::TestCase
end
def test_head_ignores_revisions
ARGV.stubs(:build_head?).returns(true)
f = formula do
f = formula("test", Pathname.new(__FILE__).expand_path, :head) do
url 'foo-1.0.bar'
revision 1
head 'foo'

View File

@ -10,30 +10,6 @@ class FormulaSpecSelectionTests < Homebrew::TestCase
assert_nil @_f.send(spec)
end
def test_selects_head_when_requested
ARGV.stubs(:build_head?).returns(true)
formula do
url 'foo-1.0'
devel { url 'foo-1.1a' }
head 'foo'
end
assert_spec_selected :head
end
def test_selects_devel_when_requested
ARGV.stubs(:build_devel?).returns(true)
formula do
url 'foo-1.0'
devel { url 'foo-1.1a' }
head 'foo'
end
assert_spec_selected :devel
end
def test_selects_stable_by_default
formula do
url 'foo-1.0'
@ -98,6 +74,26 @@ class FormulaSpecSelectionTests < Homebrew::TestCase
assert_spec_selected :devel
end
def test_selects_head_when_requested
formula("test", Pathname.new(__FILE__).expand_path, :head) do
url 'foo-1.0'
devel { url 'foo-1.1a' }
head 'foo'
end
assert_spec_selected :head
end
def test_selects_devel_when_requested
formula("test", Pathname.new(__FILE__).expand_path, :devel) do
url 'foo-1.0'
devel { url 'foo-1.1a' }
head 'foo'
end
assert_spec_selected :devel
end
def test_incomplete_devel_not_set
formula do
url 'foo-1.0'
@ -108,4 +104,13 @@ class FormulaSpecSelectionTests < Homebrew::TestCase
assert_spec_unset :devel
assert_spec_selected :stable
end
def test_does_not_raise_for_missing_spec
formula("test", Pathname.new(__FILE__).expand_path, :devel) do
url 'foo-1.0'
head 'foo'
end
assert_spec_selected :stable
end
end