Allow requirements to specify env options

This commit is contained in:
Jack Nagel 2012-12-23 19:44:56 -06:00
parent f8d253950f
commit 9c8a73cf41
4 changed files with 21 additions and 3 deletions

View File

@ -57,9 +57,8 @@ end
def post_superenv_hacks f def post_superenv_hacks f
# Only allow Homebrew-approved directories into the PATH, unless # Only allow Homebrew-approved directories into the PATH, unless
# a formula opts-in to allowing the user's path. # a formula opts-in to allowing the user's path.
if f.env.userpaths? if f.env.userpaths? or f.recursive_requirements.any? { |rq| rq.env.userpaths? }
paths = ORIGINAL_PATHS.map{|pn| pn.realpath.to_s rescue nil } - %w{/usr/X11/bin /opt/X11/bin} ENV.userpaths!
ENV['PATH'] = "#{ENV['PATH']}:#{paths.join(':')}"
end end
end end

View File

@ -1,3 +1,5 @@
require 'build_environment'
## This file defines dependencies and requirements. ## This file defines dependencies and requirements.
## ##
## A dependency is a formula that another formula needs to install. ## A dependency is a formula that another formula needs to install.
@ -169,6 +171,10 @@ class Requirement
# See X11Dependency # See X11Dependency
def modify_build_environment; nil end def modify_build_environment; nil end
def env
@env ||= self.class.env
end
def eql?(other) def eql?(other)
other.is_a? self.class and hash == other.hash other.is_a? self.class and hash == other.hash
end end
@ -181,6 +187,12 @@ class Requirement
def fatal(val=nil) def fatal(val=nil)
val.nil? ? @fatal : @fatal = val val.nil? ? @fatal : @fatal = val
end end
def env(*settings)
@env ||= BuildEnvironment.new
settings.each { |s| @env << s }
@env
end
end end
end end

View File

@ -431,6 +431,11 @@ class << ENV
append 'CPPFLAGS', "-DNCURSES_OPAQUE=0" append 'CPPFLAGS', "-DNCURSES_OPAQUE=0"
end end
def userpaths!
paths = ORIGINAL_PATHS.map { |p| p.realpath.to_s rescue nil } - %w{/usr/X11/bin /opt/X11/bin}
self['PATH'] = paths.unshift(*self['PATH'].split(":")).uniq.join(":")
end
def fortran def fortran
fc_flag_vars = %w{FCFLAGS FFLAGS} fc_flag_vars = %w{FCFLAGS FFLAGS}

View File

@ -102,6 +102,8 @@ class MPIDependency < Requirement
fatal true fatal true
env :userpaths
def initialize *lang_list def initialize *lang_list
@lang_list = lang_list @lang_list = lang_list
@non_functional = [] @non_functional = []