Class: Resource Private
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: Go, Partial, PatchResource
Instance Attribute Summary collapse
-
#checksum ⇒ Object
private
-
#download_strategy ⇒ Object
private
-
#mirrors ⇒ Object
readonly
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
-
#specs ⇒ Object
readonly
private
-
#using ⇒ Object
readonly
private
-
#version(val = nil) ⇒ Object
private
Instance Method Summary collapse
-
#apply_patches ⇒ Object
private
-
#cached_download ⇒ Object
private
-
#clear_cache ⇒ Object
private
-
#download_name ⇒ Object
private
-
#downloaded? ⇒ Boolean
private
-
#downloader ⇒ 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) ⇒ Object
private
-
#fetch_patches(skip_downloaded: false) ⇒ Object
private
-
#files(*files) ⇒ Object
private
-
#initialize(name = nil, &block) ⇒ Resource
constructor
private
A new instance of Resource.
-
#mirror(val) ⇒ Object
private
-
#patch(strip = :p1, src = nil, &block) ⇒ Object
private
-
#prepare_patches ⇒ Object
private
-
#sha256(val) ⇒ Object
private
-
#stage(target = nil, &block) ⇒ Object
Verifies download and unpacks it.
-
#unpack(target = nil) ⇒ Object
private
If a target is given, unpack there; else unpack to a temp folder.
-
#url(val = nil, **specs) ⇒ Object
private
-
#verify_download_integrity(fn) ⇒ Object
private
Methods included from OnOS
Methods included from Context
current, current=, #debug?, #quiet?, #verbose?, #with_context
Constructor Details
#initialize(name = nil, &block) ⇒ Resource
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 Resource.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'resource.rb', line 30 def initialize(name = nil, &block) @name = name @url = nil @version = nil @mirrors = [] @specs = {} @checksum = nil @using = nil @patches = [] instance_eval(&block) if block end |
Instance Attribute Details
#checksum ⇒ 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.
24 25 26 |
# File 'resource.rb', line 24 def checksum @checksum 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.
24 25 26 |
# File 'resource.rb', line 24 def download_strategy @download_strategy end |
#mirrors ⇒ 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.
22 23 24 |
# File 'resource.rb', line 22 def mirrors @mirrors 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.
28 29 30 |
# File 'resource.rb', line 28 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.
22 23 24 |
# File 'resource.rb', line 22 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.
22 23 24 |
# File 'resource.rb', line 22 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.
22 23 24 |
# File 'resource.rb', line 22 def source_modified_time @source_modified_time end |
#specs ⇒ 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.
22 23 24 |
# File 'resource.rb', line 22 def specs @specs end |
#using ⇒ 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.
22 23 24 |
# File 'resource.rb', line 22 def using @using end |
#version(val = nil) ⇒ 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 192 193 194 |
# File 'resource.rb', line 189 def version(val = nil) @version ||= begin version = detect_version(val) version.null? ? nil : version end 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.
109 110 111 112 113 114 |
# File 'resource.rb', line 109 def apply_patches return if patches.empty? ohai "Patching #{name}" patches.each(&:apply) end |
#cached_download ⇒ 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.
75 76 77 |
# File 'resource.rb', line 75 def cached_download downloader.cached_location end |
#clear_cache ⇒ 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.
79 80 81 |
# File 'resource.rb', line 79 def clear_cache downloader.clear_cache 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.
64 65 66 67 68 69 |
# File 'resource.rb', line 64 def download_name return owner.name if name.nil? return escaped_name if owner.nil? "#{owner.name}--#{escaped_name}" end |
#downloaded? ⇒ 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.
71 72 73 |
# File 'resource.rb', line 71 def downloaded? cached_download.exist? end |
#downloader ⇒ 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.
52 53 54 55 |
# File 'resource.rb', line 52 def downloader @downloader ||= download_strategy.new(url, download_name, version, mirrors: mirrors.dup, **specs) 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
.
60 61 62 |
# File 'resource.rb', line 60 def escaped_name name.tr("/", "-") end |
#fetch(verify_download_integrity: true) ⇒ 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.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'resource.rb', line 141 def fetch(verify_download_integrity: true) HOMEBREW_CACHE.mkpath fetch_patches begin downloader.fetch rescue ErrorDuringExecution, CurlDownloadStrategyError => e raise DownloadError.new(self, e) end download = cached_download verify_download_integrity(download) if verify_download_integrity download 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.
103 104 105 106 107 |
# File 'resource.rb', line 103 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.
137 138 139 |
# File 'resource.rb', line 137 def files(*files) Partial.new(self, files) 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.
196 197 198 |
# File 'resource.rb', line 196 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.
200 201 202 203 |
# File 'resource.rb', line 200 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.
99 100 101 |
# File 'resource.rb', line 99 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.
171 172 173 |
# File 'resource.rb', line 171 def sha256(val) @checksum = Checksum.new(val) end |
#stage(target = nil, &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.
89 90 91 92 93 94 95 96 97 |
# File 'resource.rb', line 89 def stage(target = nil, &block) raise ArgumentError, "target directory or block is required" if !target && block.blank? prepare_patches fetch_patches(skip_downloaded: true) fetch unless downloaded? unpack(target, &block) end |
#unpack(target = nil) ⇒ 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.
120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'resource.rb', line 120 def unpack(target = nil) mktemp(download_name) do |staging| downloader.stage do @source_modified_time = downloader.source_modified_time apply_patches if block_given? yield ResourceStageContext.new(self, staging) elsif target target = Pathname(target) target.install Pathname.pwd.children end end end end |
#url(val = nil, **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.
175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'resource.rb', line 175 def url(val = nil, **specs) return @url if val.nil? specs = specs.dup # Don't allow this to be set. specs.delete(:insecure) @url = val @using = specs.delete(:using) @download_strategy = DownloadStrategyDetector.detect(url, using) @specs.merge!(specs) @downloader = nil end |
#verify_download_integrity(fn) ⇒ 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.
157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'resource.rb', line 157 def verify_download_integrity(fn) if fn.file? ohai "Verifying checksum for '#{fn.basename}'" if verbose? fn.verify_checksum(checksum) end rescue ChecksumMissingError opoo <<~EOS Cannot verify integrity of '#{fn.basename}'. No checksum was provided for this resource. For your reference, the checksum is: sha256 "#{fn.sha256}" EOS end |