Module: Homebrew::Bundle Private

Defined in:
bundle.rb,
bundle/dsl.rb,
bundle/adder.rb,
bundle/dumper.rb,
bundle/lister.rb,
bundle/checker.rb,
bundle/remover.rb,
bundle/skipper.rb,
bundle/brewfile.rb,
bundle/installer.rb,
bundle/tap_dumper.rb,
bundle/cask_dumper.rb,
bundle/tap_checker.rb,
bundle/brew_checker.rb,
bundle/cargo_dumper.rb,
bundle/cask_checker.rb,
bundle/commands/add.rb,
bundle/brew_services.rb,
bundle/cargo_checker.rb,
bundle/commands/dump.rb,
bundle/commands/exec.rb,
bundle/commands/list.rb,
bundle/extensions/go.rb,
bundle/extensions/uv.rb,
bundle/tap_installer.rb,
bundle/cask_installer.rb,
bundle/commands/check.rb,
bundle/flatpak_dumper.rb,
bundle/formula_dumper.rb,
bundle/cargo_installer.rb,
bundle/commands/remove.rb,
bundle/flatpak_checker.rb,
bundle/commands/cleanup.rb,
bundle/commands/install.rb,
bundle/flatpak_installer.rb,
bundle/formula_installer.rb,
bundle/brew_service_checker.rb,
bundle/extensions/extension.rb,
bundle/mac_app_store_dumper.rb,
bundle/mac_app_store_checker.rb,
bundle/mac_app_store_installer.rb,
bundle/vscode_extension_dumper.rb,
bundle/vscode_extension_checker.rb,
bundle/vscode_extension_installer.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

Modules: Adder, BrewServices, Brewfile, CargoDumper, CargoInstaller, CaskDumper, CaskInstaller, Checker, Commands, Dumper, FlatpakDumper, FlatpakInstaller, FormulaDumper, Installer, Lister, MacAppStoreDumper, MacAppStoreInstaller, Remover, Skipper, TapDumper, TapInstaller, VscodeExtensionDumper, VscodeExtensionInstaller Classes: Dsl, Extension, FormulaInstaller, Go, Uv

Constant Summary collapse

GoDumper =

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.

TODO:

Remove these compatibility aliases once bundle callers and tests

stop requiring separate go dumper/installer/checker constants.

Go
GoInstaller =

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.

Go
UvDumper =

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.

TODO:

Remove these compatibility aliases once bundle callers and tests

stop requiring separate uv dumper/installer/checker constants.

Uv
UvInstaller =

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.

Uv
ExtensionTypes =

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::Hash[Symbol, T::Boolean] }

Class Method Summary collapse

Class Method Details

.brew(*args, verbose: false) ⇒ 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:

  • args (T.anything)
  • verbose (Boolean) (defaults to: false)

Returns:

  • (Boolean)


38
39
40
# File 'bundle.rb', line 38

def brew(*args, verbose: false)
  system(HOMEBREW_BREW_FILE, *args, verbose:)
end

.cargo_installed?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.

Returns:

  • (Boolean)


83
84
85
# File 'bundle.rb', line 83

def cargo_installed?
  @cargo_installed ||= which_cargo.present?
end

.cask_installed?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.

Returns:

  • (Boolean)


110
111
112
113
114
# File 'bundle.rb', line 110

def cask_installed?
  @cask_installed ||= File.directory?("#{HOMEBREW_PREFIX}/Caskroom") &&
                      (File.directory?("#{HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-cask") ||
                       !Homebrew::EnvConfig.no_install_from_api?)
end

