Class: ExternalPatch Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
Library/Homebrew/patch.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A string containing a patch.

Direct Known Subclasses

LegacyPatch

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(strip, &block) ⇒ ExternalPatch

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ExternalPatch.


138
139
140
141
# File 'Library/Homebrew/patch.rb', line 138

def initialize(strip, &block)
  @strip    = strip
  @resource = Resource::PatchResource.new(&block)
end

Instance Attribute Details

#resourceObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


132
133
134
# File 'Library/Homebrew/patch.rb', line 132

def resource
  @resource
end

#stripObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


132
133
134
# File 'Library/Homebrew/patch.rb', line 132

def strip
  @strip
end

Instance Method Details

#applyObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'Library/Homebrew/patch.rb', line 152

def apply
  base_dir = Pathname.pwd
  resource.unpack do
    patch_dir = Pathname.pwd
    if patch_files.empty?
      children = patch_dir.children
      if children.length != 1 || !children.first.file?
        raise MissingApplyError, <<~EOS
          There should be exactly one patch file in the staging directory unless
          the "apply" method was used one or more times in the patch-do block.
        EOS
      end

      patch_files << children.first.basename
    end
    dir = base_dir
    dir /= resource.directory if resource.directory.present?
    dir.cd do
      patch_files.each do |patch_file|
        ohai "Applying #{patch_file}"
        patch_file = patch_dir/patch_file
        safe_system "patch", "-g", "0", "-f", "-#{strip}", "-i", patch_file
      end
    end
  end
rescue ErrorDuringExecution => e
  f = resource.owner.owner
  cmd, *args = e.cmd
  raise BuildError.new(f, cmd, args, ENV.to_hash)
end

#external?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

143
144
145
# File 'Library/Homebrew/patch.rb', line 143

def external?
  true
end

#inspectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


183
184
185
# File 'Library/Homebrew/patch.rb', line 183

def inspect
  "#<#{self.class.name}: #{strip.inspect} #{url.inspect}>"
end

#owner=(owner) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


147
148
149
150
# File 'Library/Homebrew/patch.rb', line 147

def owner=(owner)
  resource.owner   = owner
  resource.version = resource.checksum || ERB::Util.url_encode(resource.url)
end