Class: ExternalPatch Private

Inherits:
Object show all
Extended by:
Forwardable
Defined in:
patch.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

A string containing a patch.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(strip, &block) ⇒ ExternalPatch

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns a new instance of ExternalPatch.



107
108
109
110
# File 'patch.rb', line 107

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. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



101
102
103
# File 'patch.rb', line 101

def resource
  @resource
end

#stripObject (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



101
102
103
# File 'patch.rb', line 101

def strip
  @strip
end

Instance Method Details

#applyObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'patch.rb', line 122

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.fetch(0).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.fetch(0).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. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


113
114
115
# File 'patch.rb', line 113

def external?
  true
end

#owner=(owner) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



117
118
119
120
# File 'patch.rb', line 117

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