aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/formula_support.rb
diff options
context:
space:
mode:
authorAdam Vandenberg2012-02-04 18:45:08 -0800
committerAdam Vandenberg2012-02-04 18:45:08 -0800
commitfe6ab928579cc4d381a147d4bded5c669ccd2e5f (patch)
treed5a34966c0e8bac94e45d78bcc9c52dd5300f67c /Library/Homebrew/formula_support.rb
parente251e5e4ecd0e2c6ce10cc6ef9b6d9c28ff6390e (diff)
downloadbrew-fe6ab928579cc4d381a147d4bded5c669ccd2e5f.tar.bz2
Split some classes to formula_support
formula.rb is getting big, let's start splitting things out.
Diffstat (limited to 'Library/Homebrew/formula_support.rb')
-rw-r--r--Library/Homebrew/formula_support.rb95
1 files changed, 95 insertions, 0 deletions
diff --git a/Library/Homebrew/formula_support.rb b/Library/Homebrew/formula_support.rb
new file mode 100644
index 000000000..6314f2951
--- /dev/null
+++ b/Library/Homebrew/formula_support.rb
@@ -0,0 +1,95 @@
+require 'download_strategy'
+
+
+# Defines a URL and download method for a stable or HEAD build
+class SoftwareSpecification
+ attr_reader :url, :specs, :using
+
+ VCS_SYMBOLS = {
+ :bzr => BazaarDownloadStrategy,
+ :curl => CurlDownloadStrategy,
+ :cvs => CVSDownloadStrategy,
+ :git => GitDownloadStrategy,
+ :hg => MercurialDownloadStrategy,
+ :nounzip => NoUnzipCurlDownloadStrategy,
+ :post => CurlPostDownloadStrategy,
+ :svn => SubversionDownloadStrategy,
+ }
+
+ def initialize url, specs=nil
+ raise "No url provided" if url.nil?
+ @url = url
+ unless specs.nil?
+ # Get download strategy hint, if any
+ @using = specs.delete :using
+ # The rest of the specs are for source control
+ @specs = specs
+ end
+ end
+
+ # Returns a suitable DownloadStrategy class that can be
+ # used to retreive this software package.
+ def download_strategy
+ return detect_download_strategy(@url) if @using.nil?
+
+ # If a class is passed, assume it is a download strategy
+ return @using if @using.kind_of? Class
+
+ detected = VCS_SYMBOLS[@using]
+ raise "Unknown strategy #{@using} was requested." unless detected
+ return detected
+ end
+
+ def detect_version
+ Pathname.new(@url).version
+ end
+end
+
+
+# Used to annotate formulae that duplicate OS X provided software
+# or cause conflicts when linked in.
+class KegOnlyReason
+ attr_reader :reason, :explanation
+
+ def initialize reason, explanation=nil
+ @reason = reason
+ @explanation = explanation
+ end
+
+ def to_s
+ if @reason == :provided_by_osx
+ <<-EOS.strip
+Mac OS X already provides this program and installing another version in
+parallel can cause all kinds of trouble.
+
+#{@explanation}
+EOS
+ else
+ @reason.strip
+ end
+ end
+end
+
+
+# Used to annotate formulae that won't build correctly with LLVM.
+class FailsWithLLVM
+ attr_reader :msg, :data, :build
+
+ def initialize msg=nil, data=nil
+ if msg.nil? or msg.kind_of? Hash
+ @msg = "(No specific reason was given)"
+ data = msg
+ else
+ @msg = msg
+ end
+ @data = data
+ @build = data.delete :build rescue nil
+ end
+
+ def reason
+ s = @msg
+ s += "Tested with LLVM build #{@build}" unless @build == nil
+ s += "\n"
+ return s
+ end
+end