diff options
| author | Brian Smyth | 2009-09-09 11:59:46 -0400 |
|---|---|---|
| committer | Max Howell | 2009-09-16 14:49:05 +0100 |
| commit | cfb6505767f591a1580c7ed4ce75acdc00ad8491 (patch) | |
| tree | 9e9767de610e31fae294cb0f2df8f81f7abc6792 /Library | |
| parent | 364f64fefb2af57a09b1fe0bb6900629ab0e86c5 (diff) | |
| download | homebrew-cfb6505767f591a1580c7ed4ce75acdc00ad8491.tar.bz2 | |
Teach patch to uncompress patches if necessary.
This change also eliminates the somewhat duplicate codepath if patches
returns and Array rather than a Hash.
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/formula.rb | 60 |
1 files changed, 41 insertions, 19 deletions
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 39a0f78ba..192620798 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -246,28 +246,50 @@ private def patch return if patches.empty? ohai "Patching" - if patches.kind_of? Hash - patch_args=[] - curl_args=[] - n=0 - patches.each do |arg, urls| - urls.each do |url| - dst='%03d-homebrew.patch' % n+=1 - curl_args<<url<<'-o'<<dst - patch_args<<["-#{arg}",'-i',dst] + if not patches.kind_of? Hash + # We assume -p0 + patch_defns = { :p0 => patches } + else + patch_defns = patches + end + + patch_list=[] + n=0 + patch_defns.each do |arg, urls| + urls.each do |url| + dst='%03d-homebrew.patch' % n+=1 + compression = false + case url + when /\.gz$/ + compression = :gzip + when /\.bz2$/ + compression = :bzip2 end + patch_list << { + :curl_args => [url, '-o', dst], + :args => ["-#{arg}",'-i', dst], + :filename => dst, + :compression => compression + } end - # downloading all at once is much more efficient, espeically for FTP - curl *curl_args - patch_args.each do |args| - # -f means it doesn't prompt the user if there are errors, if just - # exits with non-zero status - safe_system 'patch', '-f', *args + end + # downloading all at once is much more efficient, espeically for FTP + curl *(patch_list.collect { |p| p[:curl_args] }).flatten + patch_list.each do |p| + case p[:compression] + when :gzip + # We rename with a .gz since gunzip -S '' deletes the file mysteriously + FileUtils.mv p[:filename], p[:filename] + '.gz' + `gunzip #{p[:filename] + '.gz'}` + when :bzip2 + # We rename with a .bz2 since bunzip2 can't guess the original filename + # without it + FileUtils.mv p[:filename], p[:filename] + '.bz2' + `bunzip2 #{p[:filename] + '.bz2'}` end - else - ff=(1..patches.length).collect {|n| '%03d-homebrew.patch'%n} - curl *patches+ff.collect {|f|"-o#{f}"} - ff.each {|f| safe_system 'patch', '-p0', '-i', f} + # -f means it doesn't prompt the user if there are errors, if just + # exits with non-zero status + safe_system 'patch', '-f', *(p[:args]) end end |
