Class: Homebrew::Cmd::UpgradeCmd Private

Inherits:
AbstractCommand show all
Defined in:
cmd/upgrade.rb,
sorbet/rbi/dsl/homebrew/cmd/upgrade_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, FinalUpgradeSummary, FormulaeUpgradeContext

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, dev_cmd?, 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

#initialize(argv = ARGV.freeze) ⇒ 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:



160
161
162
163
# File 'cmd/upgrade.rb', line 160

def initialize(argv = ARGV.freeze)
  super
  @ask_prompt_required = T.let(false, T::Boolean)
end

Instance Method Details

#argsHomebrew::Cmd::UpgradeCmd::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/upgrade_cmd.rbi', line 10

def args; end

#final_upgrade_summaryFinalUpgradeSummary

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:



489
490
491
492
# File 'cmd/upgrade.rb', line 489

def final_upgrade_summary
  @final_upgrade_summary ||= T.let(FinalUpgradeSummary.new, T.nilable(FinalUpgradeSummary))
  @final_upgrade_summary
end

#formula_upgrade_descriptions(formulae, include_sizes: false) ⇒ 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:

  • formulae (Array<Formula>)
  • include_sizes (Boolean) (defaults to: false)

Returns:



583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
# File 'cmd/upgrade.rb', line 583

def formula_upgrade_descriptions(formulae, include_sizes: false)
  formulae.map do |formula|
    if formula.optlinked?
      old_keg = Keg.new(formula.opt_prefix)
      old_version = old_keg.version
      new_version = formula_upgrade_display_version(formula, old_version)
      if include_sizes
        "#{formula.full_specified_name} #{old_version} -> " \
          "#{new_version}#{formula_upgrade_size(formula)}"
      else
        "#{formula.full_specified_name} #{old_version} -> #{new_version}"
      end
    elsif include_sizes
      "#{formula.full_specified_name} #{formula.pkg_version}#{formula_upgrade_size(formula)}"
    else
      "#{formula.full_specified_name} #{formula.pkg_version}"
    end
  end
end

#formulae_upgrade_context(formulae, show_upgrade_summary: true, dry_run: args.dry_run?) ⇒ FormulaeUpgradeContext?

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:

  • formulae (Array<Formula>)
  • show_upgrade_summary (Boolean) (defaults to: true)
  • dry_run (Boolean) (defaults to: args.dry_run?)

Returns:



343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
# File 'cmd/upgrade.rb', line 343

