diff --git a/Library/Homebrew/macos.rb b/Library/Homebrew/macos.rb index e884000dd0f1..5e371d83d0ef 100644 --- a/Library/Homebrew/macos.rb +++ b/Library/Homebrew/macos.rb @@ -39,6 +39,7 @@ def locate tool end end + def dev_tools_path @dev_tools_path ||= \ if File.exist? MacOS::CLT::STANDALONE_PKG_PATH and @@ -107,19 +108,18 @@ def default_compiler end def gcc_40_build_version - @gcc_40_build_version ||= if locate("gcc-4.0") - `#{locate("gcc-4.0")} --version` =~ /build (\d{4,})/ - $1.to_i - end + @gcc_40_build_version ||= + if (path = locate("gcc-4.0")) + %x{#{path} --version}[/build (\d{4,})/, 1] + end end alias_method :gcc_4_0_build_version, :gcc_40_build_version def gcc_42_build_version - @gcc_42_build_version ||= if locate("gcc-4.2") \ - and not locate("gcc-4.2").realpath.basename.to_s =~ /^llvm/ - `#{locate("gcc-4.2")} --version` =~ /build (\d{4,})/ - $1.to_i - end + @gcc_42_build_version ||= + if (path = locate("gcc-4.2")) && path.realpath.basename.to_s !~ /^llvm/ + %x{#{path} --version}[/build (\d{4,})/, 1].to_i + end end alias_method :gcc_build_version, :gcc_42_build_version @@ -133,17 +133,17 @@ def llvm_build_version end def clang_version - @clang_version ||= if locate("clang") - `#{locate("clang")} --version` =~ /(?:clang|LLVM) version (\d\.\d)/ - $1 - end + @clang_version ||= + if (path = locate("clang")) + %x{#{path} --version}[/(?:clang|LLVM) version (\d\.\d)/, 1] + end end def clang_build_version - @clang_build_version ||= if locate("clang") - `#{locate("clang")} --version` =~ %r[clang-(\d{2,})] - $1.to_i - end + @clang_build_version ||= + if (path = locate("clang")) + %x{#{path} --version}[%r[clang-(\d{2,})], 1] + end end # See these issues for some history: