Module: Homebrew Private

Extended by:
Context, FileUtils
Defined in:
extend/os/linux/install.rb,
extend/os/mac/missing_formula.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/tab.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,
cli/error.rb,
cmd/--env.rb,
cmd/casks.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,
cmd/update.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/formulae.rb,
cmd/outdated.rb,
cmd/shellenv.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/--version.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,
shell_command.rb,
bundle_version.rb,
cli/named_args.rb,
cmd/--caskroom.rb,
cmd/autoremove.rb,
cmd/pyenv-sync.rb,
cmd/rbenv-sync.rb,
cmd/setup-ruby.rb,
dev-cmd/bottle.rb,
dev-cmd/create.rb,
dev-cmd/unpack.rb,
download_queue.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/rubocop.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,
cmd/update-reset.rb,
dev-cmd/debugger.rb,
resource_auditor.rb,
startup/bootsnap.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,
cmd/vendor-install.rb,
dev-cmd/pr-publish.rb,
formula_assertions.rb,
livecheck/strategy.rb,
retryable_download.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,
sorbet/tapioca/utils.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/generate-cask-ci-matrix.rb,
dev-cmd/update-python-resources.rb,
formula_name_cask_token_auditor.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,
service.rbi,
utils/gems.rbi,
startup/bootsnap.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, Reinstall, Search, Settings, ShellCommand, Style, Tapioca, Uninstall, Unlink, Upgrade Classes: AbstractCommand, BumpVersionParser, BundleVersion, Cleanup, DownloadQueue, FormulaAuditor, FormulaCreator, FormulaNameCaskTokenAuditor, ResourceAuditor, RetryableDownload, 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.20"

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Context

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

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.



70
71
72
# File 'global.rb', line 70

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.



70
71
72
# File 'global.rb', line 70

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.



70
71
72
# File 'global.rb', line 70

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.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'utils.rb', line 9

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)


93
94
95
# File 'global.rb', line 93

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)


110
111
112
# File 'global.rb', line 110

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

.bootsnap_keyString

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:



9
10
11
12
13
14
15
16
17
18
19
20
# File 'startup/bootsnap.rb', line 9

def self.bootsnap_key
  @bootsnap_key ||= begin
    require "digest/sha2"

    checksum = Digest::SHA256.new
    checksum << RUBY_VERSION
    checksum << RUBY_PLATFORM
    checksum << Dir.children(File.join(Gem.paths.path, "gems")).join(",")

    checksum.hexdigest
  end
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)


76
77
78
# File 'global.rb', line 76

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)


80
81
82
83
# File 'global.rb', line 80

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.



207
208
209
210
# File 'utils/gems.rb', line 207

def self.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.



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

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|
        require "time"

        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.



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

def self.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.



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

def self.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
      Process.wait(fork do
        # Native build scripts fail if EUID != UID
        Process::UID.change_privilege(Process.euid) if Process.euid != Process.uid
        exec bundle, "install", out: :err
      end)
      if $CHILD_STATUS.success?
        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.



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

def self.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.



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

def self.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.



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

def messages
  @messages ||= Messages.new
end

.migrate_gcc_dependents_if_neededvoid

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.



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
# File 'extend/os/linux/cmd/update-report.rb', line 13

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_messageString

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
9
10
# File 'extend/os/linux/cmd/update-report.rb', line 8

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.



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

def self.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.



59
60
61
62
63
64
65
# File 'utils/gems.rb', line 59

def self.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.



67
68
69
70
71
72
73
# File 'utils/gems.rb', line 67

def self.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.



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

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)


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

def raise_deprecation_exceptions?
  @raise_deprecation_exceptions == true
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.



55
56
57
# File 'utils/gems.rb', line 55

def self.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)


97
98
99
100
# File 'global.rb', line 97

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)


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

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

.running_command=(cmd) ⇒ 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:



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

def running_command=(cmd)
  @running_command_with_args = "#{cmd} #{ARGV.join(" ")}"
end

.running_command_with_argsString

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:



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

def running_command_with_args
  "brew #{@running_command_with_args}".strip
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.



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

def self.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.



24
25
26
27
28
29
30
31
# File 'utils.rb', line 24

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.



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

def self.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)


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

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)


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

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

  with_no_api_env(&block)
end

Instance Method Details

#find_in_path(executable) ⇒ 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:



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

def find_in_path(executable); end

#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

#install_bundler!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.



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

def install_bundler!; end

#install_bundler_gems!(only_warn_on_failure: false, setup_path: false, groups: []) ⇒ 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:

  • only_warn_on_failure (Boolean) (defaults to: false)
  • setup_path (Boolean) (defaults to: false)
  • groups (Array<String>) (defaults to: [])


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

def install_bundler_gems!(only_warn_on_failure: false, setup_path: false, groups: []); end

#install_gem_setup_path!(name, version: nil, executable: name, setup_gem_environment: true) ⇒ 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:

  • name (String)
  • version (String, nil) (defaults to: nil)
  • executable (String) (defaults to: name)
  • setup_gem_environment (Boolean) (defaults to: true)


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

def install_gem_setup_path!(name, version: nil, executable: name, setup_gem_environment: true); end

#odie_if_defined(message) ⇒ T.noreturn

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:

  • (T.noreturn)


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

def odie_if_defined(message); end

#ohai_if_defined(message) ⇒ 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:



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

def ohai_if_defined(message); end

#ruby_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:



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

def ruby_bindir; end