def formulae_upgrade_context(formulae, show_upgrade_summary: true, dry_run: args.dry_run?)
  if args.build_from_source?
    unless DevelopmentTools.installed?
      raise BuildFlagsError.new(["--build-from-source"], bottled: formulae.all?(&:bottled?))
    end

    unless Homebrew::EnvConfig.developer?
      opoo "building from source is not supported!"
      puts "You're on your own. Failures are expected so don't create any issues, please!"
    end
  end

  quiet = args.quiet? || (dry_run && !args.dry_run?)
  not_outdated = T.let([], T::Array[Formula])
  if formulae.blank?
    outdated = Formula.installed.select do |f|
      formula_outdated?(f)
    end
  elsif minimum_version.present?
    outdated, not_outdated = formulae.partition do |f|
      f.outdated?(fetch_head: args.fetch_HEAD?)
    end
    outdated, minimum_version_skipped = outdated.partition do |f|
      MinimumVersion.formula_outdated_kegs(f, minimum_version, fetch_head: args.fetch_HEAD?).present?
    end

    minimum_version_skipped.each do |f|
      next if quiet

      opoo "Not upgrading #{f.full_specified_name}, the installed version is not below " \
           "the minimum version #{minimum_version}"
    end
  else
    outdated, not_outdated = formulae.partition do |f|
      formula_outdated?(f)
    end
  end

  if formulae.present?
    not_outdated.each do |f|
      latest_keg = f.installed_kegs.max_by(&:scheme_and_version)
      if latest_keg.nil?
        ofail "#{f.full_specified_name} not installed"
      else
        opoo "#{f.full_specified_name} #{latest_keg.version} already installed" unless quiet
      end
    end
  end

  return if outdated.blank?

  pinned = outdated.select(&:pinned?)
  outdated -= pinned
  formulae_to_install = outdated.map do |f|
    f_latest = f.latest_formula
    if f_latest.latest_version_installed?
      f
    else
      f_latest
    end
  end

  if formulae_to_install.empty?
    oh1 "No packages to upgrade" if show_upgrade_summary
  elsif show_upgrade_summary
    verb = dry_run ? "Would upgrade" : "Upgrading"
    oh1 "#{verb} #{formulae_to_install.count} outdated #{Utils.pluralize("package",
                                                                         formulae_to_install.count)}:"
    puts Upgrade.format_upgrade_summary(formula_upgrade_descriptions(formulae_to_install)).join("\n") if
      args.no_ask?
  end

  Install.perform_preinstall_checks_once

  if formulae_to_install.any? do |formula|
    formula.bottle&.github_packages_manifest_resource&.downloaded_and_valid? == false
  end
    oh1 "Downloading bottle manifests"
  end

  formulae_installer = Upgrade.formula_installers(
    formulae_to_install,
    flags:                      args.flags_only,
    dry_run:,
    force_bottle:               args.force_bottle?,
    build_from_source_formulae: args.build_from_source_formulae,
    interactive:                args.interactive?,
    keep_tmp:                   args.keep_tmp?,
    debug_symbols:              args.debug_symbols?,
    force:                      args.force?,
    overwrite:                  args.overwrite?,
    debug:                      args.debug?,
    quiet:                      args.quiet?,
    verbose:                    args.verbose?,
  )

  if formulae_installer.blank?
    return if formulae_to_install.present?
    return if pinned.blank?
  end

  if pinned.any?
    message = "Not upgrading #{pinned.count} pinned #{Utils.pluralize("package", pinned.count)}:"
    # only fail when pinned formulae are named explicitly
    if formulae.any?
      ofail message
    else
      opoo message
    end
    puts pinned.map { |f| "#{f.full_specified_name} #{f.pkg_version}" } * ", "
  end

  if formulae_installer.blank?
    return FormulaeUpgradeContext.new(
      formulae_to_install:,
      formulae_installer:  formulae_installer,
      dependants:          Homebrew::Upgrade::Dependents.new(upgradeable: [], pinned: [], skipped: []),
      pinned_formulae:     pinned,
    )
  end

  dependants = Upgrade.dependants(
    formulae_to_install,
    flags:                      args.flags_only,
    dry_run:,
    ask:                        !args.no_ask?,
    force_bottle:               args.force_bottle?,
    build_from_source_formulae: args.build_from_source_formulae,
    interactive:                args.interactive?,
    keep_tmp:                   args.keep_tmp?,
    debug_symbols:              args.debug_symbols?,
    force:                      args.force?,
    debug:                      args.debug?,
    quiet:                      args.quiet?,
    verbose:                    args.verbose?,
  )

  FormulaeUpgradeContext.new(
    formulae_to_install:,
    formulae_installer:  formulae_installer,
    dependants:,
    pinned_formulae:     pinned,
  )
end

#prefetch_outdated_casks!(casks, download_queue:, prefetch_names: nil, prefetch_upgrades: nil, prefetch_casks: nil, prefetch_errors: nil, show_downloads_heading: true) ⇒ 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.

Parameters:

Returns:

  • (Boolean)


726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
# File 'cmd/upgrade.rb', line 726

