Module: Homebrew Private

Extended by:
Context, FileUtils
Includes:
Kernel
Defined in:
extend/os/mac/cleanup.rb,
extend/os/linux/parser.rb,
extend/os/linux/cleanup.rb,
extend/os/linux/install.rb,
extend/os/mac/diagnostic.rb,
extend/os/linux/diagnostic.rb,
extend/os/mac/dev-cmd/bottle.rb,
extend/os/mac/missing_formula.rb,
extend/os/mac/simulate_system.rb,
extend/os/linux/simulate_system.rb,
extend/os/linux/cmd/update-report.rb,
extend/os/linux/dev-cmd/update-test.rb,
api.rb,
help.rb,
fetch.rb,
style.rb,
utils.rb,
global.rb,
search.rb,
unlink.rb,
cleanup.rb,
cmd/log.rb,
cmd/pin.rb,
cmd/tap.rb,
install.rb,
service.rb,
upgrade.rb,
api/cask.rb,
cli/args.rb,
cmd/deps.rb,
cmd/desc.rb,
cmd/docs.rb,
cmd/help.rb,
cmd/home.rb,
cmd/info.rb,
cmd/link.rb,
cmd/list.rb,
cmd/uses.rb,
manpages.rb,
settings.rb,
cmd/--env.rb,
cmd/fetch.rb,
cmd/unpin.rb,
cmd/untap.rb,
reinstall.rb,
uninstall.rb,
cli/parser.rb,
cmd/config.rb,
cmd/doctor.rb,
cmd/leaves.rb,
cmd/search.rb,
cmd/unlink.rb,
dev-cmd/sh.rb,
diagnostic.rb,
env_config.rb,
utils/gems.rb,
api/formula.rb,
attestation.rb,
cmd/--cache.rb,
cmd/cleanup.rb,
cmd/command.rb,
cmd/install.rb,
cmd/migrate.rb,
cmd/missing.rb,
cmd/options.rb,
cmd/readall.rb,
cmd/upgrade.rb,
completions.rb,
dev-cmd/cat.rb,
dev-cmd/irb.rb,
tap_auditor.rb,
api/download.rb,
cmd/--cellar.rb,
cmd/--prefix.rb,
cmd/commands.rb,
cmd/outdated.rb,
cmd/tap-info.rb,
dev-cmd/bump.rb,
dev-cmd/edit.rb,
dev-cmd/prof.rb,
dev-cmd/ruby.rb,
dev-cmd/test.rb,
api/analytics.rb,
cmd/analytics.rb,
cmd/developer.rb,
cmd/gist-logs.rb,
cmd/reinstall.rb,
cmd/uninstall.rb,
dev-cmd/audit.rb,
dev-cmd/style.rb,
dev-cmd/tests.rb,
bundle_version.rb,
cli/named_args.rb,
cmd/--caskroom.rb,
cmd/autoremove.rb,
cmd/pyenv-sync.rb,
cmd/rbenv-sync.rb,
dev-cmd/bottle.rb,
dev-cmd/create.rb,
dev-cmd/unpack.rb,
sorbet/parlour.rb,
cmd/completions.rb,
cmd/nodenv-sync.rb,
cmd/postinstall.rb,
dev-cmd/extract.rb,
dev-cmd/formula.rb,
dev-cmd/linkage.rb,
dev-cmd/pr-pull.rb,
dev-cmd/release.rb,
dev-cmd/rubydoc.rb,
dev-cmd/tap-new.rb,
formula_auditor.rb,
formula_creator.rb,
livecheck/error.rb,
missing_formula.rb,
simulate_system.rb,
source_location.rb,
abstract_command.rb,
cmd/--repository.rb,
resource_auditor.rb,
cmd/update-report.rb,
dev-cmd/livecheck.rb,
dev-cmd/pr-upload.rb,
dev-cmd/typecheck.rb,
dev-cmd/unbottled.rb,
formula_free_port.rb,
dev-cmd/pr-publish.rb,
formula_assertions.rb,
livecheck/strategy.rb,
bump_version_parser.rb,
dev-cmd/update-test.rb,
dev-cmd/vendor-gems.rb,
livecheck/constants.rb,
livecheck/livecheck.rb,
dev-cmd/bump-cask-pr.rb,
dev-cmd/pr-automerge.rb,
manpages/parser/ronn.rb,
dev-cmd/bump-revision.rb,
dev-cmd/contributions.rb,
livecheck/strategy/git.rb,
livecheck/strategy/gnu.rb,
livecheck/strategy/npm.rb,
livecheck/strategy/xml.rb,
dev-cmd/bump-formula-pr.rb,
dev-cmd/update-sponsors.rb,
livecheck/strategy/cpan.rb,
livecheck/strategy/json.rb,
livecheck/strategy/pypi.rb,
livecheck/strategy/xorg.rb,
livecheck/strategy/yaml.rb,
manpages/converter/roff.rb,
livecheck/strategy/crate.rb,
livecheck/strategy/gnome.rb,
unversioned_cask_checker.rb,
dev-cmd/generate-cask-api.rb,
livecheck/skip_conditions.rb,
livecheck/strategy/apache.rb,
dev-cmd/update-maintainers.rb,
livecheck/strategy/hackage.rb,
livecheck/strategy/sparkle.rb,
dev-cmd/update-license-data.rb,
livecheck/livecheck_version.rb,
manpages/converter/kramdown.rb,
dev-cmd/generate-formula-api.rb,
dev-cmd/install-bundler-gems.rb,
livecheck/strategy/bitbucket.rb,
livecheck/strategy/launchpad.rb,
dev-cmd/dispatch-build-bottle.rb,
livecheck/strategy/page_match.rb,
dev-cmd/bump-unversioned-casks.rb,
dev-cmd/determine-test-runners.rb,
livecheck/strategy/sourceforge.rb,
dev-cmd/update-python-resources.rb,
livecheck/strategy/header_match.rb,
dev-cmd/generate-man-completions.rb,
livecheck/strategy/extract_plist.rb,
livecheck/strategy/github_latest.rb,
livecheck/strategy/github_releases.rb,
livecheck/strategy/electron_builder.rb,
global.rbi,
service.rbi,
utils/gems.rbi,
sorbet/rbi/parlour.rbi,
livecheck/livecheck.rbi

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: API, Assertions, Attestation, CLI, Cmd, Completions, DevCmd, Diagnostic, EnvConfig, Fetch, FreePort, Help, Install, Livecheck, Manpages, MissingFormula, Parlour, Search, Settings, Style, Uninstall, Unlink, Upgrade Classes: AbstractCommand, BumpVersionParser, BundleVersion, Cleanup, FormulaAuditor, FormulaCreator, ResourceAuditor, Service, SimulateSystem, SourceLocation, TapAuditor, UnversionedCaskChecker

