diff options
| author | Max Howell | 2010-09-11 20:22:54 +0100 | 
|---|---|---|
| committer | Adam Vandenberg | 2011-03-12 11:55:02 -0800 | 
| commit | 9afc85ad338f9e053fe36127937d308ad62593bc (patch) | |
| tree | 610d3c0ae869d9e58e283f065c914566316ddd8c /Library/Homebrew/utils.rb | |
| parent | f57463eee6333f8dbeb42a122290677d6c755871 (diff) | |
| download | homebrew-9afc85ad338f9e053fe36127937d308ad62593bc.tar.bz2 | |
Refactor the brew command into one file per command
The code was sucking. To the extent that maintenance was hard. It's a lot
easier to work with code that is sensibly split at sensible boundaries. So
now it is more like that.
But the refactor is minimal. Because we don't want you to have more merge
hell than absolutely necessary.
If you merge you will need to pay attention to brew.h.rb (as it is deleted)
and bin/brew (as command logic is gone). It will be painful, but you will just
have to help git out by moving any changes around manually.
Note compatibility.rb. It ensures that any function renames or removals don't
break anything. We're pretty serious about backwards compatibility. And that's
because we encourage you to hack around with the innards. And we couldn't do
that if we would then just make stuff disappear behind your back.
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 | 
