Class: Resource Private
- Includes:
- Downloadable, FileUtils, OnSystem::MacOSAndLinux
- Defined in:
- resource.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.
Resource is the fundamental representation of an external resource. The primary formula download, along with other declared resources, are instances of this class.
Direct Known Subclasses
Defined Under Namespace
Classes: BottleManifest, Formula, Go, Local, Partial, Patch
Instance Attribute Summary collapse
- #checksum ⇒ Object writeonly private
- #download_strategy ⇒ Object private
-
#name ⇒ Object
private
Formula name must be set after the DSL, as we have no access to the formula name before initialization of the formula.
- #owner ⇒ Object private
- #patches ⇒ Object readonly private
- #source_modified_time ⇒ Object readonly private
Attributes included from Downloadable
Instance Method Summary collapse
- #apply_patches ⇒ Object private
- #download_name ⇒ Object private
-
#escaped_name ⇒ Object
private
Removes /s from resource names; this allows Go package names to be used as resource names without confusing software that interacts with #download_name, e.g.
- #fetch(verify_download_integrity: true, timeout: nil, quiet: false) ⇒ Pathname private
- #fetch_patches(skip_downloaded: false) ⇒ Object private
- #files(*files) ⇒ Object private
- #freeze ⇒ Object private
- #initialize(name = nil, &block) ⇒ void constructor private
- #initialize_dup(other) ⇒ void private
-
#livecheck(&block) ⇒ Object
private
Livecheck can be used to check for newer versions of the software.
-
#livecheck_defined? ⇒ Boolean
private
Whether a livecheck specification is defined or not.
-
#livecheckable? ⇒ Boolean
deprecated
private
Deprecated.
Calling #livecheckable? is deprecated, use #livecheck_defined? instead.
- #mirror(val) ⇒ Object private
- #patch(strip = :p1, src = nil, &block) ⇒ Object private
- #prepare_patches ⇒ Object private
- #sha256(val) ⇒ Object private
- #specs ⇒ Object private
-
#stage(target = nil, debug_symbols: false, &block) ⇒ Object
Verifies download and unpacks it.
-
#unpack(target = nil, debug_symbols: false) ⇒ Object
private
If a target is given, unpack there; else unpack to a temp folder.
- #url(val = nil, **specs) ⇒ String? private
- #using ⇒ Object private
- #version(val = nil) ⇒ Version? private
Methods included from OnSystem::MacOSAndLinux
included, #on_arch_conditional, #on_macos, #on_system_conditional
Methods included from Downloadable
#cached_download, #clear_cache, #download_type, #downloaded?, #downloader, #verify_download_integrity
Methods included from Context
current, current=, #debug?, #quiet?, #verbose?, #with_context
Constructor Details
#initialize(name = nil, &block) ⇒ void
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.
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'resource.rb', line 26 def initialize(name = nil, &block) super() # Generally ensure this is synced with `initialize_dup` and `freeze` # (excluding simple objects like integers & booleans, weak refs like `owner` or permafrozen objects) @name = name @source_modified_time = nil @patches = [] @owner = nil @livecheck = Livecheck.new(self) @livecheck_defined = false @insecure = false instance_eval(&block) if block end |
Instance Attribute Details
#checksum=(value) ⇒ Object (writeonly)
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.
18 19 20 |
# File 'resource.rb', line 18 def checksum=(value) @checksum = value end |
#download_strategy ⇒ 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.
19 20 21 |
# File 'resource.rb', line 19 def download_strategy @download_strategy end |
#name ⇒ 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.
Formula name must be set after the DSL, as we have no access to the formula name before initialization of the formula.
23 24 25 |
# File 'resource.rb', line 23 def name @name end |
#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.
17 18 19 |
# File 'resource.rb', line 17 def owner @owner end |
#patches ⇒ Object (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.
17 18 19 |
# File 'resource.rb', line 17 def patches @patches end |
#source_modified_time ⇒ Object (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.
17 18 19 |
# File 'resource.rb', line 17 def source_modified_time @source_modified_time end |
Instance Method Details
#apply_patches ⇒ 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.
100 101 102 103 104 105 |
# File 'resource.rb', line 100 def apply_patches return if patches.empty? ohai "Patching #{name}" patches.each(&:apply) end |
#download_name ⇒ 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.
67 68 69 70 71 72 |
# File 'resource.rb', line 67 def download_name return owner.name if name.nil? return escaped_name if owner.nil? "#{owner.name}--#{escaped_name}" end |
#escaped_name ⇒ 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.
Removes /s from resource names; this allows Go package names
to be used as resource names without confusing software that
interacts with #download_name, e.g. github.com/foo/bar
.
63 64 65 |
# File 'resource.rb', line 63 def escaped_name name.tr("/", "-") end |
#fetch(verify_download_integrity: true, timeout: nil, quiet: false) ⇒ Pathname
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.
142 143 144 145 146 |
# File 'resource.rb', line 142 def fetch(verify_download_integrity: true, timeout: nil, quiet: false) fetch_patches super end |
#fetch_patches(skip_downloaded: false) ⇒ 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.
94 95 96 97 98 |
# File 'resource.rb', line 94 def fetch_patches(skip_downloaded: false) external_patches = patches.select(&:external?) external_patches.reject!(&:downloaded?) if skip_downloaded external_patches.each(&:fetch) end |
#files(*files) ⇒ 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.
130 131 132 |
# File 'resource.rb', line 130 def files(*files) Partial.new(self, files) end |
#freeze ⇒ 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.
48 49 50 51 52 53 |
# File 'resource.rb', line 48 def freeze @name.freeze @patches.freeze @livecheck.freeze super end |
#initialize_dup(other) ⇒ void
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.
This method returns an undefined value.
41 42 43 44 45 46 |
# File 'resource.rb', line 41 def initialize_dup(other) super @name = @name.dup @patches = @patches.dup @livecheck = @livecheck.dup end |
#livecheck(&block) ⇒ 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.
Livecheck can be used to check for newer versions of the software.
This method evaluates the DSL specified in the livecheck
block of the
Resource (if it exists) and sets the instance variables of a Livecheck
object accordingly. This is used by brew livecheck
to check for newer
versions of the software.
Example
livecheck do
url "https://example.com/foo/releases"
regex /foo-(\d+(?:\.\d+)+)\.tar/
end
162 163 164 165 166 167 |
# File 'resource.rb', line 162 def livecheck(&block) return @livecheck unless block @livecheck_defined = true @livecheck.instance_eval(&block) end |
#livecheck_defined? ⇒ 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.
Whether a livecheck specification is defined or not.
It returns true
when a livecheck
block is present in the Resource
and false
otherwise.
174 175 176 |
# File 'resource.rb', line 174 def livecheck_defined? @livecheck_defined == true end |
#livecheckable? ⇒ 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.
Calling #livecheckable? is deprecated, use #livecheck_defined? instead.
Whether a livecheck specification is defined or not. This is a legacy alias
for #livecheck_defined?
.
It returns true
when a livecheck
block is present in the Resource
and false
otherwise.
184 185 186 187 |
# File 'resource.rb', line 184 def livecheckable? odeprecated "`livecheckable?`", "`livecheck_defined?`" @livecheck_defined == true end |
#mirror(val) ⇒ 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.
221 222 223 |
# File 'resource.rb', line 221 def mirror(val) mirrors << val end |
#patch(strip = :p1, src = nil, &block) ⇒ 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.
225 226 227 228 |
# File 'resource.rb', line 225 def patch(strip = :p1, src = nil, &block) p = ::Patch.create(strip, src, &block) patches << p end |
#prepare_patches ⇒ 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.
90 91 92 |
# File 'resource.rb', line 90 def prepare_patches patches.grep(DATAPatch) { |p| p.path = owner.owner.path } end |
#sha256(val) ⇒ 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.
189 190 191 |
# File 'resource.rb', line 189 def sha256(val) @checksum = Checksum.new(val) end |
#specs ⇒ 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.
234 235 236 |
# File 'resource.rb', line 234 def specs @url&.specs || {}.freeze end |
#stage(target = nil, debug_symbols: false, &block) ⇒ Object
Verifies download and unpacks it.
The block may call |resource, staging| staging.retain!
to retain the staging
directory. Subclasses that override stage should implement the tmp
dir using Mktemp so that works with all subtypes.
80 81 82 83 84 85 86 87 88 |
# File 'resource.rb', line 80 def stage(target = nil, debug_symbols: false, &block) raise ArgumentError, "Target directory or block is required" if !target && !block_given? prepare_patches fetch_patches(skip_downloaded: true) fetch unless downloaded? unpack(target, debug_symbols:, &block) end |
#unpack(target = nil, debug_symbols: false) ⇒ 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.
If a target is given, unpack there; else unpack to a temp folder.
If block is given, yield to that block with |stage|
, where stage
is a ResourceStageContext.
A target or a block must be given, but not both.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'resource.rb', line 111 def unpack(target = nil, debug_symbols: false) current_working_directory = Pathname.pwd stage_resource(download_name, debug_symbols:) do |staging| downloader.stage do @source_modified_time = downloader.source_modified_time.freeze apply_patches if block_given? yield ResourceStageContext.new(self, staging) elsif target target = Pathname(target) target = current_working_directory/target if target.relative? target.install Pathname.pwd.children end end end end |
#url(val = nil, **specs) ⇒ String?
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.
194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'resource.rb', line 194 def url(val = nil, **specs) return @url&.to_s if val.nil? specs = specs.dup # Don't allow this to be set. specs.delete(:insecure) specs[:insecure] = true if @insecure @url = URL.new(val, specs) @downloader = nil @download_strategy = @url.download_strategy @url.to_s end |
#using ⇒ 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.
230 231 232 |
# File 'resource.rb', line 230 def using @url&.using end |
#version(val = nil) ⇒ Version?
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.
210 211 212 213 214 215 216 217 218 219 |
# File 'resource.rb', line 210 def version(val = nil) return super() if val.nil? @version = case val when String val.blank? ? Version::NULL : Version.new(val) when Version val end end |