Constant Summary collapse

DEFAULT_PREFIX =

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.let(ENV.fetch("HOMEBREW_DEFAULT_PREFIX").freeze, String)
DEFAULT_REPOSITORY =

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.let(ENV.fetch("HOMEBREW_DEFAULT_REPOSITORY").freeze, String)
DEFAULT_CELLAR =

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.

"#{DEFAULT_PREFIX}/Cellar".freeze
DEFAULT_MACOS_CELLAR =

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.

"#{HOMEBREW_DEFAULT_PREFIX}/Cellar".freeze
DEFAULT_MACOS_ARM_CELLAR =

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.

"#{HOMEBREW_MACOS_ARM_DEFAULT_PREFIX}/Cellar".freeze
DEFAULT_LINUX_CELLAR =

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.

"#{HOMEBREW_LINUX_DEFAULT_PREFIX}/Cellar".freeze
HOMEBREW_BUNDLER_VERSION =

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.

Keep in sync with the Gemfile.lock's BUNDLED WITH. After updating this, run brew vendor-gems --update=--bundler.

"2.5.9"

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Context

current, current=, debug?, quiet?, verbose?, with_context

Methods included from Kernel

#disk_usage_readable, #ensure_executable!, #ensure_formula_installed!, #exec_browser, #exec_editor, #ignore_interrupts, #interactive_shell, #number_readable, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #paths, #pretty_duration, #pretty_installed, #pretty_outdated, #pretty_uninstalled, #quiet_system, #redact_secrets, #redirect_stdout, #require?, #safe_system, #tap_and_name_comparison, #truncate_text_to_approximate_size, #which, #which_all, #which_editor, #with_custom_locale, #with_env, #with_homebrew_path