def prefetch_outdated_casks!(casks, download_queue:, prefetch_names: nil,
                             prefetch_upgrades: nil, prefetch_casks: nil, prefetch_errors: nil,
                             show_downloads_heading: true)
  return false if args.formula?

  casks = minimum_version_casks(casks, quiet: true)
  return false if minimum_version.present? && casks.empty?

  outdated_casks = Cask::Upgrade.outdated_casks(
    casks,
    args:,
    force:               args.force?,
    quiet:               true,
    greedy:              args.greedy?,
    greedy_latest:       args.greedy_latest?,
    greedy_auto_updates: args.greedy_auto_updates?,
  )
  return false if outdated_casks.empty?

  manual_installer_casks = outdated_casks.select do |cask|
    cask.artifacts.any? do |artifact|
      artifact.is_a?(Cask::Artifact::Installer) && artifact.manual_install
    end
  end
  outdated_casks -= manual_installer_casks
  return false if outdated_casks.empty?

  require "cask/installer"
  fetchable_cask_installers = []
  outdated_casks.select! do |cask|
    installer = Cask::Installer.new(
      cask,
      binaries:       args.binaries?,
      verbose:        args.verbose?,
      force:          args.force?,
      skip_cask_deps: args.skip_cask_deps?,
      require_sha:    args.require_sha?,
      upgrade:        true,
      download_queue:,
      defer_fetch:    true,
    )
    begin
      installer.check_requirements
    rescue Cask::CaskError => e
      prefetch_errors&.push(e)
      next false
    end

    fetchable_cask_installers << installer
    true
  end
  prefetch_casks&.replace(outdated_casks)
  return prefetch_errors.present? if outdated_casks.empty?

  cask_names = outdated_casks.map(&:full_name)
  Install.enqueue_cask_installers(fetchable_cask_installers, download_queue:)
  prefetch_names&.replace(cask_names)
  prefetch_upgrades&.replace(
    outdated_casks.map { |cask| "#{cask.full_name} #{cask.installed_version} -> #{cask.version}" },
  )
  Install.show_combined_fetch_downloads_heading(cask_names:) if show_downloads_heading

  true
rescue => e
  ofail e
  false
end

#record_formula_upgrade_summary(context, include_sizes: false, formulae_installer: nil, version_changes: nil) ⇒ 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:



502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
# File 'cmd/upgrade.rb', line 502

def record_formula_upgrade_summary(context, include_sizes: false, formulae_installer: nil, version_changes: nil)
  summary = final_upgrade_summary
  formulae_installer ||= context.formulae_installer
  upgrade_formulae = formulae_installer.map(&:formula)
  dependent_formulae = context.dependants.upgradeable
  summary.version_changes.concat(
    version_changes || (formula_upgrade_descriptions(upgrade_formulae, include_sizes:) +
      formula_upgrade_descriptions(dependent_formulae, include_sizes:)),
  )
  summary.pinned_formulae.concat((context.pinned_formulae + context.dependants.pinned).map do |formula|
    "#{formula.full_specified_name} #{formula.pkg_version}"
  end)

  formulae = context.formulae_to_install + context.pinned_formulae +
             context.dependants.upgradeable + context.dependants.pinned
  summary.deprecated.concat(formulae.filter_map do |formula|
    formula.full_specified_name if formula.deprecated?
  end)
  summary.disabled.concat(formulae.filter_map do |formula|
    formula.full_specified_name if formula.disabled?
  end)
  summary.source_build_formulae.concat(formulae_installer.filter_map do |formula_installer|
    formula = formula_installer.formula
    next unless formula.core_formula?
    next if formula_installer.pour_bottle?

    formula.full_specified_name
  end)
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.

Raises:



166
167
168
169
170
171
172
173
174
175
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'cmd/upgrade.rb', line 166

