Module: Homebrew::Reinstall Private

Defined in:
reinstall.rb

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

Defined Under Namespace

Classes: InstallationContext, self

Class Method Summary collapse

Class Method Details

.build_install_context(formula, flags:, force_bottle: false, build_from_source_formulae: [], interactive: false, keep_tmp: false, debug_symbols: false, force: false, debug: false, quiet: false, verbose: false, git: false) ⇒ InstallationContext

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:

  • formula (Formula)
  • flags (Array<String>)
  • force_bottle (Boolean) (defaults to: false)
  • build_from_source_formulae (Array<String>) (defaults to: [])
  • interactive (Boolean) (defaults to: false)
  • keep_tmp (Boolean) (defaults to: false)
  • debug_symbols (Boolean) (defaults to: false)
  • force (Boolean) (defaults to: false)
  • debug (Boolean) (defaults to: false)
  • quiet (Boolean) (defaults to: false)
  • verbose (Boolean) (defaults to: false)
  • git (Boolean) (defaults to: false)

Returns:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'reinstall.rb', line 30

def build_install_context(
  formula,
  flags:,
  force_bottle: false,
  build_from_source_formulae: [],
  interactive: false,
  keep_tmp: false,
  debug_symbols: false,
  force: false,
  debug: false,
  quiet: false,
  verbose: false,
  git: false
)
  if formula.opt_prefix.directory?
    keg = Keg.new(formula.opt_prefix.resolved_path)
    tab = keg.tab
    link_keg = keg.linked?
    installed_as_dependency = tab.installed_as_dependency == true
    installed_on_request = tab.installed_on_request == true
    build_bottle = tab.built_bottle?
    backup keg
  else
    link_keg = nil
    installed_as_dependency = false
    installed_on_request = true
    build_bottle = false
  end

  build_options = BuildOptions.new(Options.create(flags), formula.options)
  options = build_options.used_options
  options |= formula.build.used_options
  options &= formula.options

  formula_installer = FormulaInstaller.new(
    formula,
    **{
      options:,
      link_keg:,
      installed_as_dependency:,
      installed_on_request:,
      build_bottle:,
      force_bottle:,
      build_from_source_formulae:,
      git:,
      interactive:,
      keep_tmp:,
      debug_symbols:,
      force:,
      debug:,
      quiet:,
      verbose:,
    }.compact,
  )
  InstallationContext.new(formula_installer:, keg:, formula:, options:)
end

.reinstall_formula(install_context) ⇒ 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:



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
# File 'reinstall.rb', line 88

def reinstall_formula(install_context)
  formula_installer = install_context.formula_installer
  keg = install_context.keg
  formula = install_context.formula
  options = install_context.options
  link_keg = keg&.linked?
  verbose = formula_installer.verbose?

  oh1 "Reinstalling #{Formatter.identifier(formula.full_name)} #{options.to_a.join " "}"

  formula_installer.install
  formula_installer.finish
rescue FormulaInstallationAlreadyAttemptedError
  nil
  # Any other exceptions we want to restore the previous keg and report the error.
rescue Exception # rubocop:disable Lint/RescueException
  ignore_interrupts { restore_backup(keg, link_keg, verbose:) if keg }
  raise
else
  if keg
    backup_keg = backup_path(keg)
    begin
      FileUtils.rm_r(backup_keg) if backup_keg.exist?
    rescue Errno::EACCES, Errno::ENOTEMPTY
      odie <<~EOS
        Could not remove #{backup_keg.parent.basename} backup keg! Do so manually:
          sudo rm -rf #{backup_keg}
      EOS
    end
  end
end