Class: Resource Private

Inherits:
Object show all
Includes:
Downloadable, FileUtils, OnSystem::MacOSAndLinux, Utils::Output::Mixin
Defined in:
resource.rb,
sorbet/rbi/dsl/resource.rbi

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

BottleManifest, Formula, Local, Patch

Defined Under Namespace

Classes: BottleManifest, Formula, Local, Partial, Patch

Constant Summary collapse

Owner =

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

T.type_alias { T.any(Cask::Cask, ::Formula, Resource, SoftwareSpec, Homebrew::FormulaCreator) }

Instance Attribute Summary collapse

Attributes included from Downloadable

#checksum, #mirrors, #phase

Instance Method Summary collapse

Methods included from Utils::Output::Mixin

#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning

Methods included from OnSystem::MacOSAndLinux

included

Methods included from Downloadable

#cached_download, #clear_cache, #download_queue_message, #download_queue_name, #downloaded!, #downloaded?, #downloaded_and_valid?, #downloader, #downloading!, #extracting!, #fetched_size, #stage_from_download_queue, #stage_from_download_queue?, #staged_path_from_download_queue, #total_size, verification_cache, #verified!, #verify_download_integrity, #verifying!

Methods included from Context

current, current=, #debug?, #deferred_environment_expansion?, #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.

Parameters:

  • name (String, nil) (defaults to: nil)
  • block (T.proc.bind(Resource).void, nil)


48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'resource.rb', line 48

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 = T.let(nil, T.nilable(Time))
  @patches = T.let([], T::Array[T.any(EmbeddedPatch, ExternalPatch)])
  @owner = T.let(nil, T.nilable(Owner))
  @livecheck = T.let(Livecheck.new(self), Livecheck)
  @livecheck_defined = T.let(false, T::Boolean)
  @insecure = T.let(false, T::Boolean)
  instance_eval(&block) if block
end

Instance Attribute Details

#checksum=(value) ⇒ Checksum? (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.

Returns:



32
33
34
# File 'resource.rb', line 32

def checksum=(value)
  @checksum = value
end

#download_strategyT::Class[AbstractDownloadStrategy]

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:



35
36
37
# File 'resource.rb', line 35

def download_strategy
  @download_strategy || super
end

#nameString?

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.

Returns:



45
46
47
# File 'resource.rb', line 45

def name
  @name
end

#ownerOwner?

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:



29
30
31
# File 'resource.rb', line 29

def owner
  @owner
end

#patchesArray<EmbeddedPatch, ExternalPatch> (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.



26
27
28
# File 'resource.rb', line 26

def patches
  @patches
end

#source_modified_timeTime? (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.

Returns:



23
24
25
# File 'resource.rb', line 23

def source_modified_time
  @source_modified_time
end

Instance Method Details

#apply_patchesvoid

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.



135
136
137
138
139
140
# File 'resource.rb', line 135

def apply_patches
  return if patches.empty?

  ohai "Patching #{name}"
  patches.each(&:apply)
end

#download_queue_typeString

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:



85
# File 'resource.rb', line 85

def download_queue_type = "Resource"

#fetch(verify_download_integrity: true, timeout: nil, quiet: false, skip_patches: 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.

Parameters:

  • verify_download_integrity (Boolean) (defaults to: true)
  • timeout (Integer, Float, nil) (defaults to: nil)
  • quiet (Boolean) (defaults to: false)
  • skip_patches (Boolean) (defaults to: false)

Returns:



206
207
208
209
210
# File 'resource.rb', line 206

def fetch(verify_download_integrity: true, timeout: nil, quiet: false, skip_patches: false)
  fetch_patches unless skip_patches

  super(verify_download_integrity:, timeout:, quiet:)
end

#fetch_patches(skip_downloaded: false) ⇒ 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.

Parameters:

  • skip_downloaded (Boolean) (defaults to: false)


128
129
130
131
132
# File 'resource.rb', line 128

def fetch_patches(skip_downloaded: false)
  external_patches = patches.grep(ExternalPatch)
  external_patches.reject!(&:downloaded?) if skip_downloaded
  external_patches.each(&:fetch)
end

#files(*files) ⇒ Partial

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.

Parameters:

  • files (T.untyped)

Returns:



193
194
195
# File 'resource.rb', line 193

def files(*files)
  Partial.new(self, files)
end

#freezeT.self_type

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:

  • (T.self_type)


71
72
73
74
75
76
# File 'resource.rb', line 71

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.

Parameters:



63
64
65
66
67
68
# File 'resource.rb', line 63

def initialize_dup(other)
  super
  @name = @name.dup
  @patches = @patches.dup
  @livecheck = @livecheck.dup
end

#livecheck(&block) ⇒ T.untyped

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

Parameters:

Returns:

  • (T.untyped)


227
228
229
230
231
232
# File 'resource.rb', line 227

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.

Returns:

  • (Boolean)