Class Attribute Details

.auditing=(value) ⇒ Object (writeonly)

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.



84
85
86
# File 'global.rb', line 84

def auditing=(value)
  @auditing = value
end

.failed=(value) ⇒ Object (writeonly)

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.



84
85
86
# File 'global.rb', line 84

def failed=(value)
  @failed = value
end

.raise_deprecation_exceptions=(value) ⇒ Object (writeonly)

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.



84
85
86
# File 'global.rb', line 84

def raise_deprecation_exceptions=(value)
  @raise_deprecation_exceptions = value
end

Class Method Details

._system(cmd, *args, **options) ⇒ Object

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.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'utils.rb', line 29

def self._system(cmd, *args, **options)
  pid = fork do
    yield if block_given?
    args.map!(&:to_s)
    begin
      exec(cmd, *args, **options)
    rescue
      nil
    end
    exit! 1 # never gets here unless exec failed
  end
  Process.wait(T.must(pid))
  $CHILD_STATUS.success?
end

.auditing?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)


107
108
109
# File 'global.rb', line 107

def auditing?
  @auditing == true
end

.auto_update_command?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)


124
125
126
# File 'global.rb', line 124

def auto_update_command?
  ENV.fetch("HOMEBREW_AUTO_UPDATE_COMMAND", false).present?
end

.backup(keg) ⇒ Object

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.



82
83
84
85
86
87
88
89
90
91
92
# File 'reinstall.rb', line 82

def backup(keg)
  keg.unlink
  begin
    keg.rename backup_path(keg)
  rescue Errno::EACCES, Errno::ENOTEMPTY
    odie <<~EOS
      Could not rename #{keg.name} keg! Check/fix its permissions:
        sudo chown -R #{ENV.fetch("USER", "$(whoami)")} #{keg}
    EOS
  end
end

.backup_path(path) ⇒ Object

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.



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

def backup_path(path)
  Pathname.new "#{path}.reinstall"
end

.default_prefix?(prefix = HOMEBREW_PREFIX) ⇒ Boolean

This method is part of an internal API. This method may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Check whether Homebrew is using the default prefix.

Parameters:

Returns:

  • (Boolean)


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

def default_prefix?(prefix = HOMEBREW_PREFIX)
  prefix.to_s == DEFAULT_PREFIX
end

.failed?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)


94
95
96
97
# File 'global.rb', line 94

def failed?
  @failed ||= false
  @failed == true
end

.forget_user_gem_groups!Object

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.



209
210
211
212
# File 'utils/gems.rb', line 209

def forget_user_gem_groups!
  GEM_GROUPS_FILE.truncate(0) if GEM_GROUPS_FILE.exist?
  @user_gem_groups = []
end

.inject_dump_stats!(the_module, pattern) ⇒ Object

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.



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
86
# File 'utils.rb', line 55

