brew/Library/Homebrew/build_options.rb
Samuel John c524895666 Python 2.x and 3.x support
New `depends_on :python` Dependency.
New `depends_on :python3` Dependency.

To avoid having multiple formulae with endings -py2 and -py3,
we will handle support for different pythons (2.x vs. 3.x)
in the same formula.
Further brewed vs. external python will be transparently supported.

The formula also gets a new object `python`, which is false if
no Python is available or the user has disabled it. Otherwise
it is defined and provides several support methods:

python.site_packages # the site-packages in the formula's Cellar
python.global_site_packages
python.binary # the full path to the python binary
python.prefix
python.version
python.version.major
python.version.minor
python.xy # => e.g. "python2.7"
python.incdir # includes of python
python.libdir # the python dylib library
python.pkg_config_path # used internally by brew
python.from_osx?
python.framework?
python.universal?
python.pypy?
python.standard_caveats # Text to set PYTHONPATH for python.from_osx?
python.if3then3 # => "" for 2.x and to "3" for 3.x.

Further, to avoid code duplication, `python` takes an optional
block that is run twice if the formula defines depends_on
:python AND :python3.

python do
  system python, 'setup.py', "--prefix=#{prefix}"
end

Read more in the Homebrew wiki.
2013-06-03 17:29:43 +02:00

104 lines
2.3 KiB
Ruby

require 'options'
# This class holds the build-time options defined for a Formula,
# and provides named access to those options during install.
class BuildOptions
attr_accessor :args
include Enumerable
def initialize args
@args = Options.coerce(args)
@options = Options.new
end
def add name, description=nil
description ||= case name.to_s
when "universal" then "Build a universal binary"
when "32-bit" then "Build 32-bit only"
end.to_s
@options << Option.new(name, description)
end
def has_option? name
any? { |opt| opt.name == name }
end
def empty?
@options.empty?
end
def each(*args, &block)
@options.each(*args, &block)
end
def as_flags
@options.as_flags
end
def include? name
args.include? '--' + name
end
def with? name
if has_option? "with-#{name}"
include? "with-#{name}"
elsif has_option? "without-#{name}"
not include? "without-#{name}"
else
false
end
end
def without? name
not with? name
end
def head?
args.include? '--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') && has_option?('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') && has_option?('32-bit')
end
def used_options
Options.new(@options & @args)
end
def unused_options
Options.new(@options - @args)
end
# Some options are implicitly ON because they are not explictly turned off
# by their counterpart option. This applies only to with-/without- options.
# implicit_options are needed because `depends_on 'spam' => 'with-stuff'`
# complains if 'spam' has stuff as default and only defines `--without-stuff`.
def implicit_options
implicit = unused_options.map do |o|
if o.name =~ /^with-(.+)$/ && without?($1)
Option.new("without-#{$1}") # we loose the description, but that's ok
elsif o.name =~ /^without-(.+)$/ && with?($1)
Option.new("with-#{$1}")
end
end.compact
Options.new(implicit)
end
end