def run
  if args.build_from_source? && args.named.empty?
    raise ArgumentError, "`--build-from-source` requires at least one formula"
  end
  raise UsageError, "`--minimum-version` requires exactly one formula or cask argument." if
    minimum_version.present? && args.named.length != 1

  formulae = T.let([], T::Array[Formula])
  casks = T.let([], T::Array[Cask::Cask])
  unavailable_errors = T.let(
    [],
    T::Array[T.any(FormulaOrCaskUnavailableError, NoSuchKegError)],
  )
  @prefetched_formulae_upgrade_context = T.let(nil, T.nilable(FormulaeUpgradeContext))
  prefetched_formulae_names = T.let([], T::Array[String])
  prefetched_formulae_upgrades = T.let([], T::Array[String])
  prefetched_cask_names = T.let([], T::Array[String])
  prefetched_cask_upgrades = T.let([], T::Array[String])
  prefetched_cask_upgrade_casks = T.let([], T::Array[Cask::Cask])
  prefetched_cask_errors = T.let([], T::Array[StandardError])
  @final_upgrade_summary = T.let(FinalUpgradeSummary.new, T.nilable(FinalUpgradeSummary))
  @ask_prompt_required = false
  ask = !args.no_ask? && !args.dry_run?
  skip_upgrades_after_failed_ask_preview = T.let(false, T::Boolean)

  if args.named.present?
    Homebrew::Trust.trust_fully_qualified_items!(args.named, type: args.only_formula_or_cask)

    args.named.to_formulae_and_casks_and_unavailable(method: :resolve).each do |item|
      case item
      when FormulaOrCaskUnavailableError, NoSuchKegError
        unavailable_errors << item
      when Formula
        formulae << item
      when Cask::Cask
        casks << item
      end
    end
  end

  # If one or more formulae are specified, but no casks were
  # specified, we want to make note of that so we don't
  # try to upgrade all outdated casks.
  #
  # When names were given, we must also prevent empty resolved lists
  # from triggering the "upgrade all" path (which happens when all
  # names failed resolution).
  named_given = args.named.present?
  only_upgrade_formulae = (named_given && casks.blank?) || (formulae.present? && casks.blank?)
  only_upgrade_casks = (named_given && formulae.blank?) || (casks.present? && formulae.blank?)

  if Homebrew::EnvConfig.verify_attestations?
    formulae = Homebrew::Attestation.sort_formulae_for_install(formulae)
  end

  formulae_prefetched = T.let(false, T::Boolean)
  prefetched_casks = T.let(false, T::Boolean)
  ask_upgrade_planned = T.let(false, T::Boolean)
  shared_download_queue = T.let(nil, T.nilable(Homebrew::DownloadQueue))
  if ask
    unless only_upgrade_casks
      upgrade_outdated_formulae!(
        formulae,
        dry_run:              true,
        show_upgrade_summary: false,
      )
    end
    unless only_upgrade_formulae
      upgrade_outdated_casks!(
        casks,
        dry_run:              true,
        skip_prefetch:        false,
        show_upgrade_summary: false,
        download_queue:       nil,
      )
    end

    show_final_upgrade_summary(dry_run: true)
    if Install.ask_prompt_needed?(
      planned_names:   final_upgrade_summary.version_changes.map do |version_change|
        planned_name = version_change.split.fetch(0)
        formulae.find { |formula| formula.full_specified_name == planned_name }&.full_name || planned_name
      end,
      requested_names: args.named,
      force:           @ask_prompt_required,
      named:           args.named.present?,
    )
      Install.ask(action: "upgrade")
      Cask::Upgrade.show_upgrade_summary(final_upgrade_summary.version_changes)
    end
    ask_upgrade_planned = final_upgrade_summary.version_changes.present?
    skip_upgrades_after_failed_ask_preview = Homebrew.failed? && !ask_upgrade_planned
    @final_upgrade_summary = FinalUpgradeSummary.new
  end

  if !args.dry_run? && (!ask || ask_upgrade_planned) && !only_upgrade_formulae && !only_upgrade_casks
    shared_download_queue = Homebrew::DownloadQueue.new(pour: true)
    begin
      formulae_prefetched = upgrade_outdated_formulae!(
        formulae,
        prefetch_only:          true,
        download_queue:         shared_download_queue,
        prefetch_names:         prefetched_formulae_names,
        prefetch_upgrades:      prefetched_formulae_upgrades,
        show_upgrade_summary:   false,
        show_downloads_heading: false,
      )
      prefetched_casks = prefetch_outdated_casks!(
        casks,
        download_queue:         shared_download_queue,
        prefetch_names:         prefetched_cask_names,
        prefetch_upgrades:      prefetched_cask_upgrades,
        prefetch_casks:         prefetched_cask_upgrade_casks,
        prefetch_errors:        prefetched_cask_errors,
        show_downloads_heading: false,
      )
      unless ask
        Cask::Upgrade.show_upgrade_summary(
          prefetched_formulae_upgrades + prefetched_cask_upgrades,
          dry_run: args.dry_run?,
        )
      end
      Install.show_combined_fetch_downloads_heading(
        formula_names: prefetched_formulae_names,
        cask_names:    prefetched_cask_names,
      )
      shared_download_queue.fetch
      if shared_download_queue.fetch_failed
        formulae_prefetched = false
        prefetched_casks = false
      end
    ensure
      shared_download_queue.shutdown
    end
  end

  if !only_upgrade_casks && !skip_upgrades_after_failed_ask_preview
    upgrade_outdated_formulae!(
      formulae,
      use_prefetched:       formulae_prefetched,
      show_upgrade_summary: prefetched_formulae_upgrades.blank? && !args.dry_run? && !ask,
    )
  end
  if !only_upgrade_formulae && !skip_upgrades_after_failed_ask_preview
    if prefetched_casks
      upgrade_outdated_casks!(
        prefetched_cask_upgrade_casks,
        skip_prefetch:          true,
        show_upgrade_summary:   prefetched_cask_upgrades.blank? && !args.dry_run? && !ask,
        download_queue:         nil,
        prefetched_cask_errors: prefetched_cask_errors,
      )
    else
      upgrade_outdated_casks!(
        casks,
        skip_prefetch:        false,
        show_upgrade_summary: prefetched_cask_upgrades.blank? && !args.dry_run? && !ask,
        download_queue:       nil,
      )
    end
  end

  unavailable_errors.each { |e| ofail e }

  Cleanup.periodic_clean!(dry_run: args.dry_run?)

  Homebrew::Reinstall.reinstall_pkgconf_if_needed!(dry_run: args.dry_run?)

  Homebrew.messages.display_messages(display_times: args.display_times?)

  show_final_upgrade_summary
