Requirement: env DSL is evaluated in context of self, not ENV

This was meant to support:

  env do |req|
    append_path 'PATH', req.some_method
    ...
  end

i.e., the block was evaluated in the context of ENV. But it turned out
to be not so useful after all, so I'm ripping it out before something
actually depends on it.
This commit is contained in:
Jack Nagel 2013-04-01 12:05:57 -05:00
parent 462a418878
commit 1b0f0824fe
7 changed files with 7 additions and 43 deletions

View File

@ -22,8 +22,8 @@ class BuildEnvironment
@settings.include? :userpaths @settings.include? :userpaths
end end
def modify_build_environment(context=nil) def modify_build_environment(receiver)
@procs.each { |p| ENV.instance_exec(context, &p) } @procs.each { |p| receiver.instance_eval(&p) }
end end
def _dump(*) def _dump(*)

View File

@ -1,15 +0,0 @@
class Object
def instance_exec(*args, &block)
method_name = :__temp_instance_exec_method
singleton_class = (class << self; self; end)
singleton_class.class_eval do
define_method(method_name, &block)
end
send(method_name, *args)
ensure
singleton_class.class_eval do
remove_method(method_name) if method_defined?(method_name)
end
end unless method_defined?(:instance_exec)
end

View File

@ -3,7 +3,6 @@ require 'extend/pathname'
require 'extend/ARGV' require 'extend/ARGV'
require 'extend/string' require 'extend/string'
require 'extend/symbol' require 'extend/symbol'
require 'extend/object'
require 'utils' require 'utils'
require 'exceptions' require 'exceptions'
require 'set' require 'set'

View File

@ -68,7 +68,7 @@ class Requirement
when Pathname when Pathname
self.class.env do self.class.env do
unless ENV["PATH"].split(":").include?(o.parent.to_s) unless ENV["PATH"].split(":").include?(o.parent.to_s)
append("PATH", o.parent, ":") ENV.append("PATH", o.parent, ":")
end end
end end
end end

View File

@ -179,11 +179,11 @@ class MPIDependency < Requirement
@unknown_langs.empty? and @non_functional.empty? @unknown_langs.empty? and @non_functional.empty?
end end
env do |req| env do
# Set environment variables to help configure scripts find MPI compilers. # Set environment variables to help configure scripts find MPI compilers.
# Variable names taken from: # Variable names taken from:
# http://www.gnu.org/software/autoconf-archive/ax_mpi.html # http://www.gnu.org/software/autoconf-archive/ax_mpi.html
req.lang_list.each do |lang| @lang_list.each do |lang|
compiler = 'mpi' + lang.to_s compiler = 'mpi' + lang.to_s
mpi_path = which compiler mpi_path = which compiler

View File

@ -23,7 +23,7 @@ class BuildEnvironmentTests < Test::Unit::TestCase
def test_modify_build_environment def test_modify_build_environment
@env << Proc.new { raise StandardError } @env << Proc.new { raise StandardError }
assert_raises(StandardError) do assert_raises(StandardError) do
@env.modify_build_environment @env.modify_build_environment(self)
end end
end end
@ -38,7 +38,7 @@ class BuildEnvironmentTests < Test::Unit::TestCase
foo = mock("foo") foo = mock("foo")
@env << Proc.new { foo.some_message } @env << Proc.new { foo.some_message }
foo.expects(:some_message) foo.expects(:some_message)
@env.modify_build_environment @env.modify_build_environment(self)
end end
def test_env_block_with_argument def test_env_block_with_argument

View File

@ -1,20 +0,0 @@
require 'testing_env'
require 'extend/object'
class InstanceExecTests < Test::Unit::TestCase
def test_evaluates_in_context_of_receiver
assert_equal 1, [1].instance_exec { first }
end
def test_passes_arguments_to_block
assert_equal 2, [1].instance_exec(1) { |x| first + x }
end
def test_does_not_persist_temporary_singleton_method
obj = Object.new
before = obj.methods
obj.instance_exec { methods }
after = obj.methods
assert_equal before, after
end
end