diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 24bf1287b4..99dc96c56a 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -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 or . Additional options specific to a may be @@ -146,7 +144,7 @@ module Homebrew end end - def install + def self.install args = install_args.parse if args.env.present? diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index dc09ab35ec..507dbb61d6 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -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 or 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) diff --git a/Library/Homebrew/commands.rb b/Library/Homebrew/commands.rb index 6b0de992a4..993490144e 100644 --- a/Library/Homebrew/commands.rb +++ b/Library/Homebrew/commands.rb @@ -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? diff --git a/Library/Homebrew/commands.rbi b/Library/Homebrew/commands.rbi deleted file mode 100644 index 13522bd09f..0000000000 --- a/Library/Homebrew/commands.rbi +++ /dev/null @@ -1,5 +0,0 @@ -# typed: strict - -module Commands - include Kernel -end diff --git a/Library/Homebrew/completions.rb b/Library/Homebrew/completions.rb index e7fca41fc7..e928a5b837 100644 --- a/Library/Homebrew/completions.rb +++ b/Library/Homebrew/completions.rb @@ -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 diff --git a/Library/Homebrew/completions.rbi b/Library/Homebrew/completions.rbi deleted file mode 100644 index 8c4746bcaf..0000000000 --- a/Library/Homebrew/completions.rbi +++ /dev/null @@ -1,7 +0,0 @@ -# typed: strict - -module Homebrew - module Completions - include Kernel - end -end diff --git a/Library/Homebrew/extend/os/linux/install.rb b/Library/Homebrew/extend/os/linux/install.rb index 2202386424..cc8a6b4715 100644 --- a/Library/Homebrew/extend/os/linux/install.rb +++ b/Library/Homebrew/extend/os/linux/install.rb @@ -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? diff --git a/Library/Homebrew/help.rb b/Library/Homebrew/help.rb index fba154d8e0..a90d5a2d49 100644 --- a/Library/Homebrew/help.rb +++ b/Library/Homebrew/help.rb @@ -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? diff --git a/Library/Homebrew/help.rbi b/Library/Homebrew/help.rbi deleted file mode 100644 index 9db873c525..0000000000 --- a/Library/Homebrew/help.rbi +++ /dev/null @@ -1,7 +0,0 @@ -# typed: strict - -module Homebrew - module Help - include Kernel - end -end diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index fdf31bbe8a..49ace9b935 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -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" diff --git a/Library/Homebrew/install.rbi b/Library/Homebrew/install.rbi deleted file mode 100644 index 5208127284..0000000000 --- a/Library/Homebrew/install.rbi +++ /dev/null @@ -1,7 +0,0 @@ -# typed: strict - -module Homebrew - module Install - include Kernel - end -end diff --git a/Library/Homebrew/language/perl.rb b/Library/Homebrew/language/perl.rb index f4822239ad..3aea71dbf5 100644 --- a/Library/Homebrew/language/perl.rb +++ b/Library/Homebrew/language/perl.rb @@ -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" diff --git a/Library/Homebrew/language/perl.rbi b/Library/Homebrew/language/perl.rbi deleted file mode 100644 index 9be98f1896..0000000000 --- a/Library/Homebrew/language/perl.rbi +++ /dev/null @@ -1,9 +0,0 @@ -# typed: strict - -module Language - module Perl - module Shebang - include Kernel - end - end -end diff --git a/Library/Homebrew/language/python.rb b/Library/Homebrew/language/python.rb index b8d890e840..a5082f2f90 100644 --- a/Library/Homebrew/language/python.rb +++ b/Library/Homebrew/language/python.rb @@ -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 diff --git a/Library/Homebrew/language/python.rbi b/Library/Homebrew/language/python.rbi index ab011b8db7..ad9e51f69d 100644 --- a/Library/Homebrew/language/python.rbi +++ b/Library/Homebrew/language/python.rbi @@ -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 diff --git a/Library/Homebrew/manpages.rb b/Library/Homebrew/manpages.rb index 42b91bc3ac..3787ef826e 100644 --- a/Library/Homebrew/manpages.rb +++ b/Library/Homebrew/manpages.rb @@ -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
#{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 diff --git a/Library/Homebrew/manpages.rbi b/Library/Homebrew/manpages.rbi deleted file mode 100644 index d3765f73a3..0000000000 --- a/Library/Homebrew/manpages.rbi +++ /dev/null @@ -1,7 +0,0 @@ -# typed: strict - -module Homebrew - module Manpages - include Kernel - end -end diff --git a/Library/Homebrew/os/linux.rb b/Library/Homebrew/os/linux.rb index 2b5df8cfc3..cf03b80ada 100644 --- a/Library/Homebrew/os/linux.rb +++ b/Library/Homebrew/os/linux.rb @@ -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 diff --git a/Library/Homebrew/os/linux.rbi b/Library/Homebrew/os/linux.rbi deleted file mode 100644 index b6f3164683..0000000000 --- a/Library/Homebrew/os/linux.rbi +++ /dev/null @@ -1,7 +0,0 @@ -# typed: strict - -module OS - module Linux - include ::Kernel - end -end diff --git a/Library/Homebrew/os/mac.rb b/Library/Homebrew/os/mac.rb index b52a965130..4b6eeffe23 100644 --- a/Library/Homebrew/os/mac.rb +++ b/Library/Homebrew/os/mac.rb @@ -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 diff --git a/Library/Homebrew/os/mac.rbi b/Library/Homebrew/os/mac.rbi deleted file mode 100644 index 85a546f554..0000000000 --- a/Library/Homebrew/os/mac.rbi +++ /dev/null @@ -1,7 +0,0 @@ -# typed: strict - -module OS - module Mac - include Kernel - end -end diff --git a/Library/Homebrew/os/mac/xcode.rb b/Library/Homebrew/os/mac/xcode.rb index 6e234f8268..70f610e63e 100755 --- a/Library/Homebrew/os/mac/xcode.rb +++ b/Library/Homebrew/os/mac/xcode.rb @@ -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") diff --git a/Library/Homebrew/os/mac/xcode.rbi b/Library/Homebrew/os/mac/xcode.rbi deleted file mode 100644 index b0707a034e..0000000000 --- a/Library/Homebrew/os/mac/xcode.rbi +++ /dev/null @@ -1,9 +0,0 @@ -# typed: strict - -module OS - module Mac - module Xcode - include Kernel - end - end -end diff --git a/Library/Homebrew/search.rb b/Library/Homebrew/search.rb index 94175561a2..14f8d15f01 100644 --- a/Library/Homebrew/search.rb +++ b/Library/Homebrew/search.rb @@ -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? diff --git a/Library/Homebrew/search.rbi b/Library/Homebrew/search.rbi deleted file mode 100644 index 2c8f4bdb6e..0000000000 --- a/Library/Homebrew/search.rbi +++ /dev/null @@ -1,5 +0,0 @@ -# typed: strict - -module Homebrew::Search - include Kernel -end diff --git a/Library/Homebrew/settings.rb b/Library/Homebrew/settings.rb index f04820eef2..4e5914899d 100644 --- a/Library/Homebrew/settings.rb +++ b/Library/Homebrew/settings.rb @@ -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? diff --git a/Library/Homebrew/settings.rbi b/Library/Homebrew/settings.rbi deleted file mode 100644 index d902c06acb..0000000000 --- a/Library/Homebrew/settings.rbi +++ /dev/null @@ -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 diff --git a/Library/Homebrew/uninstall.rb b/Library/Homebrew/uninstall.rb index a6f366f448..73578c5ce2 100644 --- a/Library/Homebrew/uninstall.rb +++ b/Library/Homebrew/uninstall.rb @@ -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 diff --git a/Library/Homebrew/uninstall.rbi b/Library/Homebrew/uninstall.rbi deleted file mode 100644 index f801c23a87..0000000000 --- a/Library/Homebrew/uninstall.rbi +++ /dev/null @@ -1,7 +0,0 @@ -# typed: strict - -module Homebrew - module Uninstall - include Kernel - end -end diff --git a/Library/Homebrew/utils/formatter.rb b/Library/Homebrew/utils/formatter.rb index 870364c142..33b8909ea3 100644 --- a/Library/Homebrew/utils/formatter.rb +++ b/Library/Homebrew/utils/formatter.rb @@ -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 diff --git a/Library/Homebrew/utils/formatter.rbi b/Library/Homebrew/utils/formatter.rbi deleted file mode 100644 index e9038dd0f3..0000000000 --- a/Library/Homebrew/utils/formatter.rbi +++ /dev/null @@ -1,5 +0,0 @@ -# typed: strict - -module Formatter - include Kernel -end diff --git a/Library/Homebrew/utils/github/api.rb b/Library/Homebrew/utils/github/api.rb index 0d122975a9..9155b86797 100644 --- a/Library/Homebrew/utils/github/api.rb +++ b/Library/Homebrew/utils/github/api.rb @@ -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 diff --git a/Library/Homebrew/utils/github/api.rbi b/Library/Homebrew/utils/github/api.rbi deleted file mode 100644 index bb72675c19..0000000000 --- a/Library/Homebrew/utils/github/api.rbi +++ /dev/null @@ -1,5 +0,0 @@ -# typed: strict - -module GitHub::API - include Kernel -end diff --git a/Library/Homebrew/utils/gzip.rb b/Library/Homebrew/utils/gzip.rb index b5cbd04fa7..18a649751c 100644 --- a/Library/Homebrew/utils/gzip.rb +++ b/Library/Homebrew/utils/gzip.rb @@ -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) diff --git a/Library/Homebrew/utils/gzip.rbi b/Library/Homebrew/utils/gzip.rbi deleted file mode 100644 index 7b7201eaca..0000000000 --- a/Library/Homebrew/utils/gzip.rbi +++ /dev/null @@ -1,7 +0,0 @@ -# typed: strict - -module Utils - module Gzip - include Kernel - end -end diff --git a/Library/Homebrew/utils/inreplace.rb b/Library/Homebrew/utils/inreplace.rb index 50ff78f80b..354b11c8f7 100644 --- a/Library/Homebrew/utils/inreplace.rb +++ b/Library/Homebrew/utils/inreplace.rb @@ -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| diff --git a/Library/Homebrew/utils/inreplace.rbi b/Library/Homebrew/utils/inreplace.rbi deleted file mode 100644 index 02542091d2..0000000000 --- a/Library/Homebrew/utils/inreplace.rbi +++ /dev/null @@ -1,7 +0,0 @@ -# typed: strict - -module Utils - module Inreplace - include Kernel - end -end diff --git a/Library/Homebrew/utils/link.rb b/Library/Homebrew/utils/link.rb index c33d5ca335..d166878bc3 100644 --- a/Library/Homebrew/utils/link.rb +++ b/Library/Homebrew/utils/link.rb @@ -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 diff --git a/Library/Homebrew/utils/link.rbi b/Library/Homebrew/utils/link.rbi deleted file mode 100644 index 0b88a48d16..0000000000 --- a/Library/Homebrew/utils/link.rbi +++ /dev/null @@ -1,7 +0,0 @@ -# typed: strict - -module Utils - module Link - include Kernel - end -end diff --git a/Library/Homebrew/utils/repology.rb b/Library/Homebrew/utils/repology.rb index dc9fc61cec..b40a05cc03 100644 --- a/Library/Homebrew/utils/repology.rb +++ b/Library/Homebrew/utils/repology.rb @@ -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| diff --git a/Library/Homebrew/utils/repology.rbi b/Library/Homebrew/utils/repology.rbi deleted file mode 100644 index 57ed1c467f..0000000000 --- a/Library/Homebrew/utils/repology.rbi +++ /dev/null @@ -1,6 +0,0 @@ -# typed: strict - -module Repology - include Kernel - requires_ancestor { Utils::Curl } -end diff --git a/Library/Homebrew/utils/shebang.rb b/Library/Homebrew/utils/shebang.rb index edf36e0f0c..22cf7f2c62 100644 --- a/Library/Homebrew/utils/shebang.rb +++ b/Library/Homebrew/utils/shebang.rb @@ -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? diff --git a/Library/Homebrew/utils/shebang.rbi b/Library/Homebrew/utils/shebang.rbi deleted file mode 100644 index 9cdb0b2007..0000000000 --- a/Library/Homebrew/utils/shebang.rbi +++ /dev/null @@ -1,7 +0,0 @@ -# typed: strict - -module Utils - module Shebang - include Kernel - end -end diff --git a/Library/Homebrew/utils/shell.rb b/Library/Homebrew/utils/shell.rb index 4fe444be02..c27dac0562 100644 --- a/Library/Homebrew/utils/shell.rb +++ b/Library/Homebrew/utils/shell.rb @@ -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? diff --git a/Library/Homebrew/utils/shell.rbi b/Library/Homebrew/utils/shell.rbi deleted file mode 100644 index b860bc1190..0000000000 --- a/Library/Homebrew/utils/shell.rbi +++ /dev/null @@ -1,7 +0,0 @@ -# typed: strict - -module Utils - module Shell - include Kernel - end -end diff --git a/Library/Homebrew/warnings.rb b/Library/Homebrew/warnings.rb index f0a3ed116f..28387659a8 100644 --- a/Library/Homebrew/warnings.rb +++ b/Library/Homebrew/warnings.rb @@ -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) diff --git a/Library/Homebrew/warnings.rbi b/Library/Homebrew/warnings.rbi deleted file mode 100644 index 5d83b4cc35..0000000000 --- a/Library/Homebrew/warnings.rbi +++ /dev/null @@ -1,5 +0,0 @@ -# typed: strict - -module Warnings - include Kernel -end