aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/patch.rb
diff options
context:
space:
mode:
authorJack Nagel2014-07-29 16:06:06 -0500
committerJack Nagel2014-07-29 16:22:06 -0500
commit3f12ddbccd8416d4355e0fd0efa8f95bc1a7632f (patch)
tree0c4693b736fbe17872487215a6b73ae534b8cecf /Library/Homebrew/patch.rb
parente0c97177170f1238c53d0b9ecca8dd97bf74c03e (diff)
downloadbrew-3f12ddbccd8416d4355e0fd0efa8f95bc1a7632f.tar.bz2
Decouple DATA patches from the executing script
Diffstat (limited to 'Library/Homebrew/patch.rb')
-rw-r--r--Library/Homebrew/patch.rb45
1 files changed, 35 insertions, 10 deletions
diff --git a/Library/Homebrew/patch.rb b/Library/Homebrew/patch.rb
index 377ef3ead..477eb20a8 100644
--- a/Library/Homebrew/patch.rb
+++ b/Library/Homebrew/patch.rb
@@ -5,13 +5,17 @@ require 'erb'
module Patch
def self.create(strip, io, &block)
case strip
- when :DATA, IO, StringIO
+ when :DATA
+ DATAPatch.new(:p1)
+ when IO, StringIO
IOPatch.new(strip, :p1)
when String
IOPatch.new(StringIO.new(strip), :p1)
when Symbol
case io
- when :DATA, IO, StringIO
+ when :DATA
+ DATAPatch.new(strip)
+ when IO, StringIO
IOPatch.new(io, strip)
when String
IOPatch.new(StringIO.new(io), strip)
@@ -29,16 +33,15 @@ module Patch
case list
when Hash
list
- when Array, String, IO
+ when Array, String, :DATA
{ :p1 => list }
else
{}
end.each_pair do |strip, urls|
- urls = [urls] unless Array === urls
- urls.each do |url|
+ Array(urls).each do |url|
case url
- when IO
- patch = IOPatch.new(url, strip)
+ when :DATA
+ patch = DATAPatch.new(strip)
else
patch = LegacyPatch.new(strip, url)
end
@@ -64,9 +67,7 @@ class IOPatch
end
def apply
- @io = DATA if @io == :DATA
- data = @io.read
- data.gsub!("HOMEBREW_PREFIX", HOMEBREW_PREFIX)
+ data = contents.gsub("HOMEBREW_PREFIX", HOMEBREW_PREFIX)
IO.popen("/usr/bin/patch -g 0 -f -#{strip}", "w") { |p| p.write(data) }
raise ErrorDuringExecution, "Applying DATA patch failed" unless $?.success?
ensure
@@ -75,11 +76,35 @@ class IOPatch
@io = nil
end
+ def contents
+ @io.read
+ end
+
def inspect
"#<#{self.class.name}: #{strip.inspect}>"
end
end
+class DATAPatch < IOPatch
+ attr_accessor :path
+
+ def initialize(strip)
+ @strip = strip
+ @path = nil
+ end
+
+ def contents
+ data = ""
+ path.open("rb") do |f|
+ begin
+ line = f.gets
+ end until line.nil? || /^__END__$/ === line
+ data << line while line = f.gets
+ end
+ data
+ end
+end
+
class ExternalPatch
attr_reader :resource, :strip