def self.inject_dump_stats!(the_module, pattern)
  @injected_dump_stat_modules ||= {}
  @injected_dump_stat_modules[the_module] ||= []
  injected_methods = @injected_dump_stat_modules[the_module]
  the_module.module_eval do
    instance_methods.grep(pattern).each do |name|
      next if injected_methods.include? name

      method = instance_method(name)
      define_method(name) do |*args, &block|
        time = Time.now

        begin
          method.bind_call(self, *args, &block)
        ensure
          $times[name] ||= 0
          $times[name] += Time.now - time
        end
      end
    end
  end

  return unless $times.nil?

  $times = {}
  at_exit do
    col_width = [$times.keys.map(&:size).max.to_i + 2, 15].max
    $times.sort_by { |_k, v| v }.each do |method, time|
      puts format("%<method>-#{col_width}s %<time>0.4f sec", method: "#{method}:", time:)
    end
  end
end

.install_bundler!Object

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.



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'utils/gems.rb', line 161

def install_bundler!
  old_bundler_version = ENV.fetch("BUNDLER_VERSION", nil)

  setup_gem_environment!

  ENV["BUNDLER_VERSION"] = HOMEBREW_BUNDLER_VERSION # Set so it correctly finds existing installs
  install_gem_setup_path!(
    "bundler",
    version:               HOMEBREW_BUNDLER_VERSION,
    executable:            "bundle",
    setup_gem_environment: false,
  )
ensure
  ENV["BUNDLER_VERSION"] = old_bundler_version
end

.install_bundler_gems!(only_warn_on_failure: false, setup_path: true, groups: []) ⇒ Object

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.



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
338
339
340
341
342
343
344
345
346
# File 'utils/gems.rb', line 223

def install_bundler_gems!(only_warn_on_failure: false, setup_path: true, groups: [])
  old_path = ENV.fetch("PATH", nil)
  old_gem_path = ENV.fetch("GEM_PATH", nil)
  old_gem_home = ENV.fetch("GEM_HOME", nil)
  old_bundle_gemfile = ENV.fetch("BUNDLE_GEMFILE", nil)
  old_bundle_with = ENV.fetch("BUNDLE_WITH", nil)
  old_bundle_frozen = ENV.fetch("BUNDLE_FROZEN", nil)

  invalid_groups = groups - valid_gem_groups
  raise ArgumentError, "Invalid gem groups: #{invalid_groups.join(", ")}" unless invalid_groups.empty?

  # Tests should not modify the state of the repository.
  if ENV["HOMEBREW_TESTS"]
    setup_gem_environment!
    return
  end

  install_bundler!

  # Combine the passed groups with the ones stored in settings.
  groups |= (user_gem_groups & valid_gem_groups)
  groups.sort!

  if (homebrew_bundle_user_cache = ENV.fetch("HOMEBREW_BUNDLE_USER_CACHE", nil))
    ENV["BUNDLE_USER_CACHE"] = homebrew_bundle_user_cache
  end
  ENV["BUNDLE_GEMFILE"] = gemfile
  ENV["BUNDLE_WITH"] = groups.join(" ")
  ENV["BUNDLE_FROZEN"] = "true"

  if @bundle_installed_groups != groups
    bundle = File.join(find_in_path("bundle"), "bundle")
    bundle_check_output = `#{bundle} check 2>&1`
    bundle_check_failed = !$CHILD_STATUS.success?

    # for some reason sometimes the exit code lies so check the output too.
    bundle_install_required = bundle_check_failed || bundle_check_output.include?("Install missing gems")

    if user_vendor_version != VENDOR_VERSION
      # Check if the install is intact. This is useful if any gems are added to gitignore.
      # We intentionally map over everything and then call `any?` so that we remove the spec of each bad gem.
      specs = bundler_definition.resolve.materialize(bundler_definition.locked_dependencies)
      vendor_reinstall_required = specs.map do |spec|
        spec_file = "#{Gem.dir}/specifications/#{spec.full_name}.gemspec"
        next false unless File.exist?(spec_file)

        cache_file = "#{Gem.dir}/cache/#{spec.full_name}.gem"
        if File.exist?(cache_file)
          require "rubygems/package"
          package = Gem::Package.new(cache_file)

          package_install_intact = begin
            contents = package.contents

            # If the gem has contents, ensure we have every file installed it contains.
            contents&.all? do |gem_file|
              File.exist?("#{Gem.dir}/gems/#{spec.full_name}/#{gem_file}")
            end
          rescue Gem::Package::Error, Gem::Security::Exception
            # Malformed, assume broken
            File.unlink(cache_file)
            false
          end

          next false if package_install_intact
        end

        # Mark gem for reinstallation
        File.unlink(spec_file)
        true
      end.any?

      VENDOR_VERSION_FILE.dirname.mkpath
      VENDOR_VERSION_FILE.write(VENDOR_VERSION.to_s)

      bundle_install_required ||= vendor_reinstall_required
    end

    bundle_installed = if bundle_install_required
      if system bundle, "install", out: :err
        true
      else
        message = <<~EOS
          failed to run `#{bundle} install`!
        EOS
        if only_warn_on_failure
          opoo_if_defined message
        else
          odie_if_defined message
        end
        false
      end
    elsif system bundle, "clean", out: :err # even if we have nothing to install, we may have removed gems
      true
    else
      message = <<~EOS
        failed to run `#{bundle} clean`!
      EOS
      if only_warn_on_failure
        opoo_if_defined message
      else
        odie_if_defined message
      end
      false
    end

    if bundle_installed
      write_user_gem_groups(groups)
      @bundle_installed_groups = groups
    end
  end

  setup_gem_environment!
