aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/build_environment.rb
blob: e6dbf9734a251710462b0875625f519b8dbb9d0d (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
46
47
48
require 'set'

class BuildEnvironment
  def initialize(*settings)
    @settings = Set.new(settings)
    @procs = Set.new
  end

  def <<(o)
    case o
    when Proc then @procs << o
    else @settings << o
    end
    self
  end

  def std?
    @settings.include? :std
  end

  def userpaths?
    @settings.include? :userpaths
  end

  def modify_build_environment(receiver)
    @procs.each { |p| receiver.instance_eval(&p) }
  end

  def _dump(*)
    @settings.to_a.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