239
240
241
# File 'resource.rb', line 239

def livecheck_defined?
  @livecheck_defined == true
end

#mirror(val) ⇒ Array<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.

Parameters:

Returns:



277
278
279
# File 'resource.rb', line 277

def mirror(val)
  mirrors << val
end

#on_arch_conditional(arm: nil, intel: nil) ⇒ T.type_parameter(:U)?

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.

Parameters:

  • arm (T.type_parameter(:U), nil) (defaults to: nil)
  • intel (T.type_parameter(:U), nil) (defaults to: nil)

Returns:

  • (T.type_parameter(:U), nil)


16
# File 'sorbet/rbi/dsl/resource.rbi', line 16

def on_arch_conditional(arm: nil, intel: nil); end

#on_arm(&block) ⇒ T.type_parameter(:U)?

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.

Parameters:

  • block (T.proc.returns(T.type_parameter(:U)))

Returns:

  • (T.type_parameter(:U), nil)


24
# File 'sorbet/rbi/dsl/resource.rbi', line 24

def on_arm(&block); end

#on_big_sur(or_condition = nil, &block) ⇒ T.type_parameter(:U)?

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.

Parameters:

  • or_condition (Symbol, nil) (defaults to: nil)
  • block (T.proc.returns(T.type_parameter(:U)))

Returns:

  • (T.type_parameter(:U), nil)


33
# File 'sorbet/rbi/dsl/resource.rbi', line 33

def on_big_sur(or_condition = nil, &block); end

#on_golden_gate(or_condition = nil, &block) ⇒ T.type_parameter(:U)?

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.

Parameters:

  • or_condition (Symbol, nil) (defaults to: nil)
  • block (T.proc.returns(T.type_parameter(:U)))

Returns:

  • (T.type_parameter(:U), nil)


42
# File 'sorbet/rbi/dsl/resource.rbi', line 42

def on_golden_gate(or_condition = nil, &block); end

#on_intel(&block) ⇒ T.type_parameter(:U)?

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.

Parameters:

  • block (T.proc.returns(T.type_parameter(:U)))

Returns:

  • (T.type_parameter(:U), nil)


50
# File 'sorbet/rbi/dsl/resource.rbi', line 50

def on_intel(&block); end

#on_linux(&block) ⇒ T.type_parameter(:U)?

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.

Parameters:

  • block (T.proc.returns(T.type_parameter(:U)))

Returns:

  • (T.type_parameter(:U), nil)


58
# File 'sorbet/rbi/dsl/resource.rbi', line 58

def on_linux(&block); end

#on_macos(&block) ⇒ T.type_parameter(:U)?

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.

Parameters:

  • block (T.proc.returns(T.type_parameter(:U)))

Returns:

  • (T.type_parameter(:U), nil)


66
# File 'sorbet/rbi/dsl/resource.rbi', line 66

def on_macos(&block); end

#on_monterey(or_condition = nil, &block) ⇒ T.type_parameter(:U)?

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.

Parameters:

  • or_condition (Symbol, nil) (defaults to: nil)
  • block (T.proc.returns(T.type_parameter(:U)))

Returns:

  • (T.type_parameter(:U), nil)


75
# File 'sorbet/rbi/dsl/resource.rbi', line 75

def on_monterey(or_condition = nil, &block); end

#on_sequoia(or_condition = nil, &block) ⇒ T.type_parameter(:U)?

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.

Parameters:

  • or_condition (Symbol, nil) (defaults to: nil)
  • block (T.proc.returns(T.type_parameter(:U)))

Returns:

  • (T.type_parameter(:U), nil)


84
# File 'sorbet/rbi/dsl/resource.rbi', line 84

def on_sequoia(or_condition = nil, &block); end

#on_sonoma(or_condition = nil, &block) ⇒ T.type_parameter(:U)?

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.

Parameters:

  • or_condition (Symbol, nil) (defaults to: nil)
  • block (T.proc.returns(T.type_parameter(:U)))

Returns:

  • (T.type_parameter(:U), nil)


93
# File 'sorbet/rbi/dsl/resource.rbi', line 93

def on_sonoma(or_condition = nil, &block); end

#on_system(linux, macos:, &block) ⇒ T.type_parameter(:U)?

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.

Parameters:

  • linux (Symbol)
  • macos (Symbol)
  • block (T.proc.returns(T.type_parameter(:U)))

Returns:

  • (T.type_parameter(:U), nil)


103
# File 'sorbet/rbi/dsl/resource.rbi', line 103

def on_system(linux, macos:, &block); end

#on_system_conditional(macos: nil, linux: nil) ⇒ T.type_parameter(:U)?

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.

Parameters:

  • macos (T.type_parameter(:U), nil) (defaults to: nil)
  • linux (T.type_parameter(:U), nil) (defaults to: nil)

Returns:

  • (T.type_parameter(:U), nil)


