From 9c8a73cf417a009e0bfa957ae942193febae14bf Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sun, 23 Dec 2012 19:44:56 -0600 Subject: [PATCH] Allow requirements to specify env options --- Library/Homebrew/build.rb | 5 ++--- Library/Homebrew/dependencies.rb | 12 ++++++++++++ Library/Homebrew/extend/ENV.rb | 5 +++++ Library/Homebrew/requirements.rb | 2 ++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/build.rb b/Library/Homebrew/build.rb index aa5be65401..2ce16b32c7 100755 --- a/Library/Homebrew/build.rb +++ b/Library/Homebrew/build.rb @@ -57,9 +57,8 @@ end def post_superenv_hacks f # Only allow Homebrew-approved directories into the PATH, unless # a formula opts-in to allowing the user's path. - if f.env.userpaths? - paths = ORIGINAL_PATHS.map{|pn| pn.realpath.to_s rescue nil } - %w{/usr/X11/bin /opt/X11/bin} - ENV['PATH'] = "#{ENV['PATH']}:#{paths.join(':')}" + if f.env.userpaths? or f.recursive_requirements.any? { |rq| rq.env.userpaths? } + ENV.userpaths! end end diff --git a/Library/Homebrew/dependencies.rb b/Library/Homebrew/dependencies.rb index be6e0cf9dd..8e6c7afdf6 100644 --- a/Library/Homebrew/dependencies.rb +++ b/Library/Homebrew/dependencies.rb @@ -1,3 +1,5 @@ +require 'build_environment' + ## This file defines dependencies and requirements. ## ## A dependency is a formula that another formula needs to install. @@ -169,6 +171,10 @@ class Requirement # See X11Dependency def modify_build_environment; nil end + def env + @env ||= self.class.env + end + def eql?(other) other.is_a? self.class and hash == other.hash end @@ -181,6 +187,12 @@ class Requirement def fatal(val=nil) val.nil? ? @fatal : @fatal = val end + + def env(*settings) + @env ||= BuildEnvironment.new + settings.each { |s| @env << s } + @env + end end end diff --git a/Library/Homebrew/extend/ENV.rb b/Library/Homebrew/extend/ENV.rb index 668fd29bd0..b3b8d26b30 100644 --- a/Library/Homebrew/extend/ENV.rb +++ b/Library/Homebrew/extend/ENV.rb @@ -431,6 +431,11 @@ class << ENV append 'CPPFLAGS', "-DNCURSES_OPAQUE=0" 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 fc_flag_vars = %w{FCFLAGS FFLAGS} diff --git a/Library/Homebrew/requirements.rb b/Library/Homebrew/requirements.rb index dcf9afcd70..9dc8e0660a 100644 --- a/Library/Homebrew/requirements.rb +++ b/Library/Homebrew/requirements.rb @@ -102,6 +102,8 @@ class MPIDependency < Requirement fatal true + env :userpaths + def initialize *lang_list @lang_list = lang_list @non_functional = []