Skip to content

Commit

Permalink
Return compiler versions and builds as Versions
Browse files Browse the repository at this point in the history
  • Loading branch information
mistydemeo committed Nov 10, 2016
1 parent 16529a4 commit 20bbeb5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
11 changes: 9 additions & 2 deletions Library/Homebrew/compilers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ module CompilerConstants

class CompilerFailure
attr_reader :name
attr_rw :version

def version(val = nil)
if val
@version = Version.parse(val.to_s)
else
@version
end
end

# Allows Apple compiler `fails_with` statements to keep using `build`
# even though `build` and `version` are the same internally
Expand Down Expand Up @@ -45,7 +52,7 @@ def self.create(spec, &block)

def initialize(name, version, &block)
@name = name
@version = version
@version = Version.parse(version.to_s)
instance_eval(&block) if block_given?
end

Expand Down
22 changes: 17 additions & 5 deletions Library/Homebrew/development_tools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def default_compiler
def gcc_40_build_version
@gcc_40_build_version ||=
if (path = locate("gcc-4.0"))
`#{path} --version 2>/dev/null`[/build (\d{4,})/, 1].to_i
Version.new `#{path} --version 2>/dev/null`[/build (\d{4,})/, 1].to_i
else
Version::NULL
end
end
alias gcc_4_0_build_version gcc_40_build_version
Expand All @@ -54,7 +56,9 @@ def gcc_42_build_version
begin
gcc = locate("gcc-4.2") || HOMEBREW_PREFIX.join("opt/apple-gcc42/bin/gcc-4.2")
if gcc.exist? && !gcc.realpath.basename.to_s.start_with?("llvm")
`#{gcc} --version 2>/dev/null`[/build (\d{4,})/, 1].to_i
Version.new `#{gcc} --version 2>/dev/null`[/build (\d{4,})/, 1]
else
Version::NULL
end
end
end
Expand All @@ -63,22 +67,30 @@ def gcc_42_build_version
def clang_version
@clang_version ||=
if (path = locate("clang"))
`#{path} --version`[/(?:clang|LLVM) version (\d\.\d)/, 1]
Version.new `#{path} --version`[/(?:clang|LLVM) version (\d\.\d)/, 1]
else
Version::NULL
end
end

def clang_build_version
@clang_build_version ||=
if (path = locate("clang"))
`#{path} --version`[/clang-(\d{2,})/, 1].to_i
Version.new `#{path} --version`[/clang-(\d{2,})/, 1]
else
Version::NULL
end
end

def non_apple_gcc_version(cc)
(@non_apple_gcc_version ||= {}).fetch(cc) do
path = HOMEBREW_PREFIX.join("opt", "gcc", "bin", cc)
path = locate(cc) unless path.exist?
version = `#{path} --version`[/gcc(?:-\d(?:\.\d)? \(.+\))? (\d\.\d\.\d)/, 1] if path
version = if path
Version.new(`#{path} --version`[/gcc(?:-\d(?:\.\d)? \(.+\))? (\d\.\d\.\d)/, 1])
else
Version::NULL
end
@non_apple_gcc_version[cc] = version
end
end
Expand Down

0 comments on commit 20bbeb5

Please sign in to comment.