.exchange_uid_if_needed!(&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.

Parameters:

  • block (T.proc.returns(T.anything))

Returns:

  • (T.untyped)


124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'bundle.rb', line 124

def exchange_uid_if_needed!(&block)
  euid = Process.euid
  uid = Process.uid
  return yield if euid == uid

  old_euid = euid
  process_reexchangeable = Process::UID.re_exchangeable?
  if process_reexchangeable
    Process::UID.re_exchange
  else
    Process::Sys.seteuid(uid)
  end

  home = T.must(Etc.getpwuid(Process.uid)).dir
  return_value = with_env("HOME" => home, &block)

  if process_reexchangeable
    Process::UID.re_exchange
  else
    Process::Sys.seteuid(old_euid)
  end

  return_value
end

.extension(type) ⇒ T.class_of(Extension)?

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:



368
369
370
371
# File 'bundle/extensions/extension.rb', line 368

def extension(type)
  requested_type = type.to_sym
  extensions.find { |registered| registered.type == requested_type }
end

.extensionsArray<T.class_of(Extension)>

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:



362
363
364
365
# File 'bundle/extensions/extension.rb', line 362

def extensions
  @extensions ||= T.let([], T.nilable(T::Array[T.class_of(Extension)]))
  @extensions
end

.flatpak_installed?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.

Returns:

  • (Boolean)


105
106
107
# File 'bundle.rb', line 105

def flatpak_installed?
  @flatpak_installed ||= which_flatpak.present?
end

.formula_versions_from_env(formula_name) ⇒ 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:



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'bundle.rb', line 150

def formula_versions_from_env(formula_name)
  @formula_versions_from_env ||= begin
    formula_versions = {}

    ENV.each do |key, value|
      match = key.match(/^HOMEBREW_BUNDLE_FORMULA_VERSION_(.+)$/)
      next if match.blank?

      env_formula_name = match[1]
      next if env_formula_name.blank?

      ENV.delete(key)
      formula_versions[env_formula_name] = value
    end

    formula_versions
  end

  # Fix up formula name for a valid environment variable name.
  formula_env_name = formula_name.upcase
                                 .gsub("@", "AT")
                                 .tr("+", "X")
                                 .tr("-", "_")

  @formula_versions_from_env[formula_env_name]
end

.go_installed?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.

Returns:

  • (Boolean)


73
74
75
# File 'bundle.rb', line 73

def go_installed?
  @go_installed ||= which_go.present?
end

.mark_as_installed_on_request!(entries) ⇒ 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.

Marks Brewfile formulae as installed_on_request to prevent autoremove from removing them when their dependents are uninstalled.

Parameters:



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
# File 'bundle.rb', line 202

def mark_as_installed_on_request!(entries)
  return if entries.empty?

  require "tab"

  installed_formulae = Formula.installed_formula_names
  return if installed_formulae.empty?

  use_brew_tab = T.let(false, T::Boolean)

  formulae_to_update = entries.filter_map do |entry|
    next if entry.type != :brew

    name = entry.name
    next if installed_formulae.exclude?(name)

    tab = Tab.for_name(name)
    next if tab.tabfile.blank? || !tab.tabfile.exist?
    next if tab.installed_on_request

    next name if use_brew_tab

    tab.installed_on_request = true

    begin
      tab.write
      nil
    rescue Errno::EACCES
      # Some wrappers might treat `brew bundle` with lower permissions due to its execution of user code.
      # Running through `brew tab` ensures proper privilege escalation by going through the wrapper again.
      use_brew_tab = true
      name
    end
  end

  brew "tab", "--installed-on-request", *formulae_to_update if use_brew_tab
end

.mas_installed?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.

Returns:

  • (Boolean)


43
44
45
# File 'bundle.rb', line 43

def mas_installed?
  @mas_installed ||= which_mas.present?
end

.prepend_pkgconf_path_if_needed!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.



178
# File 'bundle.rb', line 178

def prepend_pkgconf_path_if_needed!; end

.register_extension(extension) ⇒ 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:



355
356
357
358
359
# File 'bundle/extensions/extension.rb', line 355

def register_extension(extension)
  @extensions ||= T.let([], T.nilable(T::Array[T.class_of(Extension)]))
  @extensions.reject! { |registered| registered.name == extension.name }
  @extensions << extension
end

.reset!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.



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'bundle.rb', line 181

def reset!
  @which_mas = T.let(nil, T.nilable(Pathname))
  @mas_installed = T.let(nil, T.nilable(T::Boolean))
  @vscode_installed = T.let(nil, T.nilable(T::Boolean))
  @which_vscode = T.let(nil, T.nilable(Pathname))
  @which_go = T.let(nil, T.nilable(Pathname))
  @go_installed = T.let(nil, T.nilable(T::Boolean))
  @which_cargo = T.let(nil, T.nilable(Pathname))
  @cargo_installed = T.let(nil, T.nilable(T::Boolean))
  @which_uv = T.let(nil, T.nilable(Pathname))
  @uv_installed = T.let(nil, T.nilable(T::Boolean))
  @which_flatpak = T.let(nil, T.nilable(Pathname))
  @flatpak_installed = T.let(nil, T.nilable(T::Boolean))
  @cask_installed = T.let(nil, T.nilable(T::Boolean))
  @formula_versions_from_env = T.let(nil, T.nilable(T::Hash[String, String]))
  @upgrade_formulae = T.let(nil, T.nilable(T::Array[String]))
end

.system(cmd, *args, verbose: false) ⇒ 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:

  • cmd (String, Pathname)
  • args (T.anything)
  • verbose (Boolean) (defaults to: false)

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'bundle.rb', line 20

def system(cmd, *args, verbose: false)
  return super cmd, *args if verbose

  logs = []
  success = T.let(false, T::Boolean)
  IO.popen([cmd, *args], err: [:child, :out]) do |pipe|
    while (buf = pipe.gets)
      logs << buf
    end
    Process.wait(pipe.pid)
    success = $CHILD_STATUS.success?
    pipe.close
  end
  puts logs.join unless success
  success
end

.upgrade_formulaeArray<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.

Returns:



15
16
17
# File 'bundle.rb', line 15

def upgrade_formulae
  @upgrade_formulae || []
end

.upgrade_formulae=(args_upgrade_formula) ⇒ 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:

  • args_upgrade_formula (String, nil)


10
11
12
# File 'bundle.rb', line 10

def upgrade_formulae=(args_upgrade_formula)
  @upgrade_formulae = args_upgrade_formula.to_s.split(",")
end

.uv_installed?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.

Returns:

  • (Boolean)


95
96
97
# File 'bundle.rb', line 95

def uv_installed?
  @uv_installed ||= which_uv.present?
end

.vscode_installed?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.

Returns:

  • (Boolean)


53
54
55
# File 'bundle.rb', line 53

def vscode_installed?
  @vscode_installed ||= which_vscode.present?
end

.which_cargoPathname?

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:



78
79
80
# File 'bundle.rb', line 78

def which_cargo
  @which_cargo ||= which("cargo", ORIGINAL_PATHS)
end

.which_flatpakPathname?

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:



100
101
102
# File 'bundle.rb', line 100

def which_flatpak
  @which_flatpak ||= which("flatpak", ORIGINAL_PATHS)
end

.which_formula?(name) ⇒ 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)


