Module: Utils::Path Private

Overview

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.

Helpers for Homebrew path handling and package path validation.

Defined Under Namespace

Modules: FormulaHelpers, Helpers

Class Method Summary collapse

Methods included from Output::Mixin

issue_reporting_message, odebug, odeprecated, odie, odisabled, ofail, oh1, oh1_title, ohai, ohai_title, onoe, opoo, opoo_once, opoo_outside_github_actions, opoo_without_github_actions_annotation, pretty_cannot_install, pretty_deprecated, pretty_disabled, pretty_duration, pretty_install_status, pretty_installed, pretty_removed, pretty_uninstalled, pretty_unmarked, pretty_upgradable, pretty_warning

Methods included from Helpers

child_of?, cp_path_sub, ensure_child_of!, ensure_writable, relative_path_from, resolved_path, resolved_path_exists?, rmdir_if_possible, text_executable?

Methods included from FormulaHelpers

formula_any_version_installed?, formula_opt_bin, formula_opt_include, formula_opt_lib, formula_opt_libexec, formula_opt_prefix

Class Method Details

.formula_installed_prefixes(formula_names) ⇒ Array<Pathname>

The installed prefix directories for one or more formula names.

Parameters:

Returns:



244
245
246
247
248
249
250
# File 'utils/path.rb', line 244

def self.formula_installed_prefixes(formula_names)
  Array(formula_names).map { |formula_name| HOMEBREW_CELLAR/Utils.name_from_full_name(formula_name) }
                      .select(&:directory?)
                      .uniq(&:realpath)
                      .flat_map(&:subdirs)
                      .sort_by(&:basename)
end

.formula_opt_bin_env(formula_name, *paths) ⇒ Hash{String => String}

An environment hash with PATH prepended by a formula's stable bin directory.

Parameters:

Returns:



264
265
266
# File 'utils/path.rb', line 264

def self.formula_opt_bin_env(formula_name, *paths)
  { "PATH" => formula_opt_bin_path(formula_name, *paths).to_s }
end

.formula_opt_bin_path(formula_name, *paths) ⇒ PATH

The current PATH with a formula's stable bin directory prepended.

Parameters:

Returns:



256
257
258
# File 'utils/path.rb', line 256

def self.formula_opt_bin_path(formula_name, *paths)
  PATH.new(formula_opt_bin(formula_name), *paths, ENV.fetch("PATH"))
end

.install_info(path, verbose: false) ⇒ 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:

  • path (Pathname)
  • verbose (Boolean) (defaults to: false)


164
165
166
167
# File 'utils/path.rb', line 164

def self.install_info(path, verbose: false)
  SystemCommand.quiet_system(install_info_executable, "--quiet", path.to_s, (path.dirname/"dir").to_s)
  puts "info #{path}" if verbose
end

.loadable_package_path?(_path, _package_type) ⇒ 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)


269
270
271
272
# File 'utils/path.rb', line 269

def self.loadable_package_path?(_path, _package_type)
  odeprecated "Utils::Path.loadable_package_path?", "explicit internal Formulary/CaskLoader.from_path calls"
  false
end

.tap_package_path(path, package_type) ⇒ Pathname?

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.

Resolve an audited source path to its registered tap file, including symlinked checkouts.

Parameters:

Returns:



289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'utils/path.rb', line 289

def self.tap_package_path(path, package_type)
  return unless path.file?

  require "api/env"

  path = path.expand_path
  tap = Tap.from_path(path)
  unless tap
    path = path.realpath
    tap = Tap.installed.find do |installed_tap|
      installed_tap.path.directory? && path.to_s.start_with?("#{installed_tap.path.realpath}/")
    end
    return unless tap
  end

  files = Homebrew::API.with_no_api_env do
    (package_type == :formula) ? tap.formula_files : tap.cask_files
  end
  # Tap caches file lists sorted by full path.
  return path if files.bsearch { |file| file.to_s >= path.to_s } == path

  candidate = tap.path/path.realpath.relative_path_from(tap.path.realpath)
  candidate if files.bsearch { |file| file.to_s >= candidate.to_s } == candidate
end

.uninstall_info(path, verbose: false) ⇒ 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:

  • path (Pathname)
  • verbose (Boolean) (defaults to: false)


170
171
172
173
# File 'utils/path.rb', line 170

def self.uninstall_info(path, verbose: false)
  SystemCommand.quiet_system(install_info_executable, "--delete", "--quiet", path.to_s, (path.dirname/"dir").to_s)
  puts "uninfo #{path}" if verbose
end

.valid_package_name?(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.

Accept bare package names or user/tap/name references, never filesystem paths.

Parameters:

  • name (T.anything)

Returns:

  • (Boolean)


276
277
278
279
280
281
282
283
284
# File 'utils/path.rb', line 276

def self.valid_package_name?(name)
  case name
  when String
    name.match?(HOMEBREW_PACKAGE_REFERENCE_REGEX) &&
      !name.split("/").intersect?(Utils::INVALID_PATH_COMPONENTS)
  else
    false
  end
end