Refactor module_function to reduce rbi need

This commit is contained in:
Douglas Eichelberger 2023-04-17 10:37:59 -07:00
parent e98bfdd012
commit 09c679e75f
47 changed files with 210 additions and 417 deletions

View File

@ -15,10 +15,8 @@ require "upgrade"
module Homebrew
extend T::Sig
module_function
sig { returns(CLI::Parser) }
def install_args
def self.install_args
Homebrew::CLI::Parser.new do
description <<~EOS
Install a <formula> or <cask>. Additional options specific to a <formula> may be
@ -146,7 +144,7 @@ module Homebrew
end
end
def install
def self.install
args = install_args.parse
if args.env.present?

View File

@ -18,10 +18,8 @@ require "api"
module Homebrew
extend T::Sig
module_function
sig { returns(CLI::Parser) }
def reinstall_args
def self.reinstall_args
Homebrew::CLI::Parser.new do
description <<~EOS
Uninstall and then reinstall a <formula> or <cask> using the same options it was
@ -92,7 +90,7 @@ module Homebrew
end
end
def reinstall
def self.reinstall
args = reinstall_args.parse
formulae, casks = args.named.to_formulae_and_casks(method: :resolve)

View File

@ -7,8 +7,6 @@ require "completions"
#
# @api private
module Commands
module_function
HOMEBREW_CMD_PATH = (HOMEBREW_LIBRARY_PATH/"cmd").freeze
HOMEBREW_DEV_CMD_PATH = (HOMEBREW_LIBRARY_PATH/"dev-cmd").freeze
# If you are going to change anything in below hash,
@ -38,35 +36,35 @@ module Commands
# middle due to dots in URLs or paths.
DESCRIPTION_SPLITTING_PATTERN = /\.(?>\s|$)/.freeze
def valid_internal_cmd?(cmd)
def self.valid_internal_cmd?(cmd)
require?(HOMEBREW_CMD_PATH/cmd)
end
def valid_internal_dev_cmd?(cmd)
def self.valid_internal_dev_cmd?(cmd)
require?(HOMEBREW_DEV_CMD_PATH/cmd)
end
def method_name(cmd)
def self.method_name(cmd)
cmd.to_s
.tr("-", "_")
.downcase
.to_sym
end
def args_method_name(cmd_path)
def self.args_method_name(cmd_path)
cmd_path_basename = basename_without_extension(cmd_path)
cmd_method_prefix = method_name(cmd_path_basename)
"#{cmd_method_prefix}_args".to_sym
end
def internal_cmd_path(cmd)
def self.internal_cmd_path(cmd)
[
HOMEBREW_CMD_PATH/"#{cmd}.rb",
HOMEBREW_CMD_PATH/"#{cmd}.sh",
].find(&:exist?)
end
def internal_dev_cmd_path(cmd)
def self.internal_dev_cmd_path(cmd)
[
HOMEBREW_DEV_CMD_PATH/"#{cmd}.rb",
HOMEBREW_DEV_CMD_PATH/"#{cmd}.sh",
@ -74,21 +72,21 @@ module Commands
end
# Ruby commands which can be `require`d without being run.
def external_ruby_v2_cmd_path(cmd)
def self.external_ruby_v2_cmd_path(cmd)
path = which("#{cmd}.rb", Tap.cmd_directories)
path if require?(path)
end
# Ruby commands which are run by being `require`d.
def external_ruby_cmd_path(cmd)
def self.external_ruby_cmd_path(cmd)
which("brew-#{cmd}.rb", PATH.new(ENV.fetch("PATH")).append(Tap.cmd_directories))
end
def external_cmd_path(cmd)
def self.external_cmd_path(cmd)
which("brew-#{cmd}", PATH.new(ENV.fetch("PATH")).append(Tap.cmd_directories))
end
def path(cmd)
def self.path(cmd)
internal_cmd = HOMEBREW_INTERNAL_COMMAND_ALIASES.fetch(cmd, cmd)
path ||= internal_cmd_path(internal_cmd)
path ||= internal_dev_cmd_path(internal_cmd)
@ -98,7 +96,7 @@ module Commands
path
end
def commands(external: true, aliases: false)
def self.commands(external: true, aliases: false)
cmds = internal_commands
cmds += internal_developer_commands
cmds += external_commands if external
@ -106,15 +104,15 @@ module Commands
cmds.sort
end
def internal_commands_paths
def self.internal_commands_paths
find_commands HOMEBREW_CMD_PATH
end
def internal_developer_commands_paths
def self.internal_developer_commands_paths
find_commands HOMEBREW_DEV_CMD_PATH
end
def official_external_commands_paths(quiet:)
def self.official_external_commands_paths(quiet:)
OFFICIAL_CMD_TAPS.flat_map do |tap_name, cmds|
tap = Tap.fetch(tap_name)
tap.install(quiet: quiet) unless tap.installed?
@ -122,24 +120,24 @@ module Commands
end
end
def internal_commands
def self.internal_commands
find_internal_commands(HOMEBREW_CMD_PATH).map(&:to_s)
end
def internal_developer_commands
def self.internal_developer_commands
find_internal_commands(HOMEBREW_DEV_CMD_PATH).map(&:to_s)
end
def internal_commands_aliases
def self.internal_commands_aliases
HOMEBREW_INTERNAL_COMMAND_ALIASES.keys
end
def find_internal_commands(path)
def self.find_internal_commands(path)
find_commands(path).map(&:basename)
.map(&method(:basename_without_extension))
end
def external_commands
def self.external_commands
Tap.cmd_directories.flat_map do |path|
find_commands(path).select(&:executable?)
.map(&method(:basename_without_extension))
@ -148,17 +146,17 @@ module Commands
.sort
end
def basename_without_extension(path)
def self.basename_without_extension(path)
path.basename(path.extname)
end
def find_commands(path)
def self.find_commands(path)
Pathname.glob("#{path}/*")
.select(&:file?)
.sort
end
def rebuild_internal_commands_completion_list
def self.rebuild_internal_commands_completion_list
cmds = internal_commands + internal_developer_commands + internal_commands_aliases
cmds.reject! { |cmd| Homebrew::Completions::COMPLETIONS_EXCLUSION_LIST.include? cmd }
@ -166,7 +164,7 @@ module Commands
file.atomic_write("#{cmds.sort.join("\n")}\n")
end
def rebuild_commands_completion_list
def self.rebuild_commands_completion_list
# Ensure that the cache exists so we can build the commands list
HOMEBREW_CACHE.mkpath
@ -178,7 +176,7 @@ module Commands
external_commands_file.atomic_write("#{external_commands.sort.join("\n")}\n")
end
def command_options(command)
def self.command_options(command)
path = self.path(command)
return if path.blank?
@ -202,7 +200,7 @@ module Commands
end
end
def command_description(command, short: false)
def self.command_description(command, short: false)
path = self.path(command)
return if path.blank?
@ -228,7 +226,7 @@ module Commands
end
end
def named_args_type(command)
def self.named_args_type(command)
path = self.path(command)
return if path.blank?
@ -239,7 +237,7 @@ module Commands
end
# Returns the conflicts of a given `option` for `command`.
def option_conflicts(command, option)
def self.option_conflicts(command, option)
path = self.path(command)
return if path.blank?

View File

@ -1,5 +0,0 @@
# typed: strict
module Commands
include Kernel
end

View File

@ -20,8 +20,6 @@ module Homebrew
keyword_init: true,
)
module_function
COMPLETIONS_DIR = (HOMEBREW_REPOSITORY/"completions").freeze
TEMPLATE_DIR = (HOMEBREW_LIBRARY_PATH/"completions").freeze
@ -74,7 +72,7 @@ module Homebrew
}.freeze
sig { void }
def link!
def self.link!
Settings.write :linkcompletions, true
Tap.each do |tap|
Utils::Link.link_completions tap.path, "brew completions link"
@ -82,7 +80,7 @@ module Homebrew
end
sig { void }
def unlink!
def self.unlink!
Settings.write :linkcompletions, false
Tap.each do |tap|
next if tap.official?
@ -92,12 +90,12 @@ module Homebrew
end
sig { returns(T::Boolean) }
def link_completions?
def self.link_completions?
Settings.read(:linkcompletions) == "true"
end
sig { returns(T::Boolean) }
def completions_to_link?
def self.completions_to_link?
Tap.each do |tap|
next if tap.official?
@ -110,7 +108,7 @@ module Homebrew
end
sig { void }
def show_completions_message_if_needed
def self.show_completions_message_if_needed
return if Settings.read(:completionsmessageshown) == "true"
return unless completions_to_link?
@ -125,7 +123,7 @@ module Homebrew
end
sig { void }
def update_shell_completions!
def self.update_shell_completions!
commands = Commands.commands(external: false, aliases: true).sort
puts "Writing completions to #{COMPLETIONS_DIR}"
@ -136,12 +134,12 @@ module Homebrew
end
sig { params(command: String).returns(T::Boolean) }
def command_gets_completions?(command)
def self.command_gets_completions?(command)
command_options(command).any?
end
sig { params(description: String, fish: T::Boolean).returns(String) }
def format_description(description, fish: false)
def self.format_description(description, fish: false)
description = if fish
description.gsub("'", "\\\\'")
else
@ -151,7 +149,7 @@ module Homebrew
end
sig { params(command: String).returns(T::Hash[String, String]) }
def command_options(command)
def self.command_options(command)
options = {}
Commands.command_options(command)&.each do |option|
next if option.blank?
@ -169,7 +167,7 @@ module Homebrew
end
sig { params(command: String).returns(T.nilable(String)) }
def generate_bash_subcommand_completion(command)
def self.generate_bash_subcommand_completion(command)
return unless command_gets_completions? command
named_completion_string = ""
@ -202,7 +200,7 @@ module Homebrew
end
sig { params(commands: T::Array[String]).returns(String) }
def generate_bash_completion_file(commands)
def self.generate_bash_completion_file(commands)
variables = Variables.new(
completion_functions: commands.map do |command|
generate_bash_subcommand_completion command
@ -218,7 +216,7 @@ module Homebrew
end
sig { params(command: String).returns(T.nilable(String)) }
def generate_zsh_subcommand_completion(command)
def self.generate_zsh_subcommand_completion(command)
return unless command_gets_completions? command
options = command_options(command)
@ -270,7 +268,7 @@ module Homebrew
COMPLETION
end
def generate_zsh_option_exclusions(command, option)
def self.generate_zsh_option_exclusions(command, option)
conflicts = Commands.option_conflicts(command, option.gsub(/^--/, ""))
return "" unless conflicts.presence
@ -278,7 +276,7 @@ module Homebrew
end
sig { params(commands: T::Array[String]).returns(String) }
def generate_zsh_completion_file(commands)
def self.generate_zsh_completion_file(commands)
variables = Variables.new(
aliases: Commands::HOMEBREW_INTERNAL_COMMAND_ALIASES.map do |alias_command, command|
alias_command = "'#{alias_command}'" if alias_command.start_with? "-"
@ -305,7 +303,7 @@ module Homebrew
end
sig { params(command: String).returns(T.nilable(String)) }
def generate_fish_subcommand_completion(command)
def self.generate_fish_subcommand_completion(command)
return unless command_gets_completions? command
command_description = format_description Commands.command_description(command, short: true), fish: true
@ -352,7 +350,7 @@ module Homebrew
end
sig { params(commands: T::Array[String]).returns(String) }
def generate_fish_completion_file(commands)
def self.generate_fish_completion_file(commands)
variables = Variables.new(
completion_functions: commands.map do |command|
generate_fish_subcommand_completion command

View File

@ -1,7 +0,0 @@
# typed: strict
module Homebrew
module Completions
include Kernel
end
end

View File

@ -3,8 +3,6 @@
module Homebrew
module Install
module_function
# This is a list of known paths to the host dynamic linker on Linux if
# the host glibc is new enough. The symlink_ld_so method will fail if
# the host linker cannot be found in this list.
@ -32,19 +30,19 @@ module Homebrew
].freeze
private_constant :GCC_RUNTIME_LIBS
def perform_preinstall_checks(all_fatal: false, cc: nil)
def self.perform_preinstall_checks(all_fatal: false, cc: nil)
generic_perform_preinstall_checks(all_fatal: all_fatal, cc: cc)
symlink_ld_so
setup_preferred_gcc_libs
end
def global_post_install
def self.global_post_install
generic_global_post_install
symlink_ld_so
setup_preferred_gcc_libs
end
def check_cpu
def self.check_cpu
return if Hardware::CPU.intel? && Hardware::CPU.is_64_bit?
return if Hardware::CPU.arm?
@ -59,7 +57,7 @@ module Homebrew
end
private_class_method :check_cpu
def symlink_ld_so
def self.symlink_ld_so
brew_ld_so = HOMEBREW_PREFIX/"lib/ld.so"
ld_so = HOMEBREW_PREFIX/"opt/glibc/bin/ld.so"
@ -79,7 +77,7 @@ module Homebrew
end
private_class_method :symlink_ld_so
def setup_preferred_gcc_libs
def self.setup_preferred_gcc_libs
gcc_opt_prefix = HOMEBREW_PREFIX/"opt/#{OS::LINUX_PREFERRED_GCC_RUNTIME_FORMULA}"
glibc_installed = (HOMEBREW_PREFIX/"opt/glibc/bin/ld.so").readable?

View File

@ -41,9 +41,7 @@ module Homebrew
EOS
private_constant :HOMEBREW_HELP
module_function
def help(cmd = nil, empty_argv: false, usage_error: nil, remaining_args: [])
def self.help(cmd = nil, empty_argv: false, usage_error: nil, remaining_args: [])
if cmd.nil?
# Handle `brew` (no arguments).
if empty_argv
@ -75,7 +73,7 @@ module Homebrew
exit 0
end
def command_help(cmd, path, remaining_args:)
def self.command_help(cmd, path, remaining_args:)
# Only some types of commands can have a parser.
output = if Commands.valid_internal_cmd?(cmd) ||
Commands.valid_internal_dev_cmd?(cmd) ||
@ -94,7 +92,7 @@ module Homebrew
end
private_class_method :command_help
def parser_help(path, remaining_args:)
def self.parser_help(path, remaining_args:)
# Let OptionParser generate help text for commands which have a parser.
cmd_parser = CLI::Parser.from_cmd_path(path)
return unless cmd_parser
@ -105,7 +103,7 @@ module Homebrew
end
private_class_method :parser_help
def command_help_lines(path)
def self.command_help_lines(path)
path.read
.lines
.grep(/^#:/)
@ -113,7 +111,7 @@ module Homebrew
end
private_class_method :command_help_lines
def comment_help(path)
def self.comment_help(path)
# Otherwise read #: lines from the file.
help_lines = command_help_lines(path)
return if help_lines.blank?

View File

@ -1,7 +0,0 @@
# typed: strict
module Homebrew
module Help
include Kernel
end
end

View File

@ -12,8 +12,7 @@ module Homebrew
#
# @api private
module Install
module_function
class << self
def perform_preinstall_checks(all_fatal: false, cc: nil)
check_prefix
check_cpu
@ -23,7 +22,6 @@ module Homebrew
Diagnostic.checks(:fatal_preinstall_checks)
end
alias generic_perform_preinstall_checks perform_preinstall_checks
module_function :generic_perform_preinstall_checks
def perform_build_from_source_checks(all_fatal: false)
Diagnostic.checks(:fatal_build_from_source_checks)
@ -32,7 +30,6 @@ module Homebrew
def global_post_install; end
alias generic_global_post_install global_post_install
module_function :generic_global_post_install
def check_prefix
if (Hardware::CPU.intel? || Hardware::CPU.in_rosetta2?) &&
@ -364,5 +361,6 @@ module Homebrew
end
end
end
end
require "extend/os/install"

View File

@ -1,7 +0,0 @@
# typed: strict
module Homebrew
module Install
include Kernel
end
end

View File

@ -8,9 +8,7 @@ module Language
module Perl
# Helper module for replacing `perl` shebangs.
module Shebang
module_function
def detected_perl_shebang(formula = self)
def self.detected_perl_shebang(formula = self)
perl_path = if formula.deps.map(&:name).include? "perl"
Formula["perl"].opt_bin/"perl"
elsif formula.uses_from_macos_names.include? "perl"

View File

@ -1,9 +0,0 @@
# typed: strict
module Language
module Perl
module Shebang
include Kernel
end
end
end

View File

@ -92,10 +92,8 @@ module Language
# Mixin module for {Formula} adding shebang rewrite features.
module Shebang
module_function
# @private
def python_shebang_rewrite_info(python_path)
def self.python_shebang_rewrite_info(python_path)
Utils::Shebang::RewriteInfo.new(
%r{^#! ?/usr/bin/(?:env )?python(?:[23](?:\.\d{1,2})?)?( |$)},
28, # the length of "#! /usr/bin/env pythonx.yyy "
@ -103,7 +101,7 @@ module Language
)
end
def detected_python_shebang(formula = self, use_python_from_path: false)
def self.detected_python_shebang(formula = self, use_python_from_path: false)
python_path = if use_python_from_path
"/usr/bin/env python3"
else

View File

@ -1,11 +1,5 @@
# typed: strict
module Language::Python
module Shebang
include Kernel
end
module Virtualenv
requires_ancestor { Formula }
end
module Language::Python::Virtualenv
requires_ancestor { Formula }
end

View File

@ -29,9 +29,7 @@ module Homebrew
keyword_init: true,
)
module_function
def regenerate_man_pages(quiet:)
def self.regenerate_man_pages(quiet:)
Homebrew.install_bundler_gems!
markup = build_man_page(quiet: quiet)
@ -39,7 +37,7 @@ module Homebrew
convert_man_page(markup, TARGET_MAN_PATH/"brew.1")
end
def build_man_page(quiet:)
def self.build_man_page(quiet:)
template = (SOURCE_PATH/"brew.1.md.erb").read
readme = HOMEBREW_REPOSITORY/"README.md"
variables = Variables.new(
@ -64,12 +62,12 @@ module Homebrew
ERB.new(template, trim_mode: ">").result(variables.instance_eval { binding })
end
def sort_key_for_path(path)
def self.sort_key_for_path(path)
# Options after regular commands (`~` comes after `z` in ASCII table).
path.basename.to_s.sub(/\.(rb|sh)$/, "").sub(/^--/, "~~")
end
def convert_man_page(markup, target)
def self.convert_man_page(markup, target)
manual = target.basename(".1")
organisation = "Homebrew"
@ -113,7 +111,7 @@ module Homebrew
end
end
def target_path_to_format(target)
def self.target_path_to_format(target)
case target.basename
when /\.md$/ then ["--markdown", "markdown"]
when /\.\d$/ then ["--roff", "man page"]
@ -122,7 +120,7 @@ module Homebrew
end
end
def generate_cmd_manpages(cmd_paths)
def self.generate_cmd_manpages(cmd_paths)
man_page_lines = []
# preserve existing manpage order
@ -142,7 +140,7 @@ module Homebrew
man_page_lines.compact.join("\n")
end
def cmd_parser_manpage_lines(cmd_parser)
def self.cmd_parser_manpage_lines(cmd_parser)
lines = [format_usage_banner(cmd_parser.usage_banner_text)]
lines += cmd_parser.processed_options.map do |short, long, _, desc, hidden|
next if hidden
@ -159,7 +157,7 @@ module Homebrew
lines
end
def cmd_comment_manpage_lines(cmd_path)
def self.cmd_comment_manpage_lines(cmd_path)
comment_lines = cmd_path.read.lines.grep(/^#:/)
return if comment_lines.empty?
return if comment_lines.first.include?("@hide_from_man_page")
@ -185,7 +183,7 @@ module Homebrew
end
sig { returns(String) }
def global_cask_options_manpage
def self.global_cask_options_manpage
lines = ["These options are applicable to the `install`, `reinstall`, and `upgrade` " \
"subcommands with the `--cask` flag.\n"]
lines += Homebrew::CLI::Parser.global_cask_options.map do |_, long, description:, **|
@ -195,7 +193,7 @@ module Homebrew
end
sig { returns(String) }
def global_options_manpage
def self.global_options_manpage
lines = ["These options are applicable across multiple subcommands.\n"]
lines += Homebrew::CLI::Parser.global_options.map do |short, long, desc|
generate_option_doc(short, long, desc)
@ -204,7 +202,7 @@ module Homebrew
end
sig { returns(String) }
def env_vars_manpage
def self.env_vars_manpage
lines = Homebrew::EnvConfig::ENVS.flat_map do |env, hash|
entry = "- `#{env}`:\n <br>#{hash[:description]}\n"
default = hash[:default_text]
@ -216,11 +214,11 @@ module Homebrew
lines.join("\n")
end
def format_opt(opt)
def self.format_opt(opt)
"`#{opt}`" unless opt.nil?
end
def generate_option_doc(short, long, desc)
def self.generate_option_doc(short, long, desc)
comma = (short && long) ? ", " : ""
<<~EOS
* #{format_opt(short)}#{comma}#{format_opt(long)}:
@ -228,7 +226,7 @@ module Homebrew
EOS
end
def format_usage_banner(usage_banner)
def self.format_usage_banner(usage_banner)
usage_banner&.sub(/^(#: *\* )?/, "### ")
end
end

View File

@ -1,7 +0,0 @@
# typed: strict
module Homebrew
module Manpages
include Kernel
end
end

View File

@ -8,10 +8,8 @@ module OS
module Linux
extend T::Sig
module_function
sig { returns(String) }
def os_version
def self.os_version
if which("lsb_release")
lsb_info = Utils.popen_read("lsb_release", "-a")
description = lsb_info[/^Description:\s*(.*)$/, 1].force_encoding("UTF-8")
@ -29,12 +27,12 @@ module OS
end
sig { returns(T::Boolean) }
def wsl?
def self.wsl?
/-microsoft/i.match?(OS.kernel_version.to_s)
end
sig { returns(Version) }
def wsl_version
def self.wsl_version
return Version::NULL unless wsl?
kernel = OS.kernel_version.to_s
@ -58,42 +56,42 @@ module OS
raise "Loaded OS::Linux on generic OS!" if ENV["HOMEBREW_TEST_GENERIC_OS"]
def version
def self.version
::Version::NULL
end
def full_version
def self.full_version
::Version::NULL
end
def languages
def self.languages
@languages ||= Array(ENV["LANG"]&.slice(/[a-z]+/)).uniq
end
def language
def self.language
languages.first
end
def sdk_root_needed?
def self.sdk_root_needed?
false
end
def sdk_path_if_needed(_version = nil)
def self.sdk_path_if_needed(_version = nil)
nil
end
def sdk_path(_version = nil)
def self.sdk_path(_version = nil)
nil
end
module Xcode
module_function
def version
def self.version
::Version::NULL
end
def installed?
def self.installed?
false
end
end
@ -101,11 +99,11 @@ module OS
module CLT
module_function
def version
def self.version
::Version::NULL
end
def installed?
def self.installed?
false
end
end

View File

@ -1,7 +0,0 @@
# typed: strict
module OS
module Linux
include ::Kernel
end
end

View File

@ -11,8 +11,6 @@ module OS
module Mac
extend T::Sig
module_function
::MacOS = OS::Mac
raise "Loaded OS::Mac on generic OS!" if ENV["HOMEBREW_TEST_GENERIC_OS"]
@ -23,14 +21,14 @@ module OS
# This can be compared to numerics, strings, or symbols
# using the standard Ruby Comparable methods.
sig { returns(Version) }
def version
def self.version
@version ||= full_version.strip_patch
end
# This can be compared to numerics, strings, or symbols
# using the standard Ruby Comparable methods.
sig { returns(Version) }
def full_version
def self.full_version
@full_version ||= if ENV["HOMEBREW_FAKE_EL_CAPITAN"] # for Portable Ruby building
Version.new("10.11.6")
else
@ -39,21 +37,20 @@ module OS
end
sig { params(version: String).void }
def full_version=(version)
def self.full_version=(version)
@full_version = Version.new(version.chomp)
@version = nil
end
sig { returns(::Version) }
def latest_sdk_version
def self.latest_sdk_version
# TODO: bump version when new Xcode macOS SDK is released
# NOTE: We only track the major version of the SDK.
::Version.new("13")
end
private :latest_sdk_version
sig { returns(String) }
def preferred_perl_version
def self.preferred_perl_version
if version >= :big_sur
"5.30"
else
@ -61,7 +58,7 @@ module OS
end
end
def languages
def self.languages
return @languages if @languages
os_langs = Utils.popen_read("defaults", "read", "-g", "AppleLanguages")
@ -74,17 +71,17 @@ module OS
@languages = os_langs
end
def language
def self.language
languages.first
end
sig { returns(String) }
def active_developer_dir
def self.active_developer_dir
@active_developer_dir ||= Utils.popen_read("/usr/bin/xcode-select", "-print-path").strip
end
sig { returns(T::Boolean) }
def sdk_root_needed?
def self.sdk_root_needed?
if MacOS::CLT.installed?
# If there's no CLT SDK, return false
return false unless MacOS::CLT.provides_sdk?
@ -105,7 +102,7 @@ module OS
# If no specific SDK is requested, the SDK matching the OS version is returned,
# if available. Otherwise, the latest SDK is returned.
def sdk_locator
def self.sdk_locator
if CLT.installed? && CLT.provides_sdk?
CLT.sdk_locator
else
@ -113,11 +110,11 @@ module OS
end
end
def sdk(version = nil)
def self.sdk(version = nil)
sdk_locator.sdk_if_applicable(version)
end
def sdk_for_formula(formula, version = nil, check_only_runtime_requirements: false)
def self.sdk_for_formula(formula, version = nil, check_only_runtime_requirements: false)
# If the formula requires Xcode, don't return the CLT SDK
# If check_only_runtime_requirements is true, don't necessarily return the
# Xcode SDK if the XcodeRequirement is only a build or test requirement.
@ -132,12 +129,12 @@ module OS
end
# Returns the path to an SDK or nil, following the rules set by {sdk}.
def sdk_path(version = nil)
def self.sdk_path(version = nil)
s = sdk(version)
s&.path
end
def sdk_path_if_needed(version = nil)
def self.sdk_path_if_needed(version = nil)
# Prefer CLT SDK when both Xcode and the CLT are installed.
# Expected results:
# 1. On Xcode-only systems, return the Xcode SDK.
@ -156,7 +153,7 @@ module OS
# - {https://github.com/Homebrew/legacy-homebrew/issues/13}
# - {https://github.com/Homebrew/legacy-homebrew/issues/41}
# - {https://github.com/Homebrew/legacy-homebrew/issues/48}
def macports_or_fink
def self.macports_or_fink
paths = []
# First look in the path because MacPorts is relocatable and Fink
@ -186,7 +183,7 @@ module OS
end
sig { params(ids: String).returns(T.nilable(Pathname)) }
def app_with_bundle_id(*ids)
def self.app_with_bundle_id(*ids)
path = mdfind(*ids)
.reject { |p| p.include?("/Backups.backupdb/") }
.first
@ -194,20 +191,20 @@ module OS
end
sig { params(ids: String).returns(T::Array[String]) }
def mdfind(*ids)
def self.mdfind(*ids)
(@mdfind ||= {}).fetch(ids) do
@mdfind[ids] = Utils.popen_read("/usr/bin/mdfind", mdfind_query(*ids)).split("\n")
end
end
def pkgutil_info(id)
def self.pkgutil_info(id)
(@pkginfo ||= {}).fetch(id) do |key|
@pkginfo[key] = Utils.popen_read("/usr/sbin/pkgutil", "--pkg-info", key).strip
end
end
sig { params(ids: String).returns(String) }
def mdfind_query(*ids)
def self.mdfind_query(*ids)
ids.map! { |id| "kMDItemCFBundleIdentifier == #{id}" }.join(" || ")
end
end

View File

@ -1,7 +0,0 @@
# typed: strict
module OS
module Mac
include Kernel
end
end

View File

@ -9,8 +9,6 @@ module OS
module Xcode
extend T::Sig
module_function
DEFAULT_BUNDLE_PATH = Pathname("/Applications/Xcode.app").freeze
BUNDLE_ID = "com.apple.dt.Xcode"
OLD_BUNDLE_ID = "com.apple.Xcode"
@ -20,7 +18,7 @@ module OS
# CI systems have been updated.
# This may be a beta version for a beta macOS.
sig { params(macos: MacOS::Version).returns(String) }
def latest_version(macos: MacOS.version)
def self.latest_version(macos: MacOS.version)
latest_stable = "14.3"
case macos
when "13" then latest_stable
@ -44,7 +42,7 @@ module OS
# macOS version (which may initially be a beta if that version of macOS is
# also in beta).
sig { returns(String) }
def minimum_version
def self.minimum_version
case MacOS.version
when "13" then "14.1"
when "12" then "13.1"
@ -58,19 +56,19 @@ module OS
end
sig { returns(T::Boolean) }
def below_minimum_version?
def self.below_minimum_version?
return false unless installed?
version < minimum_version
end
sig { returns(T::Boolean) }
def latest_sdk_version?
def self.latest_sdk_version?
OS::Mac.full_version >= OS::Mac.latest_sdk_version
end
sig { returns(T::Boolean) }
def needs_clt_installed?
def self.needs_clt_installed?
return false if latest_sdk_version?
# With fake El Capitan for Portable Ruby, we want the full 10.11 SDK so that we can link
@ -82,21 +80,21 @@ module OS
end
sig { returns(T::Boolean) }
def outdated?
def self.outdated?
return false unless installed?
version < latest_version
end
sig { returns(T::Boolean) }
def without_clt?
def self.without_clt?
!MacOS::CLT.installed?
end
# Returns a Pathname object corresponding to Xcode.app's Developer
# directory or nil if Xcode.app is not installed.
sig { returns(T.nilable(Pathname)) }
def prefix
def self.prefix
return @prefix if defined?(@prefix)
@prefix = T.let(@prefix, T.nilable(Pathname))
@ -115,12 +113,12 @@ module OS
end
sig { returns(Pathname) }
def toolchain_path
def self.toolchain_path
Pathname("#{prefix}/Toolchains/XcodeDefault.xctoolchain")
end
sig { returns(T.nilable(Pathname)) }
def bundle_path
def self.bundle_path
# Use the default location if it exists.
return DEFAULT_BUNDLE_PATH if DEFAULT_BUNDLE_PATH.exist?
@ -131,27 +129,27 @@ module OS
end
sig { returns(T::Boolean) }
def installed?
def self.installed?
!prefix.nil?
end
sig { returns(XcodeSDKLocator) }
def sdk_locator
def self.sdk_locator
@sdk_locator ||= XcodeSDKLocator.new
end
sig { params(version: T.nilable(MacOS::Version)).returns(T.nilable(SDK)) }
def sdk(version = nil)
def self.sdk(version = nil)
sdk_locator.sdk_if_applicable(version)
end
sig { params(version: T.nilable(MacOS::Version)).returns(T.nilable(Pathname)) }
def sdk_path(version = nil)
def self.sdk_path(version = nil)
sdk(version)&.path
end
sig { returns(String) }
def installation_instructions
def self.installation_instructions
if OS::Mac.version.prerelease?
<<~EOS
Xcode can be installed from:
@ -165,7 +163,7 @@ module OS
end
sig { returns(String) }
def update_instructions
def self.update_instructions
if OS::Mac.version.prerelease?
<<~EOS
Xcode can be updated from:
@ -179,7 +177,7 @@ module OS
end
sig { returns(::Version) }
def version
def self.version
# may return a version string
# that is guessed based on the compiler, so do not
# use it in order to check if Xcode is installed.
@ -191,7 +189,7 @@ module OS
end
sig { returns(T.nilable(String)) }
def detect_version
def self.detect_version
# This is a separate function as you can't cache the value out of a block
# if return is used in the middle, which we do many times in here.
return if !MacOS::Xcode.installed? && !MacOS::CLT.installed?
@ -219,7 +217,7 @@ module OS
end
sig { returns(String) }
def detect_version_from_clang_version
def self.detect_version_from_clang_version
version = DevelopmentTools.clang_version
return "dunno" if version.null?
@ -252,7 +250,7 @@ module OS
end
sig { returns(T::Boolean) }
def default_prefix?
def self.default_prefix?
prefix.to_s == "/Applications/Xcode.app/Contents/Developer"
end
end
@ -272,37 +270,37 @@ module OS
# Returns true even if outdated tools are installed.
sig { returns(T::Boolean) }
def installed?
def self.installed?
!version.null?
end
sig { returns(T::Boolean) }
def separate_header_package?
def self.separate_header_package?
version >= "10" && MacOS.version >= "10.14"
end
sig { returns(T::Boolean) }
def provides_sdk?
def self.provides_sdk?
version >= "8"
end
sig { returns(CLTSDKLocator) }
def sdk_locator
def self.sdk_locator
@sdk_locator ||= CLTSDKLocator.new
end
sig { params(version: T.nilable(MacOS::Version)).returns(T.nilable(SDK)) }
def sdk(version = nil)
def self.sdk(version = nil)
sdk_locator.sdk_if_applicable(version)
end
sig { params(version: T.nilable(MacOS::Version)).returns(T.nilable(Pathname)) }
def sdk_path(version = nil)
def self.sdk_path(version = nil)
sdk(version)&.path
end
sig { returns(String) }
def installation_instructions
def self.installation_instructions
if MacOS.version == "10.14"
# This is not available from `xcode-select`
<<~EOS
@ -318,7 +316,7 @@ module OS
end
sig { returns(String) }
def update_instructions
def self.update_instructions
software_update_location = if MacOS.version >= "13"
"System Settings"
elsif MacOS.version >= "10.14"
@ -343,7 +341,7 @@ module OS
# Bump these when the new version is distributed through Software Update
# and our CI systems have been updated.
sig { returns(String) }
def latest_clang_version
def self.latest_clang_version
case MacOS.version
when "13" then "1403.0.22.14.1"
when "12" then "1400.0.29.202"
@ -360,7 +358,7 @@ module OS
# without this. Generally this will be the first stable CLT release on
# that macOS version.
sig { returns(String) }
def minimum_version
def self.minimum_version
case MacOS.version
when "13" then "14.0.0"
when "12" then "13.0.0"
@ -374,14 +372,14 @@ module OS
end
sig { returns(T::Boolean) }
def below_minimum_version?
def self.below_minimum_version?
return false unless installed?
version < minimum_version
end
sig { returns(T::Boolean) }
def outdated?
def self.outdated?
clang_version = detect_clang_version
return false unless clang_version
@ -389,13 +387,13 @@ module OS
end
sig { returns(T.nilable(String)) }
def detect_clang_version
def self.detect_clang_version
version_output = Utils.popen_read("#{PKG_PATH}/usr/bin/clang", "--version")
version_output[/clang-(\d+(\.\d+)+)/, 1]
end
sig { returns(T.nilable(String)) }
def detect_version_from_clang_version
def self.detect_version_from_clang_version
detect_clang_version&.sub(/^(\d+)0(\d)\./, "\\1.\\2.")
end
@ -403,7 +401,7 @@ module OS
# Note that the different ways of installing the CLTs lead to different
# version numbers.
sig { returns(::Version) }
def version
def self.version
if @version ||= detect_version
::Version.new @version
else
@ -412,7 +410,7 @@ module OS
end
sig { returns(T.nilable(String)) }
def detect_version
def self.detect_version
version = T.let(nil, T.nilable(String))
[EXECUTABLE_PKG_ID, MAVERICKS_NEW_PKG_ID].each do |id|
next unless File.exist?("#{PKG_PATH}/usr/bin/clang")

View File

@ -1,9 +0,0 @@
# typed: strict
module OS
module Mac
module Xcode
include Kernel
end
end
end

View File

@ -8,9 +8,7 @@ module Homebrew
#
# @api private
module Search
module_function
def query_regexp(query)
def self.query_regexp(query)
if (m = query.match(%r{^/(.*)/$}))
Regexp.new(m[1])
else
@ -20,7 +18,7 @@ module Homebrew
raise "#{query} is not a valid regex."
end
def search_descriptions(string_or_regex, args, search_type: :desc)
def self.search_descriptions(string_or_regex, args, search_type: :desc)
both = !args.formula? && !args.cask?
eval_all = args.eval_all? || Homebrew::EnvConfig.eval_all?
@ -42,7 +40,7 @@ module Homebrew
end
end
def search_formulae(string_or_regex)
def self.search_formulae(string_or_regex)
if string_or_regex.is_a?(String) && string_or_regex.match?(HOMEBREW_TAP_FORMULA_REGEX)
return begin
[Formulary.factory(string_or_regex).name]
@ -74,7 +72,7 @@ module Homebrew
end.compact
end
def search_casks(string_or_regex)
def self.search_casks(string_or_regex)
if string_or_regex.is_a?(String) && string_or_regex.match?(HOMEBREW_TAP_CASK_REGEX)
return begin
[Cask::CaskLoader.load(string_or_regex).token]
@ -104,7 +102,7 @@ module Homebrew
end.uniq
end
def search_names(string_or_regex, args)
def self.search_names(string_or_regex, args)
both = !args.formula? && !args.cask?
all_formulae = if args.formula? || both
@ -122,7 +120,7 @@ module Homebrew
[all_formulae, all_casks]
end
def search(selectable, string_or_regex, &block)
def self.search(selectable, string_or_regex, &block)
case string_or_regex
when Regexp
search_regex(selectable, string_or_regex, &block)
@ -131,11 +129,11 @@ module Homebrew
end
end
def simplify_string(string)
def self.simplify_string(string)
string.downcase.gsub(/[^a-z\d]/i, "")
end
def search_regex(selectable, regex)
def self.search_regex(selectable, regex)
selectable.select do |*args|
args = yield(*args) if block_given?
args = Array(args).flatten.compact
@ -143,7 +141,7 @@ module Homebrew
end
end
def search_string(selectable, string)
def self.search_string(selectable, string)
simplified_string = simplify_string(string)
selectable.select do |*args|
args = yield(*args) if block_given?

View File

@ -1,5 +0,0 @@
# typed: strict
module Homebrew::Search
include Kernel
end

View File

@ -8,9 +8,7 @@ module Homebrew
#
# @api private
module Settings
module_function
def read(setting, repo: HOMEBREW_REPOSITORY)
def self.read(setting, repo: HOMEBREW_REPOSITORY)
return unless (repo/".git/config").exist?
value = Utils.popen_read("git", "-C", repo.to_s, "config", "--get", "homebrew.#{setting}").chomp
@ -20,7 +18,7 @@ module Homebrew
value
end
def write(setting, value, repo: HOMEBREW_REPOSITORY)
def self.write(setting, value, repo: HOMEBREW_REPOSITORY)
return unless (repo/".git/config").exist?
value = value.to_s
@ -30,7 +28,7 @@ module Homebrew
Kernel.system("git", "-C", repo.to_s, "config", "--replace-all", "homebrew.#{setting}", value, exception: true)
end
def delete(setting, repo: HOMEBREW_REPOSITORY)
def self.delete(setting, repo: HOMEBREW_REPOSITORY)
return unless (repo/".git/config").exist?
return if read(setting, repo: repo).blank?

View File

@ -1,16 +0,0 @@
# typed: strict
module Homebrew
module Settings
include Kernel
sig { params(setting: T.any(String, Symbol), repo: Pathname).returns(T.nilable(String)) }
def read(setting, repo: HOMEBREW_REPOSITORY); end
sig { params(setting: T.any(String, Symbol), value: T.any(String, T::Boolean), repo: Pathname).void }
def write(setting, value, repo: HOMEBREW_REPOSITORY); end
sig { params(setting: T.any(String, Symbol), repo: Pathname).void }
def delete(setting, repo: HOMEBREW_REPOSITORY); end
end
end

View File

@ -8,9 +8,7 @@ module Homebrew
#
# @api private
module Uninstall
module_function
def uninstall_kegs(kegs_by_rack, casks: [], force: false, ignore_dependencies: false, named_args: [])
def self.uninstall_kegs(kegs_by_rack, casks: [], force: false, ignore_dependencies: false, named_args: [])
handle_unsatisfied_dependents(kegs_by_rack,
casks: casks,
ignore_dependencies: ignore_dependencies,
@ -97,7 +95,7 @@ module Homebrew
end
end
def handle_unsatisfied_dependents(kegs_by_rack, casks: [], ignore_dependencies: false, named_args: [])
def self.handle_unsatisfied_dependents(kegs_by_rack, casks: [], ignore_dependencies: false, named_args: [])
return if ignore_dependencies
all_kegs = kegs_by_rack.values.flatten(1)
@ -107,7 +105,7 @@ module Homebrew
nil
end
def check_for_dependents(kegs, casks: [], named_args: [])
def self.check_for_dependents(kegs, casks: [], named_args: [])
return false unless (result = InstalledDependents.find_some_installed_dependents(kegs, casks: casks))
if Homebrew::EnvConfig.developer?
@ -164,7 +162,7 @@ module Homebrew
end
end
def rm_pin(rack)
def self.rm_pin(rack)
Formulary.from_rack(rack).unpin
rescue
nil

View File

@ -1,7 +0,0 @@
# typed: strict
module Homebrew
module Uninstall
include Kernel
end
end

View File

@ -7,33 +7,31 @@ require "utils/tty"
#
# @api private
module Formatter
module_function
def arrow(string, color: nil)
def self.arrow(string, color: nil)
prefix("==>", string, color)
end
def headline(string, color: nil)
def self.headline(string, color: nil)
arrow("#{Tty.bold}#{string}#{Tty.reset}", color: color)
end
def identifier(string)
def self.identifier(string)
"#{Tty.green}#{string}#{Tty.default}"
end
def option(string)
def self.option(string)
"#{Tty.bold}#{string}#{Tty.reset}"
end
def success(string, label: nil)
def self.success(string, label: nil)
label(label, string, :green)
end
def warning(string, label: nil)
def self.warning(string, label: nil)
label(label, string, :yellow)
end
def error(string, label: nil)
def self.error(string, label: nil)
label(label, string, :red)
end
@ -50,7 +48,7 @@ module Formatter
# so we always wrap one word before an option.
# @see https://github.com/Homebrew/brew/pull/12672
# @see https://macromates.com/blog/2006/wrapping-text-with-regular-expressions/
def format_help_text(string, width: 172)
def self.format_help_text(string, width: 172)
desc = OPTION_DESC_WIDTH
indent = width - desc
string.gsub(/(?<=\S) *\n(?=\S)/, " ")
@ -60,17 +58,17 @@ module Formatter
.gsub(/(.{1,#{width}})( +|$)(?!-)\n?/, "\\1\n")
end
def url(string)
def self.url(string)
"#{Tty.underline}#{string}#{Tty.no_underline}"
end
def label(label, string, color)
def self.label(label, string, color)
label = "#{label}:" unless label.nil?
prefix(label, string, color)
end
private_class_method :label
def prefix(prefix, string, color)
def self.prefix(prefix, string, color)
if prefix.nil? && color.nil?
string
elsif prefix.nil?
@ -83,7 +81,7 @@ module Formatter
end
private_class_method :prefix
def columns(*objects, gap_size: 2)
def self.columns(*objects, gap_size: 2)
objects = objects.flatten.map(&:to_s)
fallback = proc do

View File

@ -1,5 +0,0 @@
# typed: strict
module Formatter
include Kernel
end

View File

@ -33,8 +33,6 @@ module GitHub
module API
extend T::Sig
module_function
# Generic API error.
class Error < RuntimeError
attr_reader :github_message
@ -119,7 +117,7 @@ module GitHub
# Gets the password field from `git-credential-osxkeychain` for github.com,
# but only if that password looks like a GitHub Personal Access Token.
sig { returns(T.nilable(String)) }
def keychain_username_password
def self.keychain_username_password
github_credentials = Utils.popen_write("git", "credential-osxkeychain", "get") do |pipe|
pipe.write "protocol=https\nhost=github.com\n"
end
@ -141,12 +139,12 @@ module GitHub
nil
end
def credentials
def self.credentials
@credentials ||= Homebrew::EnvConfig.github_api_token || keychain_username_password
end
sig { returns(Symbol) }
def credentials_type
def self.credentials_type
if Homebrew::EnvConfig.github_api_token
:env_token
elsif keychain_username_password
@ -158,7 +156,7 @@ module GitHub
# Given an API response from GitHub, warn the user if their credentials
# have insufficient permissions.
def credentials_error_message(response_headers, needed_scopes)
def self.credentials_error_message(response_headers, needed_scopes)
return if response_headers.empty?
scopes = response_headers["x-accepted-oauth-scopes"].to_s.split(", ")
@ -184,7 +182,7 @@ module GitHub
EOS
end
def open_rest(url, data: nil, data_binary_path: nil, request_method: nil, scopes: [].freeze, parse_json: true)
def self.open_rest(url, data: nil, data_binary_path: nil, request_method: nil, scopes: [].freeze, parse_json: true)
# This is a no-op if the user is opting out of using the GitHub API.
return block_given? ? yield({}) : {} if Homebrew::EnvConfig.no_github_api?
@ -253,7 +251,7 @@ module GitHub
end
end
def paginate_rest(url, additional_query_params: nil, per_page: 100)
def self.paginate_rest(url, additional_query_params: nil, per_page: 100)
(1..API_MAX_PAGES).each do |page|
result = API.open_rest("#{url}?per_page=#{per_page}&page=#{page}&#{additional_query_params}")
break if result.blank?
@ -262,7 +260,7 @@ module GitHub
end
end
def open_graphql(query, variables: nil, scopes: [].freeze, raise_errors: true)
def self.open_graphql(query, variables: nil, scopes: [].freeze, raise_errors: true)
data = { query: query, variables: variables }
result = open_rest("#{API_URL}/graphql", scopes: scopes, data: data, request_method: "POST")
@ -277,7 +275,7 @@ module GitHub
end
end
def raise_error(output, errors, http_code, headers, scopes)
def self.raise_error(output, errors, http_code, headers, scopes)
json = begin
JSON.parse(output)
rescue

View File

@ -1,5 +0,0 @@
# typed: strict
module GitHub::API
include Kernel
end

View File

@ -10,8 +10,6 @@ module Utils
module Gzip
extend T::Sig
module_function
sig {
params(
path: T.any(String, Pathname),
@ -20,7 +18,7 @@ module Utils
output: T.any(String, Pathname),
).returns(Pathname)
}
def compress_with_options(path, mtime: ENV["SOURCE_DATE_EPOCH"].to_i, orig_name: File.basename(path),
def self.compress_with_options(path, mtime: ENV["SOURCE_DATE_EPOCH"].to_i, orig_name: File.basename(path),
output: "#{path}.gz")
# Ideally, we would just set mtime = 0 if SOURCE_DATE_EPOCH is absent, but Ruby's
# Zlib::GzipWriter does not properly handle the case of setting mtime = 0:
@ -55,7 +53,7 @@ module Utils
mtime: T.any(Integer, Time),
).returns(T::Array[Pathname])
}
def compress(*paths, reproducible: true, mtime: ENV["SOURCE_DATE_EPOCH"].to_i)
def self.compress(*paths, reproducible: true, mtime: ENV["SOURCE_DATE_EPOCH"].to_i)
if reproducible
paths.map do |path|
compress_with_options(path, mtime: mtime)

View File

@ -1,7 +0,0 @@
# typed: strict
module Utils
module Gzip
include Kernel
end
end

View File

@ -20,8 +20,6 @@ module Utils
end
end
module_function
# Sometimes we have to change a bit before we install. Mostly we
# prefer a patch, but if you need the {Formula#prefix prefix} of
# this formula in the patch you have to resort to `inreplace`,
@ -47,7 +45,7 @@ module Utils
audit_result: T::Boolean,
).void
}
def inreplace(paths, before = nil, after = nil, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter
def self.inreplace(paths, before = nil, after = nil, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter
after = after.to_s if after.is_a? Symbol
errors = {}
@ -73,7 +71,7 @@ module Utils
end
# @api private
def inreplace_pairs(path, replacement_pairs, read_only_run: false, silent: false)
def self.inreplace_pairs(path, replacement_pairs, read_only_run: false, silent: false)
str = File.binread(path)
contents = StringInreplaceExtension.new(str)
replacement_pairs.each do |old, new|

View File

@ -1,7 +0,0 @@
# typed: strict
module Utils
module Inreplace
include Kernel
end
end

View File

@ -6,9 +6,7 @@ module Utils
#
# @api private
module Link
module_function
def link_src_dst_dirs(src_dir, dst_dir, command, link_dir: false)
def self.link_src_dst_dirs(src_dir, dst_dir, command, link_dir: false)
return unless src_dir.exist?
conflicts = []
@ -42,7 +40,7 @@ module Utils
end
private_class_method :link_src_dst_dirs
def unlink_src_dst_dirs(src_dir, dst_dir, unlink_dir: false)
def self.unlink_src_dst_dirs(src_dir, dst_dir, unlink_dir: false)
return unless src_dir.exist?
src_paths = unlink_dir ? [src_dir] : src_dir.find
@ -56,27 +54,27 @@ module Utils
end
private_class_method :unlink_src_dst_dirs
def link_manpages(path, command)
def self.link_manpages(path, command)
link_src_dst_dirs(path/"manpages", HOMEBREW_PREFIX/"share/man/man1", command)
end
def unlink_manpages(path)
def self.unlink_manpages(path)
unlink_src_dst_dirs(path/"manpages", HOMEBREW_PREFIX/"share/man/man1")
end
def link_completions(path, command)
def self.link_completions(path, command)
link_src_dst_dirs(path/"completions/bash", HOMEBREW_PREFIX/"etc/bash_completion.d", command)
link_src_dst_dirs(path/"completions/zsh", HOMEBREW_PREFIX/"share/zsh/site-functions", command)
link_src_dst_dirs(path/"completions/fish", HOMEBREW_PREFIX/"share/fish/vendor_completions.d", command)
end
def unlink_completions(path)
def self.unlink_completions(path)
unlink_src_dst_dirs(path/"completions/bash", HOMEBREW_PREFIX/"etc/bash_completion.d")
unlink_src_dst_dirs(path/"completions/zsh", HOMEBREW_PREFIX/"share/zsh/site-functions")
unlink_src_dst_dirs(path/"completions/fish", HOMEBREW_PREFIX/"share/fish/vendor_completions.d")
end
def link_docs(path, command)
def self.link_docs(path, command)
link_src_dst_dirs(path/"docs", HOMEBREW_PREFIX/"share/doc/homebrew", command, link_dir: true)
end
end

View File

@ -1,7 +0,0 @@
# typed: strict
module Utils
module Link
include Kernel
end
end

View File

@ -9,13 +9,10 @@ require "utils/curl"
module Repology
HOMEBREW_CORE = "homebrew"
HOMEBREW_CASK = "homebrew_casks"
module_function
MAX_PAGINATION = 15
private_constant :MAX_PAGINATION
def query_api(last_package_in_response = "", repository:)
def self.query_api(last_package_in_response = "", repository:)
last_package_in_response += "/" if last_package_in_response.present?
url = "https://repology.org/api/v1/projects/#{last_package_in_response}?inrepo=#{repository}&outdated=1"
@ -31,7 +28,7 @@ module Repology
raise
end
def single_package_query(name, repository:)
def self.single_package_query(name, repository:)
url = "https://repology.org/tools/project-by?repo=#{repository}&" \
"name_type=srcname&target_page=api_v1_project&name=#{name}"
@ -50,7 +47,7 @@ module Repology
nil
end
def parse_api_response(limit = nil, last_package = "", repository:)
def self.parse_api_response(limit = nil, last_package = "", repository:)
package_term = case repository
when HOMEBREW_CORE
"formulae"
@ -83,7 +80,7 @@ module Repology
outdated_packages.sort.to_h
end
def latest_version(repositories)
def self.latest_version(repositories)
# The status is "unique" when the package is present only in Homebrew, so
# Repology has no way of knowing if the package is up-to-date.
is_unique = repositories.find do |repo|

View File

@ -1,6 +0,0 @@
# typed: strict
module Repology
include Kernel
requires_ancestor { Utils::Curl }
end

View File

@ -8,8 +8,6 @@ module Utils
module Shebang
extend T::Sig
module_function
# Specification on how to rewrite a given shebang.
#
# @api private
@ -33,7 +31,7 @@ module Utils
#
# @api public
sig { params(rewrite_info: RewriteInfo, paths: T::Array[T.any(String, Pathname)]).void }
def rewrite_shebang(rewrite_info, *paths)
def self.rewrite_shebang(rewrite_info, *paths)
paths.each do |f|
f = Pathname(f)
next unless f.file?

View File

@ -1,7 +0,0 @@
# typed: strict
module Utils
module Shebang
include Kernel
end
end

View File

@ -5,12 +5,10 @@ module Utils
module Shell
extend T::Sig
module_function
# Take a path and heuristically convert it to a shell name,
# return `nil` if there's no match.
sig { params(path: String).returns(T.nilable(Symbol)) }
def from_path(path)
def self.from_path(path)
# we only care about the basename
shell_name = File.basename(path)
# handle possible version suffix like `zsh-5.2`
@ -19,23 +17,23 @@ module Utils
end
sig { params(default: String).returns(String) }
def preferred_path(default: "")
def self.preferred_path(default: "")
ENV.fetch("SHELL", default)
end
sig { returns(T.nilable(Symbol)) }
def preferred
def self.preferred
from_path(preferred_path)
end
sig { returns(T.nilable(Symbol)) }
def parent
def self.parent
from_path(`ps -p #{Process.ppid} -o ucomm=`.strip)
end
# Quote values. Quoting keys is overkill.
sig { params(key: String, value: String, shell: T.nilable(Symbol)).returns(T.nilable(String)) }
def export_value(key, value, shell = preferred)
def self.export_value(key, value, shell = preferred)
case shell
when :bash, :ksh, :mksh, :sh, :zsh
"export #{key}=\"#{sh_quote(value)}\""
@ -51,7 +49,7 @@ module Utils
# Return the shell profile file based on user's preferred shell.
sig { returns(String) }
def profile
def self.profile
case preferred
when :bash
bash_profile = "#{Dir.home}/.bash_profile"
@ -64,7 +62,7 @@ module Utils
end
sig { params(variable: String, value: String).returns(T.nilable(String)) }
def set_variable_in_profile(variable, value)
def self.set_variable_in_profile(variable, value)
case preferred
when :bash, :ksh, :sh, :zsh, nil
"echo 'export #{variable}=#{sh_quote(value)}' >> #{profile}"
@ -76,7 +74,7 @@ module Utils
end
sig { params(path: String).returns(T.nilable(String)) }
def prepend_path_in_profile(path)
def self.prepend_path_in_profile(path)
case preferred
when :bash, :ksh, :mksh, :sh, :zsh, nil
"echo 'export PATH=\"#{sh_quote(path)}:$PATH\"' >> #{profile}"
@ -101,7 +99,7 @@ module Utils
UNSAFE_SHELL_CHAR = %r{([^A-Za-z0-9_\-.,:/@~\n])}.freeze
sig { params(str: String).returns(String) }
def csh_quote(str)
def self.csh_quote(str)
# ruby's implementation of shell_escape
str = str.to_s
return "''" if str.empty?
@ -115,7 +113,7 @@ module Utils
end
sig { params(str: String).returns(String) }
def sh_quote(str)
def self.sh_quote(str)
# ruby's implementation of shell_escape
str = str.to_s
return "''" if str.empty?

View File

@ -1,7 +0,0 @@
# typed: strict
module Utils
module Shell
include Kernel
end
end

View File

@ -7,8 +7,6 @@ require "warning"
#
# @api private
module Warnings
module_function
COMMON_WARNINGS = {
parser_syntax: [
%r{warning: parser/current is loading parser/ruby\d+, which recognizes},
@ -17,7 +15,7 @@ module Warnings
],
}.freeze
def ignore(*warnings)
def self.ignore(*warnings)
warnings.map! do |warning|
next warning if !warning.is_a?(Symbol) || !COMMON_WARNINGS.key?(warning)

View File

@ -1,5 +0,0 @@
# typed: strict
module Warnings
include Kernel
end