ensure
  unless setup_path
    # Reset the paths. We need to have at least temporarily changed them while invoking `bundle`.
    ENV["PATH"] = old_path
    ENV["GEM_PATH"] = old_gem_path
    ENV["GEM_HOME"] = old_gem_home
    ENV["BUNDLE_GEMFILE"] = old_bundle_gemfile
    ENV["BUNDLE_WITH"] = old_bundle_with
    ENV["BUNDLE_FROZEN"] = old_bundle_frozen
  end
end

.install_gem!(name, version: nil, setup_gem_environment: true) ⇒ Object

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.



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
# File 'utils/gems.rb', line 117

def install_gem!(name, version: nil, setup_gem_environment: true)
  setup_gem_environment! if setup_gem_environment

  specs = Gem::Specification.find_all_by_name(name, version)

  if specs.empty?
    ohai_if_defined "Installing '#{name}' gem"
    # `document: []` is equivalent to --no-document
    # `build_args: []` stops ARGV being used as a default
    # `env_shebang: true` makes shebangs generic to allow switching between system and Portable Ruby
    specs = Gem.install name, version, document: [], build_args: [], env_shebang: true
  end

  specs += specs.flat_map(&:runtime_dependencies)
                .flat_map(&:to_specs)

  # Add the specs to the $LOAD_PATH.
  specs.each do |spec|
    spec.require_paths.each do |path|
      full_path = File.join(spec.full_gem_path, path)
      $LOAD_PATH.unshift full_path unless $LOAD_PATH.include?(full_path)
    end
  end
rescue Gem::UnsatisfiableDependencyError
  odie_if_defined "failed to install the '#{name}' gem."
end

.install_gem_setup_path!(name, version: nil, executable: name, setup_gem_environment: true) ⇒ Object

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.



144
145
146
147
148
149
150
151
152
# File 'utils/gems.rb', line 144

def install_gem_setup_path!(name, version: nil, executable: name, setup_gem_environment: true)
  install_gem!(name, version:, setup_gem_environment:)
  return if find_in_path(executable)

  odie_if_defined <<~EOS
    the '#{name}' gem is installed but couldn't find '#{executable}' in the PATH:
      #{ENV.fetch("PATH")}
  EOS
end

.messagesObject

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.



99
100
101
# File 'global.rb', line 99

def messages
  @messages ||= Messages.new
end

.migrate_gcc_dependents_if_neededObject

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.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'extend/os/linux/cmd/update-report.rb', line 11