end

#show_final_upgrade_summary(dry_run: args.dry_run?) ⇒ 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:

  • dry_run (Boolean) (defaults to: args.dry_run?)


533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
# File 'cmd/upgrade.rb', line 533

def show_final_upgrade_summary(dry_run: args.dry_run?)
  summary = final_upgrade_summary
  return if summary.version_changes.empty? && summary.pinned_formulae.empty? && summary.pinned_casks.empty? &&
            summary.deprecated.empty? && summary.disabled.empty? && summary.source_build_formulae.empty?

  if summary.version_changes.present?
    version_change_count = summary.version_changes.uniq.count
    show_final_upgrade_summary_section(
      "#{dry_run ? "Would upgrade" : "Upgraded"} #{version_change_count} outdated " \
      "#{Utils.pluralize("package", version_change_count)}",
      Upgrade.format_upgrade_summary(summary.version_changes),
    )
  end
  if summary.pinned_formulae.present?
    pinned_count = summary.pinned_formulae.uniq.count
    show_final_upgrade_summary_section(
      "#{pinned_count} Pinned #{Utils.pluralize("formula", pinned_count)}",
      summary.pinned_formulae,
    )
  end
  if summary.pinned_casks.present?
    pinned_count = summary.pinned_casks.uniq.count
    show_final_upgrade_summary_section(
      "#{pinned_count} Pinned #{Utils.pluralize("cask", pinned_count)}",
      summary.pinned_casks,
    )
  end
  deprecate_disable_summary = summary.deprecated.map { |item| "#{item} (deprecated)" } +
                              summary.disabled.map { |item| "#{item} (disabled)" }
  deprecate_disable_count = deprecate_disable_summary.uniq.count
  show_final_upgrade_summary_section(
    "#{deprecate_disable_count} Deprecated or disabled #{Utils.pluralize("package", deprecate_disable_count)}",
    deprecate_disable_summary,
  )
  source_build_count = summary.source_build_formulae.uniq.count
  if dry_run
    show_final_upgrade_summary_section(
      "#{source_build_count} homebrew/core " \
      "#{Utils.pluralize("formula", source_build_count)} that would build from source",
      summary.source_build_formulae,
    )
  else
    show_final_upgrade_summary_section(
      "#{source_build_count} homebrew/core #{Utils.pluralize("formula", source_build_count)} built from source",
      summary.source_build_formulae,
    )
  end