112
# File 'sorbet/rbi/dsl/resource.rbi', line 112

def on_system_conditional(macos: nil, linux: nil); end

#on_tahoe(or_condition = nil, &block) ⇒ T.type_parameter(:U)?

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.

Parameters:

  • or_condition (Symbol, nil) (defaults to: nil)
  • block (T.proc.returns(T.type_parameter(:U)))

Returns:

  • (T.type_parameter(:U), nil)


121
# File 'sorbet/rbi/dsl/resource.rbi', line 121

def on_tahoe(or_condition = nil, &block); end

#on_ventura(or_condition = nil, &block) ⇒ T.type_parameter(:U)?

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.

Parameters:

  • or_condition (Symbol, nil) (defaults to: nil)
  • block (T.proc.returns(T.type_parameter(:U)))

Returns:

  • (T.type_parameter(:U), nil)


130
# File 'sorbet/rbi/dsl/resource.rbi', line 130

def on_ventura(or_condition = nil, &block); end

#patch(strip = :p1, src = nil, &block) ⇒ Array<EmbeddedPatch, 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.

Parameters:

Returns:



288
289
290
291
# File 'resource.rb', line 288

def patch(strip = :p1, src = nil, &block)
  p = ::Patch.create(strip, src, &block)
  patches << p
end

#prepare_patchesvoid

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.



123
124
125
# File 'resource.rb', line 123

def prepare_patches
  patches.grep(DATAPatch) { |p| p.path = T.cast(T.cast(owner, SoftwareSpec).owner, ::Formula).path }
end

#sha256(val) ⇒ Checksum

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.

Parameters:

Returns:



244
245
246
# File 'resource.rb', line 244

def sha256(val)
  @checksum = Checksum.new(val)
end

#specsHash{Symbol => T.untyped}

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:



299
300
301
# File 'resource.rb', line 299

def specs
  @url&.specs || {}.freeze
end

#stage(target = nil, debug_symbols: false, staging_path: nil, staged: false, &block) ⇒ void

This method returns an undefined value.

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.

Parameters:

  • target (String, Pathname, nil) (defaults to: nil)
  • debug_symbols (Boolean) (defaults to: false)
  • staging_path (Pathname, nil) (defaults to: nil)
  • staged (Boolean) (defaults to: false)
  • block (T.proc.params(arg0: ResourceStageContext).void, nil)

Raises:

  • (ArgumentError)


102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'resource.rb', line 102

def stage(target = nil, debug_symbols: false, staging_path: nil, staged: false, &block)
  raise ArgumentError, "Target directory or block is required" if !target && !block_given?

  prepare_patches
  fetch_patches(skip_downloaded: true)
  begin
    if !downloaded?
      fetch
    elsif !staged && checksum.present?
      verify_download_integrity(cached_download)
    end
  rescue ChecksumMismatchError
    # Remove the known-bad download so the next attempt fetches it again.
    clear_cache
    raise
  end

  unpack(target, debug_symbols:, staging_path:, staged:, &block)
end

#unpack(target = nil, debug_symbols: false, staging_path: nil, staged: false, &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.

This method returns an undefined value.

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. With staging_path, unpack into that directory rather than a fresh temporary one and, with staged too, reuse its already unpacked and patched contents.

Parameters:

  • target (String, Pathname, nil) (defaults to: nil)
  • debug_symbols (Boolean) (defaults to: false)
  • staging_path (Pathname, nil) (defaults to: nil)
  • staged (Boolean) (defaults to: false)
  • block (T.proc.params(arg0: ResourceStageContext).void, nil)


158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'resource.rb', line 158

def unpack(target = nil, debug_symbols: false, staging_path: nil, staged: false, &block)
  current_working_directory = Pathname.pwd
  stage_resource(download_name, debug_symbols:, staging_path:) do |staging|
    # A formula's `fetch` adds files to the shared staging directory, so
    # record the unpacked source's modification time for the build phase.
    source_modified_time_path = (staging_path/".source_modified_time" if staging_path)
    stage_unpacked = proc do
      source_modified_time = if staged && source_modified_time_path&.exist?
        Time.at(source_modified_time_path.read.to_i)
      else
        downloader.source_modified_time
      end
      source_modified_time_path&.write(source_modified_time.to_i.to_s) unless staged
      @source_modified_time = source_modified_time.freeze
      apply_patches unless staged
      if block
        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

    if staged
      downloader.chdir(&stage_unpacked)
    else
      downloader.stage(&stage_unpacked)
    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.

Parameters:

  • val (String, nil) (defaults to: nil)
  • specs (T.anything)

Returns:



249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'resource.rb', line 249

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

#usingT::Class[AbstractDownloadStrategy], ...

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:



294
295
296
# File 'resource.rb', line 294

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.

Parameters:

Returns:



265
266
267
268
269
270
271
272
273
274
# File 'resource.rb', line 265

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