mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00

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.
100 lines
1.9 KiB
Ruby
100 lines
1.9 KiB
Ruby
|
|
class NotAKegError < RuntimeError
|
|
end
|
|
|
|
class FormulaUnavailableError < RuntimeError
|
|
attr :name
|
|
def initialize name
|
|
@name = name
|
|
super "No available formula for #{name}"
|
|
end
|
|
end
|
|
|
|
module Homebrew
|
|
class InstallationError < RuntimeError
|
|
attr :formula
|
|
def initialize formula
|
|
@formula = formula
|
|
end
|
|
def initialize formula, message
|
|
super message
|
|
@formula = formula
|
|
end
|
|
end
|
|
end
|
|
|
|
class FormulaAlreadyInstalledError < Homebrew::InstallationError
|
|
def message
|
|
"Formula already installed: #{formula}"
|
|
end
|
|
end
|
|
|
|
class FormulaInstallationAlreadyAttemptedError < Homebrew::InstallationError
|
|
def message
|
|
"Formula installation already attempted: #{formula}"
|
|
end
|
|
end
|
|
|
|
class UnsatisfiedExternalDependencyError < Homebrew::InstallationError
|
|
attr :type
|
|
|
|
def initialize formula, type
|
|
@type = type
|
|
@formula = formula
|
|
end
|
|
|
|
def message
|
|
<<-EOS.undent
|
|
Unsatisfied dependency: #{formula}
|
|
Homebrew does not provide #{type.to_s.capitalize} dependencies, #{tool} does:
|
|
|
|
#{command_line} #{formula}
|
|
EOS
|
|
end
|
|
|
|
private
|
|
|
|
def tool
|
|
case type
|
|
when :python then 'pip'
|
|
when :ruby, :jruby then 'rubygems'
|
|
when :perl then 'cpan'
|
|
end
|
|
end
|
|
|
|
def command_line
|
|
case type
|
|
when :python
|
|
"#{brew_pip}pip install"
|
|
when :ruby
|
|
"gem install"
|
|
when :perl
|
|
"cpan -i"
|
|
when :jruby
|
|
"jruby -S gem install"
|
|
end
|
|
end
|
|
|
|
def brew_pip
|
|
'brew install pip && ' unless Formula.factory('pip').installed?
|
|
end
|
|
end
|
|
|
|
class BuildError < Homebrew::InstallationError
|
|
attr :exit_status
|
|
attr :command
|
|
attr :env
|
|
|
|
def initialize formula, cmd, args, es
|
|
@command = cmd
|
|
@env = ENV.to_hash
|
|
@exit_status = es.exitstatus rescue 1
|
|
args = args.map{ |arg| arg.gsub " ", "\\ " }.join(" ")
|
|
super formula, "Failed executing: #{command} #{args}"
|
|
end
|
|
|
|
def was_running_configure?
|
|
@command == './configure'
|
|
end
|
|
end
|