diff options
Diffstat (limited to 'Library/Homebrew/utils.rb')
| -rw-r--r-- | Library/Homebrew/utils.rb | 143 | 
1 files changed, 90 insertions, 53 deletions
| diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index de16df994..6dedf764b 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -1,38 +1,3 @@ -class ExecutionError <RuntimeError -  attr :exit_status -  attr :command - -  def initialize cmd, args = [], es = nil -    @command = cmd -    super "Failure while executing: #{cmd} #{pretty(args)*' '}" -    @exit_status = es.exitstatus rescue 1 -  end - -  def was_running_configure? -    @command == './configure' -  end - -  private - -  def pretty args -    args.collect do |arg| -      if arg.to_s.include? ' ' -        "'#{ arg.gsub "'", "\\'" }'" -      else -        arg -      end -    end -  end -end - -class BuildError <ExecutionError -  attr :env - -  def initialize cmd, args = [], es = nil -    super -    @env = ENV.to_hash -  end -end  class Tty    class <<self @@ -112,7 +77,10 @@ end  # Kernel.system but with exceptions  def safe_system cmd, *args -  raise ExecutionError.new(cmd, args, $?) unless Homebrew.system(cmd, *args) +  unless Homebrew.system cmd, *args +    args = args.map{ |arg| arg.gsub " ", "\\ " } * " " +    raise "Failure while executing: #{cmd} #{args}" +  end  end  # prints no output @@ -263,28 +231,97 @@ def nostdout    end  end -def dump_build_env env -  puts "\"--use-llvm\" was specified" if ARGV.include? '--use-llvm' +module MacOS extend self +  def gcc_42_build_version +    `/usr/bin/gcc-4.2 -v 2>&1` =~ /build (\d{4,})/ +    if $1 +      $1.to_i +    elsif system "/usr/bin/which gcc" +      # Xcode 3.0 didn't come with gcc-4.2 +      # We can't change the above regex to use gcc because the version numbers +      # are different and thus, not useful. +      # FIXME I bet you 20 quid this causes a side effect — magic values tend to +      401 +    else +      nil +    end +  end -  %w[ CC CXX LD ].each do |k| -    value = env[k] -    if value -      results = value -      if File.exists? value and File.symlink? value -        target = Pathname.new(value) -        results += " => #{target.realpath}" -      end -      puts "#{k}: #{results}" +  def gcc_40_build_version +    `/usr/bin/gcc-4.0 -v 2>&1` =~ /build (\d{4,})/ +    if $1 +      $1.to_i +    else +      nil      end    end -  %w[ CFLAGS CXXFLAGS CPPFLAGS LDFLAGS MACOSX_DEPLOYMENT_TARGET MAKEFLAGS PKG_CONFIG_PATH -      HOMEBREW_DEBUG HOMEBREW_VERBOSE HOMEBREW_USE_LLVM HOMEBREW_SVN ].each do |k| -    value = env[k] -    puts "#{k}: #{value}" if value +  def llvm_build_version +    if MACOS_VERSION >= 10.6 +      xcode_path = `/usr/bin/xcode-select -print-path`.chomp +      return nil if xcode_path.empty? +      `#{xcode_path}/usr/bin/llvm-gcc -v 2>&1` =~ /LLVM build (\d{4,})/ +      $1.to_i +    end    end -end  def x11_installed?    Pathname.new('/usr/X11/lib/libpng.dylib').exist? -end
\ No newline at end of file +end + +  def macports_or_fink_installed? +    # See these issues for some history: +    # http://github.com/mxcl/homebrew/issues/#issue/13 +    # http://github.com/mxcl/homebrew/issues/#issue/41 +    # http://github.com/mxcl/homebrew/issues/#issue/48 + +    %w[port fink].each do |ponk| +      path = `/usr/bin/which -s #{ponk}` +      return ponk unless path.empty? +    end + +    # we do the above check because macports can be relocated and fink may be +    # able to be relocated in the future. This following check is because if +    # fink and macports are not in the PATH but are still installed it can +    # *still* break the build -- because some build scripts hardcode these paths: +    %w[/sw/bin/fink /opt/local/bin/port].each do |ponk| +      return ponk if File.exist? ponk +    end + +    # finally, sometimes people make their MacPorts or Fink read-only so they +    # can quickly test Homebrew out, but still in theory obey the README's +    # advise to rename the root directory. This doesn't work, many build scripts +    # error out when they try to read from these now unreadable directories. +    %w[/sw /opt/local].each do |path| +      path = Pathname.new(path) +      return path if path.exist? and not path.readable? +    end + +    false +  end +end + +module GitHub extend self +  def issues_for_formula name +    # bit basic as depends on the issue at github having the exact name of the +    # formula in it. Which for stuff like objective-caml is unlikely. So we +    # really should search for aliases too. + +    name = f.name if Formula === name + +    require 'open-uri' +    require 'yaml' + +    issues = [] + +    open "http://github.com/api/v2/yaml/issues/search/mxcl/homebrew/open/#{name}" do |f| +      YAML::load(f.read)['issues'].each do |issue| +        issues << 'http://github.com/mxcl/homebrew/issues/#issue/%s' % issue['number'] +      end +    end + +    issues +  rescue +    [] +  end +end | 