def migrate_gcc_dependents_if_needed
  return if Settings.read("gcc-rpaths.fixed") == "true"

  Formula.installed.each do |formula|
    next unless formula.tap&.core_tap?

    recursive_runtime_dependencies = Dependency.expand(
      formula,
      cache_key: "update-report",
    ) do |_, dependency|
      Dependency.prune if dependency.build? || dependency.test?
    end
    next unless recursive_runtime_dependencies.map(&:name).include? "gcc"

    keg = formula.installed_kegs.last
    tab = keg.tab
    # Force reinstallation upon `brew upgrade` to fix the bottle RPATH.
    tab.source["versions"]["version_scheme"] = -1
    tab.write
  rescue TapFormulaUnavailableError
    nil
  end

  Settings.write "gcc-rpaths.fixed", true
end

.no_changes_messageObject

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.



7
8
9
# File 'extend/os/linux/cmd/update-report.rb', line 7

def no_changes_message
  "No changes to formulae."
end

.odie_if_defined(message) ⇒ Object

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.



77
78
79
80
81
82
83
84
# File 'utils/gems.rb', line 77

def odie_if_defined(message)
  if defined?(odie)
    odie message
  else
    $stderr.puts "Error: #{message}"
    exit 1
  end
end

.ohai_if_defined(message) ⇒ Object

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.



61
62
63
64
65
66
67
# File 'utils/gems.rb', line 61

def ohai_if_defined(message)
  if defined?(ohai)
    $stderr.ohai message
  else
    $stderr.puts "==> #{message}"
  end
end

.opoo_if_defined(message) ⇒ Object

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.



69
70
71
72
73
74
75
# File 'utils/gems.rb', line 69

def opoo_if_defined(message)
  if defined?(opoo)
    $stderr.opoo message
  else
    $stderr.puts "Warning: #{message}"
  end
end

.owner_uidObject

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.



116
117
118
# File 'global.rb', line 116

def owner_uid
  @owner_uid ||= HOMEBREW_BREW_FILE.stat.uid
end

.raise_deprecation_exceptions?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)


103
104
105
# File 'global.rb', line 103

def raise_deprecation_exceptions?
  @raise_deprecation_exceptions == true
end

.reinstall_formula(formula, flags:, installed_on_request: false, 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) ⇒ Object

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.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
# File 'reinstall.rb', line 11

def reinstall_formula(
  formula,
  flags:,
  installed_on_request: false,
  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
    keg_had_linked_opt = true
    keg_was_linked = keg.linked?
    backup keg
  end

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

  fi = FormulaInstaller.new(
    formula,
    **{
      options:,
      link_keg:                   keg_had_linked_opt ? keg_was_linked : nil,
      installed_as_dependency:    tab&.installed_as_dependency,
      installed_on_request:       installed_on_request || tab&.installed_on_request,
      build_bottle:               tab&.built_bottle?,
      force_bottle:,
      build_from_source_formulae:,
      git:,
      interactive:,
      keep_tmp:,
      debug_symbols:,
      force:,
      debug:,
      quiet:,
      verbose:,
    }.compact,
  )
  fi.prelude
  fi.fetch

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

  fi.install
  fi.finish
rescue FormulaInstallationAlreadyAttemptedError
  nil
rescue Exception # rubocop:disable Lint/RescueException
  ignore_interrupts { restore_backup(keg, keg_was_linked, verbose:) }
  raise
else
  begin
    backup_path(keg).rmtree if backup_path(keg).exist?
  rescue Errno::EACCES, Errno::ENOTEMPTY
    odie <<~EOS
      Could not remove #{backup_path(keg).parent.basename} backup keg! Do so manually:
        sudo rm -rf #{backup_path(keg)}
    EOS
  end
end

.restore_backup(keg, keg_was_linked, verbose:) ⇒ Object

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.



94
95
96
97
98
99
100
101
102
103
# File 'reinstall.rb', line 94

def restore_backup(keg, keg_was_linked, verbose:)
  path = backup_path(keg)

  return unless path.directory?

  Pathname.new(keg).rmtree if keg.exist?

  path.rename keg
  keg.link(verbose:) if keg_was_linked
end

.ruby_bindirObject

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.



57
58
59
# File 'utils/gems.rb', line 57

def ruby_bindir
  "#{RbConfig::CONFIG["prefix"]}/bin"
end

.running_as_root?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)


