aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cmd/options.rb10
-rw-r--r--Library/Homebrew/formula.rb19
-rw-r--r--Library/Homebrew/formula_support.rb77
3 files changed, 101 insertions, 5 deletions
diff --git a/Library/Homebrew/cmd/options.rb b/Library/Homebrew/cmd/options.rb
index a8dfcc04a..bd0c6b93b 100644
--- a/Library/Homebrew/cmd/options.rb
+++ b/Library/Homebrew/cmd/options.rb
@@ -19,9 +19,9 @@ end
module Homebrew extend self
def options
ff.each do |f|
- next if f.options.empty?
+ next if f.build.empty?
if ARGV.include? '--compact'
- puts f.options.collect {|o| o[0]} * " "
+ puts f.build.collect {|k,v| k} * " "
else
puts f.name if ff.length > 1
dump_options_for_formula f
@@ -31,9 +31,9 @@ module Homebrew extend self
end
def dump_options_for_formula f
- f.options.each do |o|
- puts o[0]
- puts "\t"+o[1]
+ f.options.each do |k,v|
+ puts k
+ puts "\t"+v
end
end
end
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index d78ded9b0..99a61daff 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -59,6 +59,9 @@ class Formula
# If we got an explicit path, use that, else determine from the name
@path = path.nil? ? self.class.path(name) : Pathname.new(path)
@downloader = download_strategy.new(name, @active_spec)
+
+ # Combine DSL `option` and `def options`
+ options.each {|o| self.class.build.add(o[0], o[1]) }
end
# Derive specs from class ivars
@@ -160,6 +163,10 @@ class Formula
def plist_name; 'homebrew.mxcl.'+name end
def plist_path; prefix+(plist_name+'.plist') end
+ def build
+ self.class.build
+ end
+
# Use the @active_spec to detect the download strategy.
# Can be overriden to force a custom download strategy
def download_strategy
@@ -579,6 +586,10 @@ private
}
end
+ def build
+ @build ||= BuildOptions.new(ARGV)
+ end
+
def url val=nil, specs=nil
if val.nil?
return @stable.url if @stable
@@ -630,6 +641,14 @@ private
dependencies.add(dep)
end
+ def option name, description=nil
+ # Support symbols
+ name = name.to_s
+ raise "Option name is required." if name.empty?
+ raise "Options should not start with dashes." if name[0, 1] == "-"
+ build.add name, description
+ end
+
def conflicts_with formula, opts={}
message = <<-EOS.undent
#{formula} cannot be installed alongside #{name.downcase}.
diff --git a/Library/Homebrew/formula_support.rb b/Library/Homebrew/formula_support.rb
index 30cbee4e8..6118441e2 100644
--- a/Library/Homebrew/formula_support.rb
+++ b/Library/Homebrew/formula_support.rb
@@ -151,3 +151,80 @@ EOS
end
end
end
+
+
+# This class holds the build-time options defined for a Formula,
+# and provides named access to those options during install.
+class BuildOptions
+
+ def initialize args
+ # Take a copy of the args (any string array, actually)
+ @args = Array.new(args)
+ # Extend it into an ARGV extension
+ @args.extend(HomebrewArgvExtension)
+ @options = []
+ end
+
+ def add name, description=nil
+ if description.nil?
+ case name
+ when :universal, "universal"
+ description = "Build a universal binary."
+ when "32-bit"
+ description = "Build 32-bit only."
+ else
+ description = ""
+ end
+ end
+
+ @options << [name, description]
+ end
+
+ def has_option? name
+ @options.any? {|o| o[0] == name}
+ end
+
+ def empty?
+ @options.empty?
+ end
+
+ def collect
+ @options.collect {|o| yield o[0], o[1]}
+ end
+
+ def each
+ @options.each {|o| yield o[0], o[1]}
+ end
+
+ def include? name
+ @args.include? '--' + name
+ end
+
+ def using? name
+ @args.include? '--' + name
+ end
+
+ def head?
+ @args.flag? '--HEAD'
+ end
+
+ def devel?
+ @args.include? '--devel'
+ end
+
+ def stable?
+ not (head? or devel?)
+ end
+
+ # True if the user requested a universal build.
+ def universal?
+ @args.include? '--universal'
+ end
+
+ # Request a 32-bit only build.
+ # This is needed for some use-cases though we prefer to build Universal
+ # when a 32-bit version is needed.
+ def build_32_bit?
+ @args.include? '--32-bit'
+ end
+end