brew/Library/Homebrew/build_environment.rb
Jack Nagel c53af42117 Allow env DSL to take a block
In addition to

  env :userpaths
  env :std

requirements can now do

  env do
    append 'PATH', '/some/path/to/bin'
    # and more
  end
2013-01-21 17:24:10 -06:00

46 lines
726 B
Ruby

require 'set'
class BuildEnvironment
def initialize(*settings)
@settings = Set.new(settings)
end
def <<(o)
@settings << o
self
end
def std?
@settings.include? :std
end
def userpaths?
@settings.include? :userpaths
end
def modify_build_environment
p = @settings.find { |s| Proc === s }
ENV.instance_eval(&p) unless p.nil?
end
def _dump(*)
@settings.dup.reject { |s| Proc === s }.join(":")
end
def self._load(s)
new(*s.split(":").map(&:to_sym))
end
end
module BuildEnvironmentDSL
def env(*settings, &block)
@env ||= BuildEnvironment.new
if block_given?
@env << block
else
settings.each { |s| @env << s }
end
@env
end
end