end

#upgrade_outdated_casks!(casks, skip_prefetch: false, show_upgrade_summary: true, dry_run: args.dry_run?, download_queue: nil, prefetched_cask_errors: nil) ⇒ 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.

Parameters:

  • casks (Array<Cask::Cask>)
  • skip_prefetch (Boolean) (defaults to: false)
  • show_upgrade_summary (Boolean) (defaults to: true)
  • dry_run (Boolean) (defaults to: args.dry_run?)
  • download_queue (Homebrew::DownloadQueue, nil) (defaults to: nil)
  • prefetched_cask_errors (Array<StandardError>, nil) (defaults to: nil)

Returns:

  • (Boolean)


801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
# File 'cmd/upgrade.rb', line 801

def upgrade_outdated_casks!(casks, skip_prefetch: false, show_upgrade_summary: true,
                            dry_run: args.dry_run?,
                            download_queue: nil, prefetched_cask_errors: nil)
  return false if args.formula?

  quiet = args.quiet? || (dry_run && !args.dry_run?)
  casks = minimum_version_casks(casks, quiet:)
  return false if minimum_version.present? && casks.empty?

  if skip_prefetch && casks.empty? && prefetched_cask_errors.present?
    raise Cask::MultipleCaskErrors, prefetched_cask_errors if prefetched_cask_errors.count > 1

    raise prefetched_cask_errors.fetch(0)
  end

  Cask::Upgrade.upgrade_casks!(
    *casks,
    force:                args.force?,
    greedy:               args.greedy?,
    greedy_latest:        args.greedy_latest?,
    greedy_auto_updates:  args.greedy_auto_updates?,
    dry_run:,
    binaries:             args.binaries?,
    require_sha:          args.require_sha?,
    skip_cask_deps:       args.skip_cask_deps?,
    quit:                 !args.no_quit?,
    verbose:              args.verbose?,
    quiet:,
    skip_prefetch:,
    show_upgrade_summary:,
    download_queue:,
    summary_upgrades:     final_upgrade_summary.version_changes,
    summary_pinned:       final_upgrade_summary.pinned_casks,
    summary_deprecated:   final_upgrade_summary.deprecated,
    summary_disabled:     final_upgrade_summary.disabled,
    prefetched_errors:    prefetched_cask_errors,
    args:,
  )
rescue => e
  ofail e
  false
end

#upgrade_outdated_formulae!(formulae, prefetch_only: false, use_prefetched: false, dry_run: args.dry_run?, download_queue: nil, prefetch_names: nil, prefetch_upgrades: nil, show_upgrade_summary: true, show_downloads_heading: true) ⇒ 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.

Parameters:

  • formulae (Array<Formula>)
  • prefetch_only (Boolean) (defaults to: false)
  • use_prefetched (Boolean) (defaults to: false)
  • dry_run (Boolean) (defaults to: args.dry_run?)
  • download_queue (Homebrew::DownloadQueue, nil) (defaults to: nil)
  • prefetch_names (Array<String>, nil) (defaults to: nil)
  • prefetch_upgrades (Array<String>, nil) (defaults to: nil)
  • show_upgrade_summary (Boolean) (defaults to: true)
  • show_downloads_heading (Boolean) (defaults to: true)

