2014-07-02 21:57:52 -05:00
|
|
|
module CompilerConstants
|
2015-05-07 01:12:24 -07:00
|
|
|
GNU_GCC_VERSIONS = %w[4.3 4.4 4.5 4.6 4.7 4.8 4.9 5]
|
|
|
|
GNU_GCC_REGEXP = /^gcc-(4\.[3-9]|5)$/
|
2014-07-02 21:57:52 -05:00
|
|
|
end
|
|
|
|
|
2012-03-18 13:58:13 -05:00
|
|
|
class CompilerFailure
|
2014-08-03 10:47:47 -05:00
|
|
|
attr_reader :name
|
2014-09-21 00:53:15 -05:00
|
|
|
attr_rw :version
|
2012-03-18 13:58:13 -05:00
|
|
|
|
2014-06-16 16:08:41 -05:00
|
|
|
# Allows Apple compiler `fails_with` statements to keep using `build`
|
|
|
|
# even though `build` and `version` are the same internally
|
|
|
|
alias_method :build, :version
|
|
|
|
|
2014-09-21 00:53:15 -05:00
|
|
|
# The cause is no longer used so we need not hold a reference to the string
|
|
|
|
def cause(_); end
|
|
|
|
|
2014-04-04 21:16:09 -07:00
|
|
|
def self.for_standard standard
|
2014-08-01 20:15:58 -05:00
|
|
|
COLLECTIONS.fetch(standard) do
|
2014-04-04 21:16:09 -07:00
|
|
|
raise ArgumentError, "\"#{standard}\" is not a recognized standard"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-01 20:15:57 -05:00
|
|
|
def self.create(spec, &block)
|
2013-06-28 01:38:09 -05:00
|
|
|
# Non-Apple compilers are in the format fails_with compiler => version
|
2014-08-01 20:15:57 -05:00
|
|
|
if spec.is_a?(Hash)
|
2014-08-06 09:56:09 -05:00
|
|
|
_, major_version = spec.each { |e| break e }
|
2014-08-03 10:47:47 -05:00
|
|
|
name = "gcc-#{major_version}"
|
2013-09-28 12:21:16 -07:00
|
|
|
# so fails_with :gcc => '4.8' simply marks all 4.8 releases incompatible
|
2014-08-01 20:15:57 -05:00
|
|
|
version = "#{major_version}.999"
|
2013-12-12 14:53:53 -06:00
|
|
|
else
|
2014-08-03 10:47:47 -05:00
|
|
|
name = spec
|
2014-08-01 20:15:57 -05:00
|
|
|
version = 9999
|
2013-09-28 12:21:16 -07:00
|
|
|
end
|
2014-08-03 11:15:39 -05:00
|
|
|
new(name, version, &block)
|
2014-08-01 20:15:57 -05:00
|
|
|
end
|
|
|
|
|
2014-08-03 10:47:47 -05:00
|
|
|
def initialize(name, version, &block)
|
2014-08-03 10:47:47 -05:00
|
|
|
@name = name
|
2014-08-01 20:15:57 -05:00
|
|
|
@version = version
|
|
|
|
instance_eval(&block) if block_given?
|
2012-03-18 13:58:13 -05:00
|
|
|
end
|
2014-08-01 20:15:58 -05:00
|
|
|
|
2014-08-03 10:47:47 -05:00
|
|
|
def ===(compiler)
|
2014-08-03 13:12:59 -05:00
|
|
|
name == compiler.name && version >= compiler.version
|
2014-08-03 10:47:47 -05:00
|
|
|
end
|
|
|
|
|
2014-08-03 15:28:26 -05:00
|
|
|
def inspect
|
|
|
|
"#<#{self.class.name}: #{name} #{version}>"
|
|
|
|
end
|
|
|
|
|
2014-08-01 20:15:58 -05:00
|
|
|
COLLECTIONS = {
|
|
|
|
:cxx11 => [
|
2014-09-21 00:53:15 -05:00
|
|
|
create(:gcc_4_0),
|
|
|
|
create(:gcc),
|
|
|
|
create(:llvm),
|
|
|
|
create(:clang) { build 425 },
|
|
|
|
create(:gcc => "4.3"),
|
|
|
|
create(:gcc => "4.4"),
|
|
|
|
create(:gcc => "4.5"),
|
|
|
|
create(:gcc => "4.6"),
|
2014-08-01 20:15:58 -05:00
|
|
|
],
|
2015-04-21 17:51:55 -04:00
|
|
|
:openmp => [
|
|
|
|
create(:clang),
|
|
|
|
create(:llvm),
|
|
|
|
],
|
2014-08-01 20:15:58 -05:00
|
|
|
}
|
2012-03-18 13:58:13 -05:00
|
|
|
end
|
|
|
|
|
2014-09-18 15:50:54 -05:00
|
|
|
class CompilerSelector
|
|
|
|
include CompilerConstants
|
2012-03-18 13:58:13 -05:00
|
|
|
|
2014-09-18 15:50:54 -05:00
|
|
|
Compiler = Struct.new(:name, :version)
|
2013-03-13 02:07:01 -05:00
|
|
|
|
2014-09-18 15:50:54 -05:00
|
|
|
COMPILER_PRIORITY = {
|
|
|
|
:clang => [:clang, :gcc, :llvm, :gnu, :gcc_4_0],
|
|
|
|
:gcc => [:gcc, :llvm, :gnu, :clang, :gcc_4_0],
|
|
|
|
:llvm => [:llvm, :gcc, :gnu, :clang, :gcc_4_0],
|
|
|
|
:gcc_4_0 => [:gcc_4_0, :gcc, :llvm, :gnu, :clang],
|
|
|
|
}
|
2012-03-18 13:58:13 -05:00
|
|
|
|
2014-09-18 15:50:54 -05:00
|
|
|
def self.select_for(formula, compilers=self.compilers)
|
2014-09-18 15:50:54 -05:00
|
|
|
new(formula, MacOS, compilers).compiler
|
2013-03-13 02:07:01 -05:00
|
|
|
end
|
2014-09-18 15:50:54 -05:00
|
|
|
|
2014-09-18 15:50:54 -05:00
|
|
|
def self.compilers
|
|
|
|
COMPILER_PRIORITY.fetch(MacOS.default_compiler)
|
|
|
|
end
|
|
|
|
|
2014-09-18 15:50:54 -05:00
|
|
|
attr_reader :formula, :failures, :versions, :compilers
|
2014-09-18 15:50:54 -05:00
|
|
|
|
2014-09-18 15:50:54 -05:00
|
|
|
def initialize(formula, versions, compilers)
|
2014-09-18 15:50:54 -05:00
|
|
|
@formula = formula
|
|
|
|
@failures = formula.compiler_failures
|
2014-06-11 21:05:31 -05:00
|
|
|
@versions = versions
|
2014-09-18 15:50:54 -05:00
|
|
|
@compilers = compilers
|
2012-03-18 13:58:13 -05:00
|
|
|
end
|
|
|
|
|
2013-03-13 02:07:01 -05:00
|
|
|
def compiler
|
2014-09-18 15:50:54 -05:00
|
|
|
find_compiler { |c| return c.name unless fails_with?(c) }
|
2014-09-18 15:50:54 -05:00
|
|
|
raise CompilerSelectionError.new(formula)
|
2013-03-13 02:07:01 -05:00
|
|
|
end
|
2012-03-18 13:58:13 -05:00
|
|
|
|
2013-03-13 02:07:01 -05:00
|
|
|
private
|
2012-03-18 13:58:13 -05:00
|
|
|
|
2014-09-18 15:50:54 -05:00
|
|
|
def find_compiler
|
|
|
|
compilers.each do |compiler|
|
|
|
|
case compiler
|
|
|
|
when :gnu
|
|
|
|
GNU_GCC_VERSIONS.reverse_each do |v|
|
2015-05-07 01:12:24 -07:00
|
|
|
name = "gcc-#{v}"
|
2015-05-17 19:18:32 -04:00
|
|
|
version = compiler_version(name)
|
2014-09-18 15:50:54 -05:00
|
|
|
yield Compiler.new(name, version) if version
|
|
|
|
end
|
|
|
|
else
|
2015-05-17 19:18:32 -04:00
|
|
|
version = compiler_version(compiler)
|
2014-09-18 15:50:54 -05:00
|
|
|
yield Compiler.new(compiler, version) if version
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-18 15:50:54 -05:00
|
|
|
def fails_with?(compiler)
|
2014-09-18 15:50:54 -05:00
|
|
|
failures.any? { |failure| failure === compiler }
|
2014-09-18 15:50:54 -05:00
|
|
|
end
|
2015-05-17 19:18:32 -04:00
|
|
|
|
|
|
|
def compiler_version(name)
|
|
|
|
case name
|
|
|
|
when GNU_GCC_REGEXP
|
|
|
|
versions.non_apple_gcc_version(name)
|
|
|
|
else
|
|
|
|
versions.send("#{name}_build_version")
|
|
|
|
end
|
|
|
|
end
|
2012-03-18 13:58:13 -05:00
|
|
|
end
|