111
112
113
114
# File 'global.rb', line 111

def running_as_root?
  @process_euid ||= Process.euid
  @process_euid.zero?
end

.running_as_root_but_not_owned_by_root?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)


120
121
122
# File 'global.rb', line 120

def running_as_root_but_not_owned_by_root?
  running_as_root? && !owner_uid.zero?
end

.setup_gem_environment!(setup_path: true) ⇒ Object

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.



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
# File 'utils/gems.rb', line 86

def setup_gem_environment!(setup_path: true)
  require "rubygems"
  raise "RubyGems too old!" if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.2.0")

  ENV["BUNDLER_NO_OLD_RUBYGEMS_WARNING"] = "1"

  # Match where our bundler gems are.
  gem_home = "#{RUBY_BUNDLE_VENDOR_DIRECTORY}/#{RbConfig::CONFIG["ruby_version"]}"
  Gem.paths = {
    "GEM_HOME" => gem_home,
    "GEM_PATH" => gem_home,
  }

  # Set TMPDIR so Xcode's `make` doesn't fall back to `/var/tmp/`,
  # which may be not user-writable.
  ENV["TMPDIR"] = ENV.fetch("HOMEBREW_TEMP", nil)

  return unless setup_path

  # Add necessary Ruby and Gem binary directories to `PATH`.
  paths = ENV.fetch("PATH").split(":")
  paths.unshift(ruby_bindir) unless paths.include?(ruby_bindir)
  paths.unshift(Gem.bindir) unless paths.include?(Gem.bindir)
  ENV["PATH"] = paths.compact.join(":")

  # Set envs so the above binaries can be invoked.
  # We don't do this unless requested as some formulae may invoke system Ruby instead of ours.
  ENV["GEM_HOME"] = gem_home
  ENV["GEM_PATH"] = gem_home
end

.system(cmd, *args, **options) ⇒ Object

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.



44
45
46
47
48
49
50
51
# File 'utils.rb', line 44

def self.system(cmd, *args, **options)
  if verbose?
    out = (options[:out] == :err) ? $stderr : $stdout
    out.puts "#{cmd} #{args * " "}".gsub(RUBY_PATH, "ruby")
                                   .gsub($LOAD_PATH.join(File::PATH_SEPARATOR).to_s, "$LOAD_PATH")
  end
  _system(cmd, *args, **options)
end

.valid_gem_groupsObject

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.



45
46
47
48
49
50
51
52
53
54
55
# File 'utils/gems.rb', line 45

def valid_gem_groups
  install_bundler!
  require "bundler"

  Bundler.with_unbundled_env do
    ENV["BUNDLE_GEMFILE"] = gemfile
    groups = bundler_definition.groups
    groups.delete(:default)
    groups.map(&:to_s)
  end
end

.with_no_api_env(&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.untyped))

Returns:

  • (T.untyped)


196
197
198
199
200
# File 'api.rb', line 196

def self.with_no_api_env(&block)
  return yield if Homebrew::EnvConfig.no_install_from_api?

  with_env(HOMEBREW_NO_INSTALL_FROM_API: "1", HOMEBREW_AUTOMATICALLY_SET_NO_INSTALL_FROM_API: "1", &block)
end

.with_no_api_env_if_needed(condition, &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:

  • condition (Boolean)
  • block (T.proc.returns(T.untyped))

Returns:

  • (T.untyped)


203
204
205
206
207
# File 'api.rb', line 203

def self.with_no_api_env_if_needed(condition, &block)
  return yield unless condition

  with_no_api_env(&block)
end

Instance Method Details

#gem_user_bindirString

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:



8
# File 'utils/gems.rbi', line 8

def gem_user_bindir; end