From d06824c357a43cc2ecb5229784285cb30b037354 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sat, 19 Jan 2013 20:45:57 -0600 Subject: [PATCH] ENV.with_build_environment --- Library/Homebrew/extend/ENV.rb | 8 ++++++++ Library/Homebrew/requirements.rb | 25 +++++++++++-------------- Library/Homebrew/test/test_ENV.rb | 9 +++++++++ 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/Library/Homebrew/extend/ENV.rb b/Library/Homebrew/extend/ENV.rb index 095d05b70e..6ac5a0db24 100644 --- a/Library/Homebrew/extend/ENV.rb +++ b/Library/Homebrew/extend/ENV.rb @@ -438,6 +438,14 @@ class << ENV self['PATH'] = paths.unshift(*self['PATH'].split(":")).uniq.join(":") end + def with_build_environment + old_env = to_hash + setup_build_environment + yield + ensure + replace(old_env) + end + def fortran fc_flag_vars = %w{FCFLAGS FFLAGS} diff --git a/Library/Homebrew/requirements.rb b/Library/Homebrew/requirements.rb index ffb03cb378..b5d920bab0 100644 --- a/Library/Homebrew/requirements.rb +++ b/Library/Homebrew/requirements.rb @@ -125,23 +125,20 @@ class MPIDependency < Requirement def satisfied? # we have to assure the ENV is (almost) as during the build - orig_PATH = ENV['PATH'] require 'superenv' - ENV.setup_build_environment - ENV.userpaths! - @lang_list.each do |lang| - case lang - when :cc, :cxx, :f90, :f77 - compiler = 'mpi' + lang.to_s - @non_functional << compiler unless mpi_wrapper_works? compiler - else - @unknown_langs << lang.to_s + ENV.with_build_environment do + ENV.userpaths! + + @lang_list.each do |lang| + case lang + when :cc, :cxx, :f90, :f77 + compiler = 'mpi' + lang.to_s + @non_functional << compiler unless mpi_wrapper_works? compiler + else + @unknown_langs << lang.to_s + end end end - - # Restore the original paths - ENV['PATH'] = orig_PATH - @unknown_langs.empty? and @non_functional.empty? end diff --git a/Library/Homebrew/test/test_ENV.rb b/Library/Homebrew/test/test_ENV.rb index 8e69cb6f01..1a1dd922bd 100644 --- a/Library/Homebrew/test/test_ENV.rb +++ b/Library/Homebrew/test/test_ENV.rb @@ -26,4 +26,13 @@ class EnvironmentTests < Test::Unit::TestCase assert_nil ENV['LD'] assert_equal ENV['OBJC'], ENV['CC'] end + + def test_with_build_environment + before = ENV.to_hash + ENV.with_build_environment do + ENV['foo'] = 'bar' + end + assert_nil ENV['foo'] + assert_equal before, ENV.to_hash + end end