aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Nagel2014-07-29 16:06:07 -0500
committerJack Nagel2014-07-29 16:22:06 -0500
commit893775c7b4df963ee68d8f4f46bbe2e644768b02 (patch)
tree5988635c715e8cca1766674cb45cbbec986d9af1
parentf3cb1d2b0614e3dcfe2e2911e65bfd24511a2fc2 (diff)
downloadhomebrew-893775c7b4df963ee68d8f4f46bbe2e644768b02.tar.bz2
Simplify internal representation of patches
- remove support for IO objects, since we no longer access ::DATA directly - since we don't need to support IO objects, use a separate class for string patches and stop wrapping strings in StringIO ojects
-rw-r--r--Library/Homebrew/formula.rb4
-rw-r--r--Library/Homebrew/patch.rb47
-rw-r--r--Library/Homebrew/software_spec.rb4
-rw-r--r--Library/Homebrew/test/test_patch.rb17
4 files changed, 30 insertions, 42 deletions
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index 70f9af310..ee3235206 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -671,8 +671,8 @@ class Formula
specs.each { |spec| spec.option(name, description) }
end
- def patch strip=:p1, io=nil, &block
- specs.each { |spec| spec.patch(strip, io, &block) }
+ def patch strip=:p1, src=nil, &block
+ specs.each { |spec| spec.patch(strip, src, &block) }
end
def plist_options options
diff --git a/Library/Homebrew/patch.rb b/Library/Homebrew/patch.rb
index 477eb20a8..53ea0ac6d 100644
--- a/Library/Homebrew/patch.rb
+++ b/Library/Homebrew/patch.rb
@@ -1,24 +1,19 @@
require 'resource'
-require 'stringio'
require 'erb'
module Patch
- def self.create(strip, io, &block)
+ def self.create(strip, src, &block)
case strip
when :DATA
DATAPatch.new(:p1)
- when IO, StringIO
- IOPatch.new(strip, :p1)
when String
- IOPatch.new(StringIO.new(strip), :p1)
+ StringPatch.new(:p1, strip)
when Symbol
- case io
+ case src
when :DATA
DATAPatch.new(strip)
- when IO, StringIO
- IOPatch.new(io, strip)
when String
- IOPatch.new(StringIO.new(io), strip)
+ StringPatch.new(strip, src)
else
ExternalPatch.new(strip, &block)
end
@@ -53,31 +48,26 @@ module Patch
end
end
-class IOPatch
+class EmbeddedPatch
attr_writer :owner
attr_reader :strip
+ def initialize(strip)
+ @strip = strip
+ end
+
def external?
false
end
- def initialize(io, strip)
- @io = io
- @strip = strip
+ def contents
+ raise NotImplementedError
end
def apply
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
- # IO and StringIO cannot be marshaled, so remove the reference
- # in case we are indirectly referenced by an exception later.
- @io = nil
- end
-
- def contents
- @io.read
end
def inspect
@@ -85,11 +75,11 @@ class IOPatch
end
end
-class DATAPatch < IOPatch
+class DATAPatch < EmbeddedPatch
attr_accessor :path
def initialize(strip)
- @strip = strip
+ super
@path = nil
end
@@ -105,6 +95,17 @@ class DATAPatch < IOPatch
end
end
+class StringPatch < EmbeddedPatch
+ def initialize(strip, str)
+ super(strip)
+ @str = str
+ end
+
+ def contents
+ @str
+ end
+end
+
class ExternalPatch
attr_reader :resource, :strip
diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb
index fb29ad5a6..e173cb476 100644
--- a/Library/Homebrew/software_spec.rb
+++ b/Library/Homebrew/software_spec.rb
@@ -90,8 +90,8 @@ class SoftwareSpec
dependency_collector.requirements
end
- def patch strip=:p1, io=nil, &block
- patches << Patch.create(strip, io, &block)
+ def patch strip=:p1, src=nil, &block
+ patches << Patch.create(strip, src, &block)
end
def add_legacy_patches(list)
diff --git a/Library/Homebrew/test/test_patch.rb b/Library/Homebrew/test/test_patch.rb
index 4b8cdf53c..a70d581d8 100644
--- a/Library/Homebrew/test/test_patch.rb
+++ b/Library/Homebrew/test/test_patch.rb
@@ -9,28 +9,15 @@ class PatchTests < Homebrew::TestCase
assert_equal :p2, patch.strip
end
- def test_create_io
- patch = Patch.create(:p0, StringIO.new("foo"))
- assert_kind_of IOPatch, patch
- refute_predicate patch, :external?
- assert_equal :p0, patch.strip
- end
-
- def test_create_io_without_strip
- patch = Patch.create(StringIO.new("foo"), nil)
- assert_kind_of IOPatch, patch
- assert_equal :p1, patch.strip
- end
-
def test_create_string
patch = Patch.create(:p0, "foo")
- assert_kind_of IOPatch, patch
+ assert_kind_of StringPatch, patch
assert_equal :p0, patch.strip
end
def test_create_string_without_strip
patch = Patch.create("foo", nil)
- assert_kind_of IOPatch, patch
+ assert_kind_of StringPatch, patch
assert_equal :p1, patch.strip
end