diff options
| author | Jack Nagel | 2014-07-29 16:06:06 -0500 |
|---|---|---|
| committer | Jack Nagel | 2014-07-29 16:22:06 -0500 |
| commit | f3cb1d2b0614e3dcfe2e2911e65bfd24511a2fc2 (patch) | |
| tree | 105313ca7fe29c085cfcb782814af69b5f2fc896 /Library/Homebrew | |
| parent | 1d039ebf2bd9e3fb7b1f753f616fe0a5f8bcba3b (diff) | |
| download | homebrew-f3cb1d2b0614e3dcfe2e2911e65bfd24511a2fc2.tar.bz2 | |
Decouple DATA patches from the executing script
Diffstat (limited to 'Library/Homebrew')
| -rw-r--r-- | Library/Homebrew/build.rb | 7 | ||||
| -rw-r--r-- | Library/Homebrew/formula.rb | 4 | ||||
| -rw-r--r-- | Library/Homebrew/formula_installer.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/patch.rb | 45 | ||||
| -rw-r--r-- | Library/Homebrew/test/test_patch.rb | 4 | ||||
| -rw-r--r-- | Library/Homebrew/test/test_patching.rb | 24 |
6 files changed, 65 insertions, 21 deletions
diff --git a/Library/Homebrew/build.rb b/Library/Homebrew/build.rb index 71fb519d2..4fd6c7929 100644 --- a/Library/Homebrew/build.rb +++ b/Library/Homebrew/build.rb @@ -1,14 +1,9 @@ # This script is loaded by formula_installer as a separate instance. -# Rationale: Formula can use __END__, Formula can change ENV # Thrown exceptions are propogated back to the parent process over a pipe STD_TRAP = trap("INT") { exit! 130 } # no backtrace thanks -at_exit do - # the whole of everything must be run in at_exit because the formula has to - # be the run script as __END__ must work for *that* formula. - main -end +at_exit { main } require 'global' require 'cxxstdlib' diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index ecf5ec6ca..70f9af310 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -212,6 +212,8 @@ class Formula # any e.g. configure options for this package def options; [] end + # Deprecated + DATA = :DATA def patches; {} end # rarely, you don't want your library symlinked into the main prefix @@ -577,6 +579,8 @@ class Formula active_spec.add_legacy_patches(patches) return if patchlist.empty? + active_spec.patches.grep(DATAPatch).each { |p| p.path = path } + active_spec.patches.select(&:external?).each do |patch| patch.verify_download_integrity(patch.fetch) end diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 4e185d717..f21f15439 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -483,8 +483,6 @@ class FormulaInstaller # 1. formulae can modify ENV, so we must ensure that each # installation has a pristine ENV when it starts, forking now is # the easiest way to do this - # 2. formulae have access to __END__ the only way to allow this is - # to make the formula script the executed script read, write = IO.pipe # I'm guessing this is not a good way to do this, but I'm no UNIX guru ENV['HOMEBREW_ERROR_PIPE'] = write.to_i.to_s 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 diff --git a/Library/Homebrew/test/test_patch.rb b/Library/Homebrew/test/test_patch.rb index bc0e522d3..4b8cdf53c 100644 --- a/Library/Homebrew/test/test_patch.rb +++ b/Library/Homebrew/test/test_patch.rb @@ -36,13 +36,13 @@ class PatchTests < Homebrew::TestCase def test_create_DATA patch = Patch.create(:p0, :DATA) - assert_kind_of IOPatch, patch + assert_kind_of DATAPatch, patch assert_equal :p0, patch.strip end def test_create_DATA_without_strip patch = Patch.create(:DATA, nil) - assert_kind_of IOPatch, patch + assert_kind_of DATAPatch, patch assert_equal :p1, patch.strip end diff --git a/Library/Homebrew/test/test_patching.rb b/Library/Homebrew/test/test_patching.rb index 8fe8489f2..76ed37483 100644 --- a/Library/Homebrew/test/test_patching.rb +++ b/Library/Homebrew/test/test_patching.rb @@ -8,7 +8,7 @@ class PatchingTests < Homebrew::TestCase PATCH_A_CONTENTS = File.read "#{TEST_DIRECTORY}/patches/noop-a.diff" PATCH_B_CONTENTS = File.read "#{TEST_DIRECTORY}/patches/noop-b.diff" - def formula(&block) + def formula(*args, &block) super do url "file://#{TEST_DIRECTORY}/tarballs/testball-0.1.tbz" sha1 "482e737739d946b7c8cbaf127d9ee9c148b999f5" @@ -138,4 +138,26 @@ class PatchingTests < Homebrew::TestCase end.brew { assert_patched 'libexec/noop' } end end + + def test_patch_DATA_constant + shutup do + formula("test", Pathname.new(__FILE__).expand_path) do + def patches + Formula::DATA + end + end.brew { assert_patched "libexec/noop" } + end + end end + +__END__ +diff --git a/libexec/NOOP b/libexec/NOOP +index bfdda4c..e08d8f4 100755 +--- a/libexec/NOOP ++++ b/libexec/NOOP +@@ -1,2 +1,2 @@ + #!/bin/bash +-echo NOOP +\ No newline at end of file ++echo ABCD +\ No newline at end of file |
