mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-15 19:56:59 +08:00

Move Formula.expand_dependencies into the Dependency class, and extend it to allow arbitrary filters to be applied when enumerating deps. When supplied with a block, expand_dependencies will yield a [dependent, dependency] pair for each dependency, allowing callers to filter out dependencies that may not be applicable or useful in a given situation. Deps can be skipped by simple calling Dependency.prune in the block, e.g.: Dependency.expand_dependencies do |f, dep| Dependency.prune if dep.to_formula.installed? end The return value of the method is the filtered list. If no block is supplied, a default filter that omits optional or recommended deps based on what the dependent formula has requested is applied. Formula#recursive_dependencies is now implemented on top of this, allowing FormulaInstaller to exact detailed control over what deps are installed. `brew missing` and `brew upgrade` can learn to use this to apply the installed options set when expanding dependencies. Move Formula.expand_deps and Formula#recursive_deps into compat, because these methods do not respect the new optional and recommended tags and thus should no longer be used.
250 lines
5.2 KiB
Ruby
250 lines
5.2 KiB
Ruby
## Compatibility layer introduced in 0.8 (refactor)
|
|
|
|
# maybe never used by anyone, but alas it must continue to exist
|
|
def versions_of(keg_name)
|
|
`/bin/ls #{HOMEBREW_CELLAR}/#{keg_name}`.collect { |version| version.strip }.reverse
|
|
end
|
|
|
|
def dump_config
|
|
require 'cmd/--config'
|
|
Homebrew.__config
|
|
end
|
|
|
|
def dump_build_env env
|
|
require 'cmd/--env'
|
|
Homebrew.dump_build_env env
|
|
end
|
|
|
|
def default_cc
|
|
MacOS.default_cc
|
|
end
|
|
|
|
def gcc_42_build
|
|
MacOS.gcc_42_build_version
|
|
end
|
|
|
|
alias :gcc_build :gcc_42_build
|
|
|
|
def gcc_40_build
|
|
MacOS.gcc_40_build_version
|
|
end
|
|
|
|
def llvm_build
|
|
MacOS.llvm_build_version
|
|
end
|
|
|
|
def x11_installed?
|
|
MacOS::X11.installed?
|
|
end
|
|
|
|
def macports_or_fink_installed?
|
|
MacOS.macports_or_fink_installed?
|
|
end
|
|
|
|
def outdated_brews
|
|
require 'cmd/outdated'
|
|
Homebrew.outdated_brews
|
|
end
|
|
|
|
def search_brews text
|
|
require 'cmd/search'
|
|
Homebrew.search_brews text
|
|
end
|
|
|
|
def snow_leopard_64?
|
|
MacOS.prefer_64_bit?
|
|
end
|
|
|
|
class Formula
|
|
# in compatability because the naming is somewhat confusing
|
|
def self.resolve_alias name
|
|
opoo 'Formula.resolve_alias is deprecated and will eventually be removed'
|
|
opoo 'Use Formula.canonical_name instead.'
|
|
|
|
# Don't resolve paths or URLs
|
|
return name if name.include?("/")
|
|
|
|
aka = HOMEBREW_REPOSITORY+"Library/Aliases"+name
|
|
if aka.file?
|
|
aka.realpath.basename('.rb').to_s
|
|
else
|
|
name
|
|
end
|
|
end
|
|
|
|
# This used to be called in "def install", but should now be used
|
|
# up in the DSL section.
|
|
def fails_with_llvm msg=nil, data=nil
|
|
opoo "Calling fails_with_llvm in the install method is deprecated"
|
|
puts "Use the fails_with DSL instead."
|
|
FailsWithLLVM.new(msg, data).handle_failure
|
|
end
|
|
|
|
def fails_with_llvm?
|
|
fails_with? :llvm
|
|
end
|
|
|
|
def self.fails_with_llvm msg=nil, data=nil
|
|
fails_with_llvm_reason = FailsWithLLVM.new(msg, data)
|
|
@cc_failures ||= CompilerFailures.new
|
|
@cc_failures << fails_with_llvm_reason
|
|
end
|
|
|
|
def std_cmake_parameters
|
|
"-DCMAKE_INSTALL_PREFIX='#{prefix}' -DCMAKE_BUILD_TYPE=None -DCMAKE_FIND_FRAMEWORK=LAST -Wno-dev"
|
|
end
|
|
|
|
class << self
|
|
def bottle_sha1 val=nil
|
|
val.nil? ? @bottle_sha1 : @bottle_sha1 = val
|
|
end
|
|
end
|
|
|
|
# These methods return lists of Formula objects.
|
|
# They are eprecated in favor of Dependency::expand_dependencies
|
|
# and Formula#recursive_dependencies, which return lists of
|
|
# Dependency objects instead.
|
|
def self.expand_deps f
|
|
f.deps.map do |dep|
|
|
f_dep = Formula.factory dep.to_s
|
|
expand_deps(f_dep) << f_dep
|
|
end
|
|
end
|
|
|
|
def recursive_deps
|
|
Formula.expand_deps(self).flatten.uniq
|
|
end
|
|
end
|
|
|
|
class UnidentifiedFormula < Formula
|
|
end
|
|
|
|
module HomebrewEnvExtension extend self
|
|
def use_clang?
|
|
compiler == :clang
|
|
end
|
|
|
|
def use_gcc?
|
|
compiler == :gcc
|
|
end
|
|
|
|
def use_llvm?
|
|
compiler == :llvm
|
|
end
|
|
end
|
|
|
|
class FailsWithLLVM
|
|
attr_reader :compiler, :build, :cause
|
|
|
|
def initialize msg=nil, data=nil
|
|
if msg.nil? or msg.kind_of? Hash
|
|
@cause = "(No specific reason was given)"
|
|
data = msg
|
|
else
|
|
@cause = msg
|
|
end
|
|
@build = (data.delete :build rescue nil).to_i
|
|
@compiler = :llvm
|
|
end
|
|
|
|
def handle_failure
|
|
return unless ENV.compiler == :llvm
|
|
|
|
# version 2336 is the latest version as of Xcode 4.2, so it is the
|
|
# latest version we have tested against so we will switch to GCC and
|
|
# bump this integer when Xcode 4.3 is released. TODO do that!
|
|
if build.to_i >= 2336
|
|
if MacOS::Xcode.version < "4.2"
|
|
opoo "Formula will not build with LLVM, using GCC"
|
|
ENV.gcc
|
|
else
|
|
opoo "Formula will not build with LLVM, trying Clang"
|
|
ENV.clang
|
|
end
|
|
return
|
|
end
|
|
opoo "Building with LLVM, but this formula is reported to not work with LLVM:"
|
|
puts
|
|
puts cause
|
|
puts
|
|
puts <<-EOS.undent
|
|
We are continuing anyway so if the build succeeds, please open a ticket with
|
|
the following information: #{MacOS.llvm_build_version}-#{MACOS_VERSION}. So
|
|
that we can update the formula accordingly. Thanks!
|
|
EOS
|
|
puts
|
|
if MacOS::Xcode.version < "4.2"
|
|
puts "If it doesn't work you can: brew install --use-gcc"
|
|
else
|
|
puts "If it doesn't work you can try: brew install --use-clang"
|
|
end
|
|
puts
|
|
end
|
|
end
|
|
|
|
# TODO eventually some of these should print deprecation warnings
|
|
module MacOS extend self
|
|
def xcode_folder
|
|
Xcode.folder
|
|
end
|
|
|
|
def xcode_prefix
|
|
Xcode.prefix
|
|
end
|
|
|
|
def xcode_installed?
|
|
Xcode.installed?
|
|
end
|
|
|
|
def xcode_version
|
|
Xcode.version
|
|
end
|
|
|
|
def clt_installed?
|
|
CLT.installed?
|
|
end
|
|
|
|
def clt_version?
|
|
CLT.version
|
|
end
|
|
|
|
def x11_installed?
|
|
X11.installed?
|
|
end
|
|
|
|
def x11_prefix
|
|
X11.prefix
|
|
end
|
|
|
|
def leopard?
|
|
10.5 == MACOS_VERSION
|
|
end
|
|
|
|
def snow_leopard?
|
|
10.6 <= MACOS_VERSION # Actually Snow Leopard or newer
|
|
end
|
|
alias_method :snow_leopard_or_newer?, :snow_leopard?
|
|
|
|
def lion?
|
|
10.7 <= MACOS_VERSION # Actually Lion or newer
|
|
end
|
|
alias_method :lion_or_newer?, :lion?
|
|
|
|
def mountain_lion?
|
|
10.8 <= MACOS_VERSION # Actually Mountain Lion or newer
|
|
end
|
|
alias_method :mountain_lion_or_newer?, :mountain_lion?
|
|
|
|
def macports_or_fink_installed?
|
|
not MacOS.macports_or_fink.empty?
|
|
end
|
|
end
|
|
|
|
|
|
class Version
|
|
def slice *args
|
|
opoo "Calling slice on versions is deprecated, use: to_s.slice"
|
|
to_s.slice *args
|
|
end
|
|
end
|