diff options
| author | Adam Vandenberg | 2010-03-22 21:19:20 -0700 |
|---|---|---|
| committer | Adam Vandenberg | 2010-03-22 21:19:20 -0700 |
| commit | 6586f89a29325d312a660cd80a3ea857c350e38a (patch) | |
| tree | bb0ba5a4522df23ec821d670c0bffb1ce7364b04 /Library | |
| parent | ff037639317b60393dc9b58b9813d149c4855dfc (diff) | |
| download | brew-6586f89a29325d312a660cd80a3ea857c350e38a.tar.bz2 | |
Add md5 on 'brew create' if we can figure it out.
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/brew.h.rb | 16 | ||||
| -rw-r--r-- | Library/Homebrew/download_strategy.rb | 16 | ||||
| -rw-r--r-- | Library/Homebrew/formula.rb | 14 |
3 files changed, 32 insertions, 14 deletions
diff --git a/Library/Homebrew/brew.h.rb b/Library/Homebrew/brew.h.rb index b5b05ee1e..ff091fea3 100644 --- a/Library/Homebrew/brew.h.rb +++ b/Library/Homebrew/brew.h.rb @@ -26,6 +26,7 @@ end def __make url, name require 'formula' + require 'digest' path = Formula.path name raise "#{path} already exists" if path.exist? @@ -45,13 +46,26 @@ def __make url, name puts "Version detected as #{version}." end + md5 = '' + if ARGV.include? "--cache" and version != nil + strategy = detect_download_strategy url + if strategy == CurlDownloadStrategy + d = strategy.new url, name, version, nil + the_tarball = d.fetch + md5 = Digest::MD5.hexdigest(the_tarball.read) + puts "MD5 is #{md5}" + else + puts "--cache requested, but we can only cache formulas that use Curl." + end + end + template=<<-EOS require 'formula' class #{Formula.class_s name} <Formula url '#{url}' homepage '' - md5 '' + md5 '#{md5}' cmake depends_on 'cmake' diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 8cc279f40..a94be48b3 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -287,3 +287,19 @@ class BazaarDownloadStrategy <AbstractDownloadStrategy end end end + +def detect_download_strategy url + case url + when %r[^cvs://] then CVSDownloadStrategy + when %r[^hg://] then MercurialDownloadStrategy + when %r[^svn://] then SubversionDownloadStrategy + when %r[^svn+http://] then SubversionDownloadStrategy + when %r[^git://] then GitDownloadStrategy + when %r[^bzr://] then BazaarDownloadStrategy + when %r[^https?://(.+?\.)?googlecode\.com/hg] then MercurialDownloadStrategy + when %r[^https?://(.+?\.)?googlecode\.com/svn] then SubversionDownloadStrategy + when %r[^https?://(.+?\.)?sourceforge\.net/svnroot/] then SubversionDownloadStrategy + when %r[^http://svn.apache.org/repos/] then SubversionDownloadStrategy + else CurlDownloadStrategy + end +end diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 9d1617ed4..9f7137507 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -134,19 +134,7 @@ class Formula # reimplement if we don't autodetect the download strategy you require def download_strategy - case url - when %r[^cvs://] then CVSDownloadStrategy - when %r[^hg://] then MercurialDownloadStrategy - when %r[^svn://] then SubversionDownloadStrategy - when %r[^svn+http://] then SubversionDownloadStrategy - when %r[^git://] then GitDownloadStrategy - when %r[^bzr://] then BazaarDownloadStrategy - when %r[^https?://(.+?\.)?googlecode\.com/hg] then MercurialDownloadStrategy - when %r[^https?://(.+?\.)?googlecode\.com/svn] then SubversionDownloadStrategy - when %r[^https?://(.+?\.)?sourceforge\.net/svnroot/] then SubversionDownloadStrategy - when %r[^http://svn.apache.org/repos/] then SubversionDownloadStrategy - else CurlDownloadStrategy - end + detect_download_strategy url end # tell the user about any caveats regarding this package, return a string |
