Support env :std, :userpaths

Closes Homebrew/homebrew#14654.
This commit is contained in:
Adam Vandenberg 2012-09-14 07:54:14 -07:00
parent 4bf72a3e62
commit 88ad4c061d
3 changed files with 33 additions and 20 deletions

View File

@ -53,32 +53,17 @@ rescue Exception => e
end end
def post_superenv_hacks f def post_superenv_hacks f
# TODO replace with Formula DSL # Only allow Homebrew-approved directories into the PATH, unless
# Python etc. build but then pip can't build stuff. # a formula opts-in to allowing the user's path.
# Scons resets ENV and then can't find superenv's build-tools. if f.env.userpaths?
# In some cases we should only apply in the case of an option I suggest the
# following:
#
# option 'with-passenger' do
# env :userpaths # for superenv
# end
# option 'without-foo' do
# env :std, :x11
# end
#
# NOTE I think all ENV stuff should be specified with a DSL like this now.
case f.name.to_sym
when :lilypond, :nginx, :auctex
paths = ORIGINAL_PATHS.map{|pn| pn.realpath.to_s rescue nil } - %w{/usr/X11/bin /opt/X11/bin} paths = ORIGINAL_PATHS.map{|pn| pn.realpath.to_s rescue nil } - %w{/usr/X11/bin /opt/X11/bin}
ENV['PATH'] = "#{ENV['PATH']}:#{paths.join(':')}" ENV['PATH'] = "#{ENV['PATH']}:#{paths.join(':')}"
end end
end end
def pre_superenv_hacks f def pre_superenv_hacks f
# fontforge needs 10.7 SDK, wine 32 bit, graphviz has mysteriously missing symbols # Allow a formula to opt-in to the std environment.
# and ruby/python/ghc etc. create gem/pip that then won't work ARGV.unshift '--env=std' if (f.env.std? or
stdenvs = %w{fontforge python python3 ruby ruby-enterprise-edition jruby wine graphviz ghc}
ARGV.unshift '--env=std' if (stdenvs.include?(f.name) or
f.recursive_deps.detect{|d| d.name == 'scons' }) and f.recursive_deps.detect{|d| d.name == 'scons' }) and
not ARGV.include? '--env=super' not ARGV.include? '--env=super'
end end

View File

@ -0,0 +1,15 @@
require 'set'
class BuildEnvironment
def initialize settings
@settings = Set.new(settings)
end
def std?
@settings.include? :std
end
def userpaths?
@settings.include? :userpaths
end
end

View File

@ -6,6 +6,7 @@ require 'bottles'
require 'extend/fileutils' require 'extend/fileutils'
require 'patches' require 'patches'
require 'compilers' require 'compilers'
require 'build_environment'
class Formula class Formula
@ -436,6 +437,10 @@ class Formula
def deps; self.class.dependencies.deps; end def deps; self.class.dependencies.deps; end
def requirements; self.class.dependencies.requirements; end def requirements; self.class.dependencies.requirements; end
def env
@env ||= BuildEnvironment.new(self.class.environments)
end
def conflicts def conflicts
requirements.select { |r| r.is_a? ConflictRequirement } requirements.select { |r| r.is_a? ConflictRequirement }
end end
@ -646,6 +651,14 @@ private
@stable.mirror(val) @stable.mirror(val)
end end
def environments
@environments ||= []
end
def env *settings
environments.concat [settings].flatten
end
def dependencies def dependencies
@dependencies ||= DependencyCollector.new @dependencies ||= DependencyCollector.new
end end