Module: Homebrew::Bundle Private

Defined in:
bundle.rb,
bundle/dsl.rb,
bundle/tap.rb,
bundle/brew.rb,
bundle/cask.rb,
bundle/adder.rb,
bundle/trust.rb,
bundle/dumper.rb,
bundle/lister.rb,
bundle/checker.rb,
bundle/remover.rb,
bundle/skipper.rb,
bundle/brewfile.rb,
bundle/installer.rb,
bundle/package_type.rb,
bundle/brew_services.rb,
bundle/extensions/go.rb,
bundle/extensions/uv.rb,
bundle/extensions/npm.rb,
bundle/extensions/krew.rb,
bundle/extensions/cargo.rb,
bundle/extensions/winget.rb,
bundle/extensions/flatpak.rb,
bundle/extensions/extension.rb,
bundle/extensions/mac_app_store.rb,
bundle/extensions/vscode_extension.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, Brewfile, Checker, Dumper, Installer, Lister, Remover, Skipper, Trust Classes: Brew, Cargo, Cask, Dsl, Extension, Flatpak, Go, Krew, MacAppStore, Npm, PackageType, Tap, Uv, VscodeExtension, Winget

Constant Summary collapse

EntryOptionScalar =

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.nilable(T.any(String, Integer, Symbol, TrueClass, FalseClass)) }
NestedEntryOptionValue =

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(EntryOptionScalar, T::Array[String]) }
NestedEntryOptions =

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, NestedEntryOptionValue] }
EntryOption =

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(EntryOptionScalar, T::Array[String], NestedEntryOptions) }
EntryOptions =

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, EntryOption] }
EntryInputOptions =

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, Object] }
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)


46
47
48
# File 'bundle.rb', line 46

def brew(*args, verbose: false)
  system(HOMEBREW_BREW_FILE, *args, verbose:)
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)


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

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

.dump_package_types ⇒ Array<T.class_of(PackageType)>

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:



189
190
191
192
# File 'bundle/package_type.rb', line 189

def dump_package_types
  core_package_types = [:tap, :brew, :cask].filter_map { |type| package_type(type) }
  (core_package_types + (package_types - core_package_types)).uniq
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:



411
412
413
414
# File 'bundle/extensions/extension.rb', line 411

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

.extensions ⇒ Array<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:



405
406
407
408
# File 'bundle/extensions/extension.rb', line 405

def extensions
  @extensions ||= T.let([], T.nilable(T::Array[T.class_of(Extension)]))
  @extensions
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:



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

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

.formula_versions_from_env_cache ⇒ Hash{String => 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:



86
87
88
# File 'bundle.rb', line 86

def formula_versions_from_env_cache
  @formula_versions_from_env
end

.formula_versions_from_env_cache=(formula_versions) ⇒ 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:



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

def formula_versions_from_env_cache=(formula_versions)
  @formula_versions_from_env = formula_versions
end

.installable(type) ⇒ T.class_of(PackageType)?

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:



421
422
423
# File 'bundle/extensions/extension.rb', line 421

def installable(type)
  package_type(type) || extension(type)
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:



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

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 = Formulary.canonical_name(entry.name)
    next if installed_formulae.exclude?(name)

    tab = Tab.for_name(name)
    tabfile = tab.tabfile
    next unless 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

.package_type(type) ⇒ T.class_of(PackageType)?

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:



183
184
185
186
# File 'bundle/package_type.rb', line 183

def package_type(type)
  requested_type = type.to_sym
  package_types.find { |registered| registered.type == requested_type }
end

.package_types ⇒ Array<T.class_of(PackageType)>

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:



177
178
179
180
# File 'bundle/package_type.rb', line 177

def package_types
  @package_types ||= T.let([], T.nilable(T::Array[T.class_of(PackageType)]))
  @package_types
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.



96
# File 'bundle.rb', line 96

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:



398
399
400
401
402
# File 'bundle/extensions/extension.rb', line 398

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

.register_package_type(package_type) ⇒ 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:



170
171
172
173
174
# File 'bundle/package_type.rb', line 170

def register_package_type(package_type)
  @package_types ||= T.let([], T.nilable(T::Array[T.class_of(PackageType)]))
  @package_types.reject! { |registered| registered.name == package_type.name }
  @package_types << package_type
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.



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

def reset!
  @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
36
37
38
39
40
41
42
43
# File 'bundle.rb', line 20

def system(cmd, *args, verbose: false)
  env = {}

  # Make sure node's bin opt path is part of the PATH
  # This is essential for the npm bundle extension that calls node directly
  if Npm.package_manager_executable && cmd.to_s == Npm.package_manager_executable.to_s
    env["PATH"] = "#{ENV.fetch("PATH")}:#{HOMEBREW_PREFIX}/opt/node/bin"
  end

  return super env, cmd, *args if verbose

  logs = []
  success = T.let(false, T::Boolean)
  IO.popen(env, [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_formulae ⇒ 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.

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