Class: Homebrew::Cmd::FetchCmd Private

Inherits:
AbstractCommand show all
Includes:
Fetch
Defined in:
cmd/fetch.rb,
sorbet/rbi/dsl/homebrew/cmd/fetch_cmd.rbi

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.

Defined Under Namespace

Classes: Args

Constant Summary collapse

FETCH_MAX_TRIES =

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.

5

Instance Method Summary collapse

Methods included from Fetch

#fetch_bottle?

Methods inherited from AbstractCommand

command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?

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_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#argsHomebrew::Cmd::FetchCmd::Args

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.



10
# File 'sorbet/rbi/dsl/homebrew/cmd/fetch_cmd.rbi', line 10

def args; end

#cask_downloads(cask) ⇒ Array<Cask::Download>

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:



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'cmd/fetch.rb', line 176

def cask_downloads(cask)
  ref = cask.reloadable_ref

  if args.all_platforms? && cask.loaded_from_api?
    opoo "Cask #{cask} was loaded from the API; cannot fetch all operating system and " \
         "architecture variants. Set `HOMEBREW_NO_INSTALL_FROM_API=1` to fetch them all."
  end

  # With `--all-platforms`, a cask without `on_system` blocks resolves
  # identically everywhere, so one combination covers the whole matrix.
  cask_combinations = args.os_arch_combinations
  cask_combinations = cask_combinations.first(1) if args.all_platforms? && !cask.on_system_blocks_exist?

  downloads = T.let([], T::Array[Cask::Download])
  enqueued_urls = Set.new

  cask_combinations.each do |os, arch|
    SimulateSystem.with(os:, arch:) do
      loaded_cask = begin
        Cask::CaskLoader.load(ref)
      rescue Cask::CaskInvalidError, Cask::CaskUnreadableError
        raise unless cask.on_system_blocks_exist?
      end
      if loaded_cask.nil? || loaded_cask.depends_on.arch&.none? { |dep_arch| dep_arch[:type] == arch }
        opoo "Cask #{cask} is not supported on os #{os} and arch #{arch}"
        next
      end

      languages = (loaded_cask.languages if args.all_platforms?)
      languages = [nil] if languages.blank?

      languages.each do |language|
        localized_cask = loaded_cask
        if language
          # Reload per language: `Cask::Download` reads `sha256`/`url`
          # lazily, so each download needs its own cask instance.
          localized_cask = Cask::CaskLoader.load(ref)
          localized_cask.config = localized_cask.config.merge(
            Cask::Config.new(explicit: { languages: [language] }),
          )
        end

        if localized_cask.url.nil? || localized_cask.sha256.nil?
          opoo "Cask #{cask} is not supported on os #{os} and arch #{arch}"
          next
        end

        next unless enqueued_urls.add?(localized_cask.url.to_s)

        downloads << Cask::Download.new(
          localized_cask,
          require_sha: Homebrew::EnvConfig.cask_opts_require_sha?,
        )
      end
    end
  end

  downloads
end

#runvoid

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.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'cmd/fetch.rb', line 79

def run
  Formulary.enable_factory_cache!

  if enqueue_api_formula_bottles? || enqueue_api_cask_downloads?
    download_queue.fetch
    return
  end

  bucket = if args.deps?
    args.named.to_formulae_and_casks.flat_map do |formula_or_cask|
      case formula_or_cask
      when Formula
        formula = formula_or_cask
        [formula, *formula.recursive_dependencies.map(&:to_formula)]
      else
        formula_or_cask
      end
    end
  else
    args.named.to_formulae_and_casks
  end.uniq

  os_arch_combinations = args.os_arch_combinations

  puts "Fetching: #{bucket * ", "}" if bucket.size > 1
  bucket.each do |formula_or_cask|
    case formula_or_cask
    when Formula
      formula = formula_or_cask
      ref = formula.reloadable_ref

      os_arch_combinations.each do |os, arch|
        SimulateSystem.with(os:, arch:) do
          formula = Formulary.factory(ref, args.HEAD? ? :head : :stable)

          formula.print_tap_action verb: "Fetching"

          fetched_bottle = false
          if fetch_bottle?(
            formula,
            force_bottle:               args.force_bottle?,
            bottle_tag:                 args.bottle_tag&.to_sym,
            build_from_source_formulae: args.build_from_source_formulae,
            os:                         args.os&.to_sym,
            arch:                       args.arch&.to_sym,
          )
            begin
              formula.clear_cache if args.force?

              bottle_tag = Utils::Bottles::Tag.from_arg(args.bottle_tag&.to_sym, os:, arch:)

              bottle = formula.bottle_for_tag(bottle_tag)

              if bottle.nil?
                opoo "Bottle for tag #{bottle_tag.to_sym.inspect} is unavailable."
                next
              end

              if (manifest_resource = bottle.github_packages_manifest_resource)
                download_queue.enqueue(manifest_resource)
              end
              download_queue.enqueue(bottle)
            rescue Interrupt
              raise
            rescue => e
              raise if Homebrew::EnvConfig.developer?

              fetched_bottle = false
              onoe e.message
              opoo "Bottle fetch failed, fetching the source instead."
            else
              fetched_bottle = true
            end
          end

          next if fetched_bottle

          if (resource = formula.resource)
            download_queue.enqueue(resource)
          end

          formula.enqueue_resources_and_patches(download_queue:)
        end
      end
    when Cask::Cask
      cask_downloads(formula_or_cask).each { |download| download_queue.enqueue(download) }
    else
      odie "Invalid formula or cask: #{formula_or_cask}"
    end
  end

  download_queue.fetch
ensure
  download_queue.shutdown
end