blob: f716256ef4ad806979b04680bad8dd95606e2df7 (
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
class Compiler < Struct.new(:name, :priority)
def build
MacOS.send("#{name}_build_version")
end
end
class CompilerFailure
attr_reader :compiler
def initialize compiler, &block
@compiler = compiler
instance_eval(&block) if block_given?
@build ||= 9999
end
def build val=nil
val.nil? ? @build.to_i : @build = val.to_i
end
def cause val=nil
val.nil? ? @cause : @cause = val
end
end
class CompilerQueue
def initialize
@array = []
end
def <<(o)
@array << o
self
end
def pop
@array.delete(@array.max { |a, b| a.priority <=> b.priority })
end
def empty?
@array.empty?
end
end
class CompilerSelector
def initialize(f, old_compiler=ENV.compiler)
@f = f
@old_compiler = old_compiler
@compilers = CompilerQueue.new
%w{clang llvm gcc}.map(&:to_sym).each do |cc|
unless MacOS.send("#{cc}_build_version").nil?
@compilers << Compiler.new(cc, priority_for(cc))
end
end
end
def compiler
begin
cc = @compilers.pop
end while @f.fails_with?(cc)
cc.nil? ? @old_compiler : cc.name
end
private
def priority_for(cc)
case cc
when :clang then MacOS.clang_build_version >= 318 ? 3 : 0.5
when :llvm then 2
when :gcc then 1
end
end
end
|