117
118
119
120
121
# File 'bundle.rb', line 117

def which_formula?(name)
  formula = Formulary.factory(name)
  ENV["PATH"] = "#{formula.opt_bin}:#{ENV.fetch("PATH", nil)}" if formula.any_version_installed?
  which(name).present?
end

.which_goPathname?

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.

TODO:

Remove these go helpers once the bundle extension specs stop

stubbing them directly.

Returns:



68
69
70
# File 'bundle.rb', line 68

def which_go
  @which_go ||= which("go", ORIGINAL_PATHS)
end

.which_masPathname?

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:



48
49
50
# File 'bundle.rb', line 48

def which_mas
  @which_mas ||= which("mas", ORIGINAL_PATHS)
end

.which_uvPathname?

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.

TODO:

Remove these uv helpers once the bundle extension specs stop

stubbing them directly.

Returns:



90
91
92
# File 'bundle.rb', line 90

def which_uv
  @which_uv ||= which("uv", ORIGINAL_PATHS)
end

.which_vscodePathname?

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:



58
59
60
61
62
63
# File 'bundle.rb', line 58

def which_vscode
  @which_vscode ||= which("code", ORIGINAL_PATHS)
  @which_vscode ||= which("codium", ORIGINAL_PATHS)
  @which_vscode ||= which("cursor", ORIGINAL_PATHS)
  @which_vscode ||= which("code-insiders", ORIGINAL_PATHS)
end