Returns:

  • (Boolean)


616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
# File 'cmd/upgrade.rb', line 616

def upgrade_outdated_formulae!(formulae, prefetch_only: false, use_prefetched: false,
                               dry_run: args.dry_run?,
                               download_queue: nil,
                               prefetch_names: nil,
                               prefetch_upgrades: nil,
                               show_upgrade_summary: true,
                               show_downloads_heading: true)
  return false if args.cask?

  use_prefetched_context = use_prefetched && @prefetched_formulae_upgrade_context
  context = if use_prefetched_context
    @prefetched_formulae_upgrade_context
  else
    formulae_upgrade_context(formulae, show_upgrade_summary:, dry_run:)
  end
  return false if context.blank?

  if prefetch_only
    prefetch_download_queue = download_queue || Homebrew.default_download_queue
    valid_formula_installers = Install.enqueue_formulae(context.formulae_installer,
                                                        download_queue: prefetch_download_queue)
    if show_downloads_heading
      Install.show_combined_fetch_downloads_heading(
        formula_names: valid_formula_installers.map { |fi| fi.formula.name },
      )
    end
    prefetch_names&.replace(valid_formula_installers.map { |fi| fi.formula.name })
    prefetch_upgrades&.replace(formula_upgrade_descriptions(valid_formula_installers.map(&:formula)))
    @prefetched_formulae_upgrade_context = FormulaeUpgradeContext.new(
      formulae_to_install: context.formulae_to_install,
      formulae_installer:  valid_formula_installers,
      dependants:          context.dependants,
      pinned_formulae:     context.pinned_formulae,
    )
    return valid_formula_installers.present?
  end

  formula_version_changes = formula_upgrade_descriptions(context.formulae_installer.map(&:formula),
                                                         include_sizes: dry_run)
  dependent_version_changes = formula_upgrade_descriptions(context.dependants.upgradeable,
                                                           include_sizes: dry_run)
  if dry_run
    record_formula_upgrade_summary(context,
                                   version_changes: formula_version_changes + dependent_version_changes)
  end
  if !args.no_ask? && dry_run && args.named.present? &&
     Install.formulae_ask_prompt_needed?(context.formulae_installer, context.dependants)
    @ask_prompt_required = true
  end

  skip_formula_names = if dry_run
    (context.formulae_installer.map(&:formula) + context.dependants.upgradeable)
      .uniq(&:full_name)
      .map(&:full_name)
  else
    []
  end

  upgraded_formula_installers = Upgrade.upgrade_formulae(
    context.formulae_installer,
    dry_run:,
    verbose:            args.verbose?,
    fetch:              !use_prefetched_context,
    skip_formula_names:,
  )

  Upgrade.upgrade_dependents(
    context.dependants, context.formulae_to_install,
    flags:                      args.flags_only,
    dry_run:,
    force_bottle:               args.force_bottle?,
    build_from_source_formulae: args.build_from_source_formulae,
    interactive:                args.interactive?,
    keep_tmp:                   args.keep_tmp?,
    debug_symbols:              args.debug_symbols?,
    force:                      args.force?,
    debug:                      args.debug?,
    quiet:                      args.quiet?,
    verbose:                    args.verbose?,
    skip_formula_names:
  )

  unless dry_run
    upgraded_formula_installers_by_identity = T.let({}.compare_by_identity,
                                                    T::Hash[FormulaInstaller, T::Boolean])
    upgraded_formula_installers.each do |formula_installer|
      upgraded_formula_installers_by_identity[formula_installer] = true
    end
    record_formula_upgrade_summary(
      context,
      formulae_installer: upgraded_formula_installers,
      version_changes:    context.formulae_installer.each_with_index.filter_map do |formula_installer, index|
        formula_version_changes.fetch(index) if upgraded_formula_installers_by_identity.key?(formula_installer)
      end + dependent_version_changes,
    )
  end

  @prefetched_formulae_upgrade_context = nil if use_prefetched_context
  true
end