aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/build_environment.rb
blob: 18876f95422f195187764e4ae173b54359dd7796 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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