mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Refactor module_function to reduce rbi need
This commit is contained in:
parent
e98bfdd012
commit
09c679e75f
@ -15,10 +15,8 @@ require "upgrade"
|
|||||||
module Homebrew
|
module Homebrew
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
|
|
||||||
module_function
|
|
||||||
|
|
||||||
sig { returns(CLI::Parser) }
|
sig { returns(CLI::Parser) }
|
||||||
def install_args
|
def self.install_args
|
||||||
Homebrew::CLI::Parser.new do
|
Homebrew::CLI::Parser.new do
|
||||||
description <<~EOS
|
description <<~EOS
|
||||||
Install a <formula> or <cask>. Additional options specific to a <formula> may be
|
Install a <formula> or <cask>. Additional options specific to a <formula> may be
|
||||||
@ -146,7 +144,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def install
|
def self.install
|
||||||
args = install_args.parse
|
args = install_args.parse
|
||||||
|
|
||||||
if args.env.present?
|
if args.env.present?
|
||||||
|
@ -18,10 +18,8 @@ require "api"
|
|||||||
module Homebrew
|
module Homebrew
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
|
|
||||||
module_function
|
|
||||||
|
|
||||||
sig { returns(CLI::Parser) }
|
sig { returns(CLI::Parser) }
|
||||||
def reinstall_args
|
def self.reinstall_args
|
||||||
Homebrew::CLI::Parser.new do
|
Homebrew::CLI::Parser.new do
|
||||||
description <<~EOS
|
description <<~EOS
|
||||||
Uninstall and then reinstall a <formula> or <cask> using the same options it was
|
Uninstall and then reinstall a <formula> or <cask> using the same options it was
|
||||||
@ -92,7 +90,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def reinstall
|
def self.reinstall
|
||||||
args = reinstall_args.parse
|
args = reinstall_args.parse
|
||||||
|
|
||||||
formulae, casks = args.named.to_formulae_and_casks(method: :resolve)
|
formulae, casks = args.named.to_formulae_and_casks(method: :resolve)
|
||||||
|
@ -7,8 +7,6 @@ require "completions"
|
|||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
module Commands
|
module Commands
|
||||||
module_function
|
|
||||||
|
|
||||||
HOMEBREW_CMD_PATH = (HOMEBREW_LIBRARY_PATH/"cmd").freeze
|
HOMEBREW_CMD_PATH = (HOMEBREW_LIBRARY_PATH/"cmd").freeze
|
||||||
HOMEBREW_DEV_CMD_PATH = (HOMEBREW_LIBRARY_PATH/"dev-cmd").freeze
|
HOMEBREW_DEV_CMD_PATH = (HOMEBREW_LIBRARY_PATH/"dev-cmd").freeze
|
||||||
# If you are going to change anything in below hash,
|
# If you are going to change anything in below hash,
|
||||||
@ -38,35 +36,35 @@ module Commands
|
|||||||
# middle due to dots in URLs or paths.
|
# middle due to dots in URLs or paths.
|
||||||
DESCRIPTION_SPLITTING_PATTERN = /\.(?>\s|$)/.freeze
|
DESCRIPTION_SPLITTING_PATTERN = /\.(?>\s|$)/.freeze
|
||||||
|
|
||||||
def valid_internal_cmd?(cmd)
|
def self.valid_internal_cmd?(cmd)
|
||||||
require?(HOMEBREW_CMD_PATH/cmd)
|
require?(HOMEBREW_CMD_PATH/cmd)
|
||||||
end
|
end
|
||||||
|
|
||||||
def valid_internal_dev_cmd?(cmd)
|
def self.valid_internal_dev_cmd?(cmd)
|
||||||
require?(HOMEBREW_DEV_CMD_PATH/cmd)
|
require?(HOMEBREW_DEV_CMD_PATH/cmd)
|
||||||
end
|
end
|
||||||
|
|
||||||
def method_name(cmd)
|
def self.method_name(cmd)
|
||||||
cmd.to_s
|
cmd.to_s
|
||||||
.tr("-", "_")
|
.tr("-", "_")
|
||||||
.downcase
|
.downcase
|
||||||
.to_sym
|
.to_sym
|
||||||
end
|
end
|
||||||
|
|
||||||
def args_method_name(cmd_path)
|
def self.args_method_name(cmd_path)
|
||||||
cmd_path_basename = basename_without_extension(cmd_path)
|
cmd_path_basename = basename_without_extension(cmd_path)
|
||||||
cmd_method_prefix = method_name(cmd_path_basename)
|
cmd_method_prefix = method_name(cmd_path_basename)
|
||||||
"#{cmd_method_prefix}_args".to_sym
|
"#{cmd_method_prefix}_args".to_sym
|
||||||
end
|
end
|
||||||
|
|
||||||
def internal_cmd_path(cmd)
|
def self.internal_cmd_path(cmd)
|
||||||
[
|
[
|
||||||
HOMEBREW_CMD_PATH/"#{cmd}.rb",
|
HOMEBREW_CMD_PATH/"#{cmd}.rb",
|
||||||
HOMEBREW_CMD_PATH/"#{cmd}.sh",
|
HOMEBREW_CMD_PATH/"#{cmd}.sh",
|
||||||
].find(&:exist?)
|
].find(&:exist?)
|
||||||
end
|
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}.rb",
|
||||||
HOMEBREW_DEV_CMD_PATH/"#{cmd}.sh",
|
HOMEBREW_DEV_CMD_PATH/"#{cmd}.sh",
|
||||||
@ -74,21 +72,21 @@ module Commands
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Ruby commands which can be `require`d without being run.
|
# 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 = which("#{cmd}.rb", Tap.cmd_directories)
|
||||||
path if require?(path)
|
path if require?(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Ruby commands which are run by being `require`d.
|
# 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))
|
which("brew-#{cmd}.rb", PATH.new(ENV.fetch("PATH")).append(Tap.cmd_directories))
|
||||||
end
|
end
|
||||||
|
|
||||||
def external_cmd_path(cmd)
|
def self.external_cmd_path(cmd)
|
||||||
which("brew-#{cmd}", PATH.new(ENV.fetch("PATH")).append(Tap.cmd_directories))
|
which("brew-#{cmd}", PATH.new(ENV.fetch("PATH")).append(Tap.cmd_directories))
|
||||||
end
|
end
|
||||||
|
|
||||||
def path(cmd)
|
def self.path(cmd)
|
||||||
internal_cmd = HOMEBREW_INTERNAL_COMMAND_ALIASES.fetch(cmd, cmd)
|
internal_cmd = HOMEBREW_INTERNAL_COMMAND_ALIASES.fetch(cmd, cmd)
|
||||||
path ||= internal_cmd_path(internal_cmd)
|
path ||= internal_cmd_path(internal_cmd)
|
||||||
path ||= internal_dev_cmd_path(internal_cmd)
|
path ||= internal_dev_cmd_path(internal_cmd)
|
||||||
@ -98,7 +96,7 @@ module Commands
|
|||||||
path
|
path
|
||||||
end
|
end
|
||||||
|
|
||||||
def commands(external: true, aliases: false)
|
def self.commands(external: true, aliases: false)
|
||||||
cmds = internal_commands
|
cmds = internal_commands
|
||||||
cmds += internal_developer_commands
|
cmds += internal_developer_commands
|
||||||
cmds += external_commands if external
|
cmds += external_commands if external
|
||||||
@ -106,15 +104,15 @@ module Commands
|
|||||||
cmds.sort
|
cmds.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
def internal_commands_paths
|
def self.internal_commands_paths
|
||||||
find_commands HOMEBREW_CMD_PATH
|
find_commands HOMEBREW_CMD_PATH
|
||||||
end
|
end
|
||||||
|
|
||||||
def internal_developer_commands_paths
|
def self.internal_developer_commands_paths
|
||||||
find_commands HOMEBREW_DEV_CMD_PATH
|
find_commands HOMEBREW_DEV_CMD_PATH
|
||||||
end
|
end
|
||||||
|
|
||||||
def official_external_commands_paths(quiet:)
|
def self.official_external_commands_paths(quiet:)
|
||||||
OFFICIAL_CMD_TAPS.flat_map do |tap_name, cmds|
|
OFFICIAL_CMD_TAPS.flat_map do |tap_name, cmds|
|
||||||
tap = Tap.fetch(tap_name)
|
tap = Tap.fetch(tap_name)
|
||||||
tap.install(quiet: quiet) unless tap.installed?
|
tap.install(quiet: quiet) unless tap.installed?
|
||||||
@ -122,24 +120,24 @@ module Commands
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def internal_commands
|
def self.internal_commands
|
||||||
find_internal_commands(HOMEBREW_CMD_PATH).map(&:to_s)
|
find_internal_commands(HOMEBREW_CMD_PATH).map(&:to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
def internal_developer_commands
|
def self.internal_developer_commands
|
||||||
find_internal_commands(HOMEBREW_DEV_CMD_PATH).map(&:to_s)
|
find_internal_commands(HOMEBREW_DEV_CMD_PATH).map(&:to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
def internal_commands_aliases
|
def self.internal_commands_aliases
|
||||||
HOMEBREW_INTERNAL_COMMAND_ALIASES.keys
|
HOMEBREW_INTERNAL_COMMAND_ALIASES.keys
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_internal_commands(path)
|
def self.find_internal_commands(path)
|
||||||
find_commands(path).map(&:basename)
|
find_commands(path).map(&:basename)
|
||||||
.map(&method(:basename_without_extension))
|
.map(&method(:basename_without_extension))
|
||||||
end
|
end
|
||||||
|
|
||||||
def external_commands
|
def self.external_commands
|
||||||
Tap.cmd_directories.flat_map do |path|
|
Tap.cmd_directories.flat_map do |path|
|
||||||
find_commands(path).select(&:executable?)
|
find_commands(path).select(&:executable?)
|
||||||
.map(&method(:basename_without_extension))
|
.map(&method(:basename_without_extension))
|
||||||
@ -148,17 +146,17 @@ module Commands
|
|||||||
.sort
|
.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
def basename_without_extension(path)
|
def self.basename_without_extension(path)
|
||||||
path.basename(path.extname)
|
path.basename(path.extname)
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_commands(path)
|
def self.find_commands(path)
|
||||||
Pathname.glob("#{path}/*")
|
Pathname.glob("#{path}/*")
|
||||||
.select(&:file?)
|
.select(&:file?)
|
||||||
.sort
|
.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
def rebuild_internal_commands_completion_list
|
def self.rebuild_internal_commands_completion_list
|
||||||
cmds = internal_commands + internal_developer_commands + internal_commands_aliases
|
cmds = internal_commands + internal_developer_commands + internal_commands_aliases
|
||||||
cmds.reject! { |cmd| Homebrew::Completions::COMPLETIONS_EXCLUSION_LIST.include? cmd }
|
cmds.reject! { |cmd| Homebrew::Completions::COMPLETIONS_EXCLUSION_LIST.include? cmd }
|
||||||
|
|
||||||
@ -166,7 +164,7 @@ module Commands
|
|||||||
file.atomic_write("#{cmds.sort.join("\n")}\n")
|
file.atomic_write("#{cmds.sort.join("\n")}\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
def rebuild_commands_completion_list
|
def self.rebuild_commands_completion_list
|
||||||
# Ensure that the cache exists so we can build the commands list
|
# Ensure that the cache exists so we can build the commands list
|
||||||
HOMEBREW_CACHE.mkpath
|
HOMEBREW_CACHE.mkpath
|
||||||
|
|
||||||
@ -178,7 +176,7 @@ module Commands
|
|||||||
external_commands_file.atomic_write("#{external_commands.sort.join("\n")}\n")
|
external_commands_file.atomic_write("#{external_commands.sort.join("\n")}\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
def command_options(command)
|
def self.command_options(command)
|
||||||
path = self.path(command)
|
path = self.path(command)
|
||||||
return if path.blank?
|
return if path.blank?
|
||||||
|
|
||||||
@ -202,7 +200,7 @@ module Commands
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def command_description(command, short: false)
|
def self.command_description(command, short: false)
|
||||||
path = self.path(command)
|
path = self.path(command)
|
||||||
return if path.blank?
|
return if path.blank?
|
||||||
|
|
||||||
@ -228,7 +226,7 @@ module Commands
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def named_args_type(command)
|
def self.named_args_type(command)
|
||||||
path = self.path(command)
|
path = self.path(command)
|
||||||
return if path.blank?
|
return if path.blank?
|
||||||
|
|
||||||
@ -239,7 +237,7 @@ module Commands
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Returns the conflicts of a given `option` for `command`.
|
# Returns the conflicts of a given `option` for `command`.
|
||||||
def option_conflicts(command, option)
|
def self.option_conflicts(command, option)
|
||||||
path = self.path(command)
|
path = self.path(command)
|
||||||
return if path.blank?
|
return if path.blank?
|
||||||
|
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
|
|
||||||
module Commands
|
|
||||||
include Kernel
|
|
||||||
end
|
|
@ -20,8 +20,6 @@ module Homebrew
|
|||||||
keyword_init: true,
|
keyword_init: true,
|
||||||
)
|
)
|
||||||
|
|
||||||
module_function
|
|
||||||
|
|
||||||
COMPLETIONS_DIR = (HOMEBREW_REPOSITORY/"completions").freeze
|
COMPLETIONS_DIR = (HOMEBREW_REPOSITORY/"completions").freeze
|
||||||
TEMPLATE_DIR = (HOMEBREW_LIBRARY_PATH/"completions").freeze
|
TEMPLATE_DIR = (HOMEBREW_LIBRARY_PATH/"completions").freeze
|
||||||
|
|
||||||
@ -74,7 +72,7 @@ module Homebrew
|
|||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
sig { void }
|
sig { void }
|
||||||
def link!
|
def self.link!
|
||||||
Settings.write :linkcompletions, true
|
Settings.write :linkcompletions, true
|
||||||
Tap.each do |tap|
|
Tap.each do |tap|
|
||||||
Utils::Link.link_completions tap.path, "brew completions link"
|
Utils::Link.link_completions tap.path, "brew completions link"
|
||||||
@ -82,7 +80,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { void }
|
sig { void }
|
||||||
def unlink!
|
def self.unlink!
|
||||||
Settings.write :linkcompletions, false
|
Settings.write :linkcompletions, false
|
||||||
Tap.each do |tap|
|
Tap.each do |tap|
|
||||||
next if tap.official?
|
next if tap.official?
|
||||||
@ -92,12 +90,12 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def link_completions?
|
def self.link_completions?
|
||||||
Settings.read(:linkcompletions) == "true"
|
Settings.read(:linkcompletions) == "true"
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def completions_to_link?
|
def self.completions_to_link?
|
||||||
Tap.each do |tap|
|
Tap.each do |tap|
|
||||||
next if tap.official?
|
next if tap.official?
|
||||||
|
|
||||||
@ -110,7 +108,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { void }
|
sig { void }
|
||||||
def show_completions_message_if_needed
|
def self.show_completions_message_if_needed
|
||||||
return if Settings.read(:completionsmessageshown) == "true"
|
return if Settings.read(:completionsmessageshown) == "true"
|
||||||
return unless completions_to_link?
|
return unless completions_to_link?
|
||||||
|
|
||||||
@ -125,7 +123,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { void }
|
sig { void }
|
||||||
def update_shell_completions!
|
def self.update_shell_completions!
|
||||||
commands = Commands.commands(external: false, aliases: true).sort
|
commands = Commands.commands(external: false, aliases: true).sort
|
||||||
|
|
||||||
puts "Writing completions to #{COMPLETIONS_DIR}"
|
puts "Writing completions to #{COMPLETIONS_DIR}"
|
||||||
@ -136,12 +134,12 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { params(command: String).returns(T::Boolean) }
|
sig { params(command: String).returns(T::Boolean) }
|
||||||
def command_gets_completions?(command)
|
def self.command_gets_completions?(command)
|
||||||
command_options(command).any?
|
command_options(command).any?
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(description: String, fish: T::Boolean).returns(String) }
|
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 = if fish
|
||||||
description.gsub("'", "\\\\'")
|
description.gsub("'", "\\\\'")
|
||||||
else
|
else
|
||||||
@ -151,7 +149,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { params(command: String).returns(T::Hash[String, String]) }
|
sig { params(command: String).returns(T::Hash[String, String]) }
|
||||||
def command_options(command)
|
def self.command_options(command)
|
||||||
options = {}
|
options = {}
|
||||||
Commands.command_options(command)&.each do |option|
|
Commands.command_options(command)&.each do |option|
|
||||||
next if option.blank?
|
next if option.blank?
|
||||||
@ -169,7 +167,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { params(command: String).returns(T.nilable(String)) }
|
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
|
return unless command_gets_completions? command
|
||||||
|
|
||||||
named_completion_string = ""
|
named_completion_string = ""
|
||||||
@ -202,7 +200,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { params(commands: T::Array[String]).returns(String) }
|
sig { params(commands: T::Array[String]).returns(String) }
|
||||||
def generate_bash_completion_file(commands)
|
def self.generate_bash_completion_file(commands)
|
||||||
variables = Variables.new(
|
variables = Variables.new(
|
||||||
completion_functions: commands.map do |command|
|
completion_functions: commands.map do |command|
|
||||||
generate_bash_subcommand_completion command
|
generate_bash_subcommand_completion command
|
||||||
@ -218,7 +216,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { params(command: String).returns(T.nilable(String)) }
|
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
|
return unless command_gets_completions? command
|
||||||
|
|
||||||
options = command_options(command)
|
options = command_options(command)
|
||||||
@ -270,7 +268,7 @@ module Homebrew
|
|||||||
COMPLETION
|
COMPLETION
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_zsh_option_exclusions(command, option)
|
def self.generate_zsh_option_exclusions(command, option)
|
||||||
conflicts = Commands.option_conflicts(command, option.gsub(/^--/, ""))
|
conflicts = Commands.option_conflicts(command, option.gsub(/^--/, ""))
|
||||||
return "" unless conflicts.presence
|
return "" unless conflicts.presence
|
||||||
|
|
||||||
@ -278,7 +276,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { params(commands: T::Array[String]).returns(String) }
|
sig { params(commands: T::Array[String]).returns(String) }
|
||||||
def generate_zsh_completion_file(commands)
|
def self.generate_zsh_completion_file(commands)
|
||||||
variables = Variables.new(
|
variables = Variables.new(
|
||||||
aliases: Commands::HOMEBREW_INTERNAL_COMMAND_ALIASES.map do |alias_command, command|
|
aliases: Commands::HOMEBREW_INTERNAL_COMMAND_ALIASES.map do |alias_command, command|
|
||||||
alias_command = "'#{alias_command}'" if alias_command.start_with? "-"
|
alias_command = "'#{alias_command}'" if alias_command.start_with? "-"
|
||||||
@ -305,7 +303,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { params(command: String).returns(T.nilable(String)) }
|
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
|
return unless command_gets_completions? command
|
||||||
|
|
||||||
command_description = format_description Commands.command_description(command, short: true), fish: true
|
command_description = format_description Commands.command_description(command, short: true), fish: true
|
||||||
@ -352,7 +350,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { params(commands: T::Array[String]).returns(String) }
|
sig { params(commands: T::Array[String]).returns(String) }
|
||||||
def generate_fish_completion_file(commands)
|
def self.generate_fish_completion_file(commands)
|
||||||
variables = Variables.new(
|
variables = Variables.new(
|
||||||
completion_functions: commands.map do |command|
|
completion_functions: commands.map do |command|
|
||||||
generate_fish_subcommand_completion command
|
generate_fish_subcommand_completion command
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
|
|
||||||
module Homebrew
|
|
||||||
module Completions
|
|
||||||
include Kernel
|
|
||||||
end
|
|
||||||
end
|
|
@ -3,8 +3,6 @@
|
|||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
module Install
|
module Install
|
||||||
module_function
|
|
||||||
|
|
||||||
# This is a list of known paths to the host dynamic linker on Linux if
|
# 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 glibc is new enough. The symlink_ld_so method will fail if
|
||||||
# the host linker cannot be found in this list.
|
# the host linker cannot be found in this list.
|
||||||
@ -32,19 +30,19 @@ module Homebrew
|
|||||||
].freeze
|
].freeze
|
||||||
private_constant :GCC_RUNTIME_LIBS
|
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)
|
generic_perform_preinstall_checks(all_fatal: all_fatal, cc: cc)
|
||||||
symlink_ld_so
|
symlink_ld_so
|
||||||
setup_preferred_gcc_libs
|
setup_preferred_gcc_libs
|
||||||
end
|
end
|
||||||
|
|
||||||
def global_post_install
|
def self.global_post_install
|
||||||
generic_global_post_install
|
generic_global_post_install
|
||||||
symlink_ld_so
|
symlink_ld_so
|
||||||
setup_preferred_gcc_libs
|
setup_preferred_gcc_libs
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_cpu
|
def self.check_cpu
|
||||||
return if Hardware::CPU.intel? && Hardware::CPU.is_64_bit?
|
return if Hardware::CPU.intel? && Hardware::CPU.is_64_bit?
|
||||||
return if Hardware::CPU.arm?
|
return if Hardware::CPU.arm?
|
||||||
|
|
||||||
@ -59,7 +57,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
private_class_method :check_cpu
|
private_class_method :check_cpu
|
||||||
|
|
||||||
def symlink_ld_so
|
def self.symlink_ld_so
|
||||||
brew_ld_so = HOMEBREW_PREFIX/"lib/ld.so"
|
brew_ld_so = HOMEBREW_PREFIX/"lib/ld.so"
|
||||||
|
|
||||||
ld_so = HOMEBREW_PREFIX/"opt/glibc/bin/ld.so"
|
ld_so = HOMEBREW_PREFIX/"opt/glibc/bin/ld.so"
|
||||||
@ -79,7 +77,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
private_class_method :symlink_ld_so
|
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}"
|
gcc_opt_prefix = HOMEBREW_PREFIX/"opt/#{OS::LINUX_PREFERRED_GCC_RUNTIME_FORMULA}"
|
||||||
glibc_installed = (HOMEBREW_PREFIX/"opt/glibc/bin/ld.so").readable?
|
glibc_installed = (HOMEBREW_PREFIX/"opt/glibc/bin/ld.so").readable?
|
||||||
|
|
||||||
|
@ -41,9 +41,7 @@ module Homebrew
|
|||||||
EOS
|
EOS
|
||||||
private_constant :HOMEBREW_HELP
|
private_constant :HOMEBREW_HELP
|
||||||
|
|
||||||
module_function
|
def self.help(cmd = nil, empty_argv: false, usage_error: nil, remaining_args: [])
|
||||||
|
|
||||||
def help(cmd = nil, empty_argv: false, usage_error: nil, remaining_args: [])
|
|
||||||
if cmd.nil?
|
if cmd.nil?
|
||||||
# Handle `brew` (no arguments).
|
# Handle `brew` (no arguments).
|
||||||
if empty_argv
|
if empty_argv
|
||||||
@ -75,7 +73,7 @@ module Homebrew
|
|||||||
exit 0
|
exit 0
|
||||||
end
|
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.
|
# Only some types of commands can have a parser.
|
||||||
output = if Commands.valid_internal_cmd?(cmd) ||
|
output = if Commands.valid_internal_cmd?(cmd) ||
|
||||||
Commands.valid_internal_dev_cmd?(cmd) ||
|
Commands.valid_internal_dev_cmd?(cmd) ||
|
||||||
@ -94,7 +92,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
private_class_method :command_help
|
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.
|
# Let OptionParser generate help text for commands which have a parser.
|
||||||
cmd_parser = CLI::Parser.from_cmd_path(path)
|
cmd_parser = CLI::Parser.from_cmd_path(path)
|
||||||
return unless cmd_parser
|
return unless cmd_parser
|
||||||
@ -105,7 +103,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
private_class_method :parser_help
|
private_class_method :parser_help
|
||||||
|
|
||||||
def command_help_lines(path)
|
def self.command_help_lines(path)
|
||||||
path.read
|
path.read
|
||||||
.lines
|
.lines
|
||||||
.grep(/^#:/)
|
.grep(/^#:/)
|
||||||
@ -113,7 +111,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
private_class_method :command_help_lines
|
private_class_method :command_help_lines
|
||||||
|
|
||||||
def comment_help(path)
|
def self.comment_help(path)
|
||||||
# Otherwise read #: lines from the file.
|
# Otherwise read #: lines from the file.
|
||||||
help_lines = command_help_lines(path)
|
help_lines = command_help_lines(path)
|
||||||
return if help_lines.blank?
|
return if help_lines.blank?
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
|
|
||||||
module Homebrew
|
|
||||||
module Help
|
|
||||||
include Kernel
|
|
||||||
end
|
|
||||||
end
|
|
@ -12,8 +12,7 @@ module Homebrew
|
|||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
module Install
|
module Install
|
||||||
module_function
|
class << self
|
||||||
|
|
||||||
def perform_preinstall_checks(all_fatal: false, cc: nil)
|
def perform_preinstall_checks(all_fatal: false, cc: nil)
|
||||||
check_prefix
|
check_prefix
|
||||||
check_cpu
|
check_cpu
|
||||||
@ -23,7 +22,6 @@ module Homebrew
|
|||||||
Diagnostic.checks(:fatal_preinstall_checks)
|
Diagnostic.checks(:fatal_preinstall_checks)
|
||||||
end
|
end
|
||||||
alias generic_perform_preinstall_checks perform_preinstall_checks
|
alias generic_perform_preinstall_checks perform_preinstall_checks
|
||||||
module_function :generic_perform_preinstall_checks
|
|
||||||
|
|
||||||
def perform_build_from_source_checks(all_fatal: false)
|
def perform_build_from_source_checks(all_fatal: false)
|
||||||
Diagnostic.checks(:fatal_build_from_source_checks)
|
Diagnostic.checks(:fatal_build_from_source_checks)
|
||||||
@ -32,7 +30,6 @@ module Homebrew
|
|||||||
|
|
||||||
def global_post_install; end
|
def global_post_install; end
|
||||||
alias generic_global_post_install global_post_install
|
alias generic_global_post_install global_post_install
|
||||||
module_function :generic_global_post_install
|
|
||||||
|
|
||||||
def check_prefix
|
def check_prefix
|
||||||
if (Hardware::CPU.intel? || Hardware::CPU.in_rosetta2?) &&
|
if (Hardware::CPU.intel? || Hardware::CPU.in_rosetta2?) &&
|
||||||
@ -364,5 +361,6 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
require "extend/os/install"
|
require "extend/os/install"
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
|
|
||||||
module Homebrew
|
|
||||||
module Install
|
|
||||||
include Kernel
|
|
||||||
end
|
|
||||||
end
|
|
@ -8,9 +8,7 @@ module Language
|
|||||||
module Perl
|
module Perl
|
||||||
# Helper module for replacing `perl` shebangs.
|
# Helper module for replacing `perl` shebangs.
|
||||||
module Shebang
|
module Shebang
|
||||||
module_function
|
def self.detected_perl_shebang(formula = self)
|
||||||
|
|
||||||
def detected_perl_shebang(formula = self)
|
|
||||||
perl_path = if formula.deps.map(&:name).include? "perl"
|
perl_path = if formula.deps.map(&:name).include? "perl"
|
||||||
Formula["perl"].opt_bin/"perl"
|
Formula["perl"].opt_bin/"perl"
|
||||||
elsif formula.uses_from_macos_names.include? "perl"
|
elsif formula.uses_from_macos_names.include? "perl"
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
|
|
||||||
module Language
|
|
||||||
module Perl
|
|
||||||
module Shebang
|
|
||||||
include Kernel
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
@ -92,10 +92,8 @@ module Language
|
|||||||
|
|
||||||
# Mixin module for {Formula} adding shebang rewrite features.
|
# Mixin module for {Formula} adding shebang rewrite features.
|
||||||
module Shebang
|
module Shebang
|
||||||
module_function
|
|
||||||
|
|
||||||
# @private
|
# @private
|
||||||
def python_shebang_rewrite_info(python_path)
|
def self.python_shebang_rewrite_info(python_path)
|
||||||
Utils::Shebang::RewriteInfo.new(
|
Utils::Shebang::RewriteInfo.new(
|
||||||
%r{^#! ?/usr/bin/(?:env )?python(?:[23](?:\.\d{1,2})?)?( |$)},
|
%r{^#! ?/usr/bin/(?:env )?python(?:[23](?:\.\d{1,2})?)?( |$)},
|
||||||
28, # the length of "#! /usr/bin/env pythonx.yyy "
|
28, # the length of "#! /usr/bin/env pythonx.yyy "
|
||||||
@ -103,7 +101,7 @@ module Language
|
|||||||
)
|
)
|
||||||
end
|
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
|
python_path = if use_python_from_path
|
||||||
"/usr/bin/env python3"
|
"/usr/bin/env python3"
|
||||||
else
|
else
|
||||||
|
@ -1,11 +1,5 @@
|
|||||||
# typed: strict
|
# typed: strict
|
||||||
|
|
||||||
module Language::Python
|
module Language::Python::Virtualenv
|
||||||
module Shebang
|
|
||||||
include Kernel
|
|
||||||
end
|
|
||||||
|
|
||||||
module Virtualenv
|
|
||||||
requires_ancestor { Formula }
|
requires_ancestor { Formula }
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
@ -29,9 +29,7 @@ module Homebrew
|
|||||||
keyword_init: true,
|
keyword_init: true,
|
||||||
)
|
)
|
||||||
|
|
||||||
module_function
|
def self.regenerate_man_pages(quiet:)
|
||||||
|
|
||||||
def regenerate_man_pages(quiet:)
|
|
||||||
Homebrew.install_bundler_gems!
|
Homebrew.install_bundler_gems!
|
||||||
|
|
||||||
markup = build_man_page(quiet: quiet)
|
markup = build_man_page(quiet: quiet)
|
||||||
@ -39,7 +37,7 @@ module Homebrew
|
|||||||
convert_man_page(markup, TARGET_MAN_PATH/"brew.1")
|
convert_man_page(markup, TARGET_MAN_PATH/"brew.1")
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_man_page(quiet:)
|
def self.build_man_page(quiet:)
|
||||||
template = (SOURCE_PATH/"brew.1.md.erb").read
|
template = (SOURCE_PATH/"brew.1.md.erb").read
|
||||||
readme = HOMEBREW_REPOSITORY/"README.md"
|
readme = HOMEBREW_REPOSITORY/"README.md"
|
||||||
variables = Variables.new(
|
variables = Variables.new(
|
||||||
@ -64,12 +62,12 @@ module Homebrew
|
|||||||
ERB.new(template, trim_mode: ">").result(variables.instance_eval { binding })
|
ERB.new(template, trim_mode: ">").result(variables.instance_eval { binding })
|
||||||
end
|
end
|
||||||
|
|
||||||
def sort_key_for_path(path)
|
def self.sort_key_for_path(path)
|
||||||
# Options after regular commands (`~` comes after `z` in ASCII table).
|
# Options after regular commands (`~` comes after `z` in ASCII table).
|
||||||
path.basename.to_s.sub(/\.(rb|sh)$/, "").sub(/^--/, "~~")
|
path.basename.to_s.sub(/\.(rb|sh)$/, "").sub(/^--/, "~~")
|
||||||
end
|
end
|
||||||
|
|
||||||
def convert_man_page(markup, target)
|
def self.convert_man_page(markup, target)
|
||||||
manual = target.basename(".1")
|
manual = target.basename(".1")
|
||||||
organisation = "Homebrew"
|
organisation = "Homebrew"
|
||||||
|
|
||||||
@ -113,7 +111,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def target_path_to_format(target)
|
def self.target_path_to_format(target)
|
||||||
case target.basename
|
case target.basename
|
||||||
when /\.md$/ then ["--markdown", "markdown"]
|
when /\.md$/ then ["--markdown", "markdown"]
|
||||||
when /\.\d$/ then ["--roff", "man page"]
|
when /\.\d$/ then ["--roff", "man page"]
|
||||||
@ -122,7 +120,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_cmd_manpages(cmd_paths)
|
def self.generate_cmd_manpages(cmd_paths)
|
||||||
man_page_lines = []
|
man_page_lines = []
|
||||||
|
|
||||||
# preserve existing manpage order
|
# preserve existing manpage order
|
||||||
@ -142,7 +140,7 @@ module Homebrew
|
|||||||
man_page_lines.compact.join("\n")
|
man_page_lines.compact.join("\n")
|
||||||
end
|
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 = [format_usage_banner(cmd_parser.usage_banner_text)]
|
||||||
lines += cmd_parser.processed_options.map do |short, long, _, desc, hidden|
|
lines += cmd_parser.processed_options.map do |short, long, _, desc, hidden|
|
||||||
next if hidden
|
next if hidden
|
||||||
@ -159,7 +157,7 @@ module Homebrew
|
|||||||
lines
|
lines
|
||||||
end
|
end
|
||||||
|
|
||||||
def cmd_comment_manpage_lines(cmd_path)
|
def self.cmd_comment_manpage_lines(cmd_path)
|
||||||
comment_lines = cmd_path.read.lines.grep(/^#:/)
|
comment_lines = cmd_path.read.lines.grep(/^#:/)
|
||||||
return if comment_lines.empty?
|
return if comment_lines.empty?
|
||||||
return if comment_lines.first.include?("@hide_from_man_page")
|
return if comment_lines.first.include?("@hide_from_man_page")
|
||||||
@ -185,7 +183,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(String) }
|
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` " \
|
lines = ["These options are applicable to the `install`, `reinstall`, and `upgrade` " \
|
||||||
"subcommands with the `--cask` flag.\n"]
|
"subcommands with the `--cask` flag.\n"]
|
||||||
lines += Homebrew::CLI::Parser.global_cask_options.map do |_, long, description:, **|
|
lines += Homebrew::CLI::Parser.global_cask_options.map do |_, long, description:, **|
|
||||||
@ -195,7 +193,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def global_options_manpage
|
def self.global_options_manpage
|
||||||
lines = ["These options are applicable across multiple subcommands.\n"]
|
lines = ["These options are applicable across multiple subcommands.\n"]
|
||||||
lines += Homebrew::CLI::Parser.global_options.map do |short, long, desc|
|
lines += Homebrew::CLI::Parser.global_options.map do |short, long, desc|
|
||||||
generate_option_doc(short, long, desc)
|
generate_option_doc(short, long, desc)
|
||||||
@ -204,7 +202,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def env_vars_manpage
|
def self.env_vars_manpage
|
||||||
lines = Homebrew::EnvConfig::ENVS.flat_map do |env, hash|
|
lines = Homebrew::EnvConfig::ENVS.flat_map do |env, hash|
|
||||||
entry = "- `#{env}`:\n <br>#{hash[:description]}\n"
|
entry = "- `#{env}`:\n <br>#{hash[:description]}\n"
|
||||||
default = hash[:default_text]
|
default = hash[:default_text]
|
||||||
@ -216,11 +214,11 @@ module Homebrew
|
|||||||
lines.join("\n")
|
lines.join("\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
def format_opt(opt)
|
def self.format_opt(opt)
|
||||||
"`#{opt}`" unless opt.nil?
|
"`#{opt}`" unless opt.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_option_doc(short, long, desc)
|
def self.generate_option_doc(short, long, desc)
|
||||||
comma = (short && long) ? ", " : ""
|
comma = (short && long) ? ", " : ""
|
||||||
<<~EOS
|
<<~EOS
|
||||||
* #{format_opt(short)}#{comma}#{format_opt(long)}:
|
* #{format_opt(short)}#{comma}#{format_opt(long)}:
|
||||||
@ -228,7 +226,7 @@ module Homebrew
|
|||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
def format_usage_banner(usage_banner)
|
def self.format_usage_banner(usage_banner)
|
||||||
usage_banner&.sub(/^(#: *\* )?/, "### ")
|
usage_banner&.sub(/^(#: *\* )?/, "### ")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
|
|
||||||
module Homebrew
|
|
||||||
module Manpages
|
|
||||||
include Kernel
|
|
||||||
end
|
|
||||||
end
|
|
@ -8,10 +8,8 @@ module OS
|
|||||||
module Linux
|
module Linux
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
|
|
||||||
module_function
|
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def os_version
|
def self.os_version
|
||||||
if which("lsb_release")
|
if which("lsb_release")
|
||||||
lsb_info = Utils.popen_read("lsb_release", "-a")
|
lsb_info = Utils.popen_read("lsb_release", "-a")
|
||||||
description = lsb_info[/^Description:\s*(.*)$/, 1].force_encoding("UTF-8")
|
description = lsb_info[/^Description:\s*(.*)$/, 1].force_encoding("UTF-8")
|
||||||
@ -29,12 +27,12 @@ module OS
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def wsl?
|
def self.wsl?
|
||||||
/-microsoft/i.match?(OS.kernel_version.to_s)
|
/-microsoft/i.match?(OS.kernel_version.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(Version) }
|
sig { returns(Version) }
|
||||||
def wsl_version
|
def self.wsl_version
|
||||||
return Version::NULL unless wsl?
|
return Version::NULL unless wsl?
|
||||||
|
|
||||||
kernel = OS.kernel_version.to_s
|
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"]
|
raise "Loaded OS::Linux on generic OS!" if ENV["HOMEBREW_TEST_GENERIC_OS"]
|
||||||
|
|
||||||
def version
|
def self.version
|
||||||
::Version::NULL
|
::Version::NULL
|
||||||
end
|
end
|
||||||
|
|
||||||
def full_version
|
def self.full_version
|
||||||
::Version::NULL
|
::Version::NULL
|
||||||
end
|
end
|
||||||
|
|
||||||
def languages
|
def self.languages
|
||||||
@languages ||= Array(ENV["LANG"]&.slice(/[a-z]+/)).uniq
|
@languages ||= Array(ENV["LANG"]&.slice(/[a-z]+/)).uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
def language
|
def self.language
|
||||||
languages.first
|
languages.first
|
||||||
end
|
end
|
||||||
|
|
||||||
def sdk_root_needed?
|
def self.sdk_root_needed?
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def sdk_path_if_needed(_version = nil)
|
def self.sdk_path_if_needed(_version = nil)
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def sdk_path(_version = nil)
|
def self.sdk_path(_version = nil)
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
module Xcode
|
module Xcode
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
def version
|
def self.version
|
||||||
::Version::NULL
|
::Version::NULL
|
||||||
end
|
end
|
||||||
|
|
||||||
def installed?
|
def self.installed?
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -101,11 +99,11 @@ module OS
|
|||||||
module CLT
|
module CLT
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
def version
|
def self.version
|
||||||
::Version::NULL
|
::Version::NULL
|
||||||
end
|
end
|
||||||
|
|
||||||
def installed?
|
def self.installed?
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
|
|
||||||
module OS
|
|
||||||
module Linux
|
|
||||||
include ::Kernel
|
|
||||||
end
|
|
||||||
end
|
|
@ -11,8 +11,6 @@ module OS
|
|||||||
module Mac
|
module Mac
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
|
|
||||||
module_function
|
|
||||||
|
|
||||||
::MacOS = OS::Mac
|
::MacOS = OS::Mac
|
||||||
|
|
||||||
raise "Loaded OS::Mac on generic OS!" if ENV["HOMEBREW_TEST_GENERIC_OS"]
|
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
|
# This can be compared to numerics, strings, or symbols
|
||||||
# using the standard Ruby Comparable methods.
|
# using the standard Ruby Comparable methods.
|
||||||
sig { returns(Version) }
|
sig { returns(Version) }
|
||||||
def version
|
def self.version
|
||||||
@version ||= full_version.strip_patch
|
@version ||= full_version.strip_patch
|
||||||
end
|
end
|
||||||
|
|
||||||
# This can be compared to numerics, strings, or symbols
|
# This can be compared to numerics, strings, or symbols
|
||||||
# using the standard Ruby Comparable methods.
|
# using the standard Ruby Comparable methods.
|
||||||
sig { returns(Version) }
|
sig { returns(Version) }
|
||||||
def full_version
|
def self.full_version
|
||||||
@full_version ||= if ENV["HOMEBREW_FAKE_EL_CAPITAN"] # for Portable Ruby building
|
@full_version ||= if ENV["HOMEBREW_FAKE_EL_CAPITAN"] # for Portable Ruby building
|
||||||
Version.new("10.11.6")
|
Version.new("10.11.6")
|
||||||
else
|
else
|
||||||
@ -39,21 +37,20 @@ module OS
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { params(version: String).void }
|
sig { params(version: String).void }
|
||||||
def full_version=(version)
|
def self.full_version=(version)
|
||||||
@full_version = Version.new(version.chomp)
|
@full_version = Version.new(version.chomp)
|
||||||
@version = nil
|
@version = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(::Version) }
|
sig { returns(::Version) }
|
||||||
def latest_sdk_version
|
def self.latest_sdk_version
|
||||||
# TODO: bump version when new Xcode macOS SDK is released
|
# TODO: bump version when new Xcode macOS SDK is released
|
||||||
# NOTE: We only track the major version of the SDK.
|
# NOTE: We only track the major version of the SDK.
|
||||||
::Version.new("13")
|
::Version.new("13")
|
||||||
end
|
end
|
||||||
private :latest_sdk_version
|
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def preferred_perl_version
|
def self.preferred_perl_version
|
||||||
if version >= :big_sur
|
if version >= :big_sur
|
||||||
"5.30"
|
"5.30"
|
||||||
else
|
else
|
||||||
@ -61,7 +58,7 @@ module OS
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def languages
|
def self.languages
|
||||||
return @languages if @languages
|
return @languages if @languages
|
||||||
|
|
||||||
os_langs = Utils.popen_read("defaults", "read", "-g", "AppleLanguages")
|
os_langs = Utils.popen_read("defaults", "read", "-g", "AppleLanguages")
|
||||||
@ -74,17 +71,17 @@ module OS
|
|||||||
@languages = os_langs
|
@languages = os_langs
|
||||||
end
|
end
|
||||||
|
|
||||||
def language
|
def self.language
|
||||||
languages.first
|
languages.first
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(String) }
|
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
|
@active_developer_dir ||= Utils.popen_read("/usr/bin/xcode-select", "-print-path").strip
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def sdk_root_needed?
|
def self.sdk_root_needed?
|
||||||
if MacOS::CLT.installed?
|
if MacOS::CLT.installed?
|
||||||
# If there's no CLT SDK, return false
|
# If there's no CLT SDK, return false
|
||||||
return false unless MacOS::CLT.provides_sdk?
|
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 no specific SDK is requested, the SDK matching the OS version is returned,
|
||||||
# if available. Otherwise, the latest SDK is returned.
|
# if available. Otherwise, the latest SDK is returned.
|
||||||
|
|
||||||
def sdk_locator
|
def self.sdk_locator
|
||||||
if CLT.installed? && CLT.provides_sdk?
|
if CLT.installed? && CLT.provides_sdk?
|
||||||
CLT.sdk_locator
|
CLT.sdk_locator
|
||||||
else
|
else
|
||||||
@ -113,11 +110,11 @@ module OS
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def sdk(version = nil)
|
def self.sdk(version = nil)
|
||||||
sdk_locator.sdk_if_applicable(version)
|
sdk_locator.sdk_if_applicable(version)
|
||||||
end
|
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 the formula requires Xcode, don't return the CLT SDK
|
||||||
# If check_only_runtime_requirements is true, don't necessarily return the
|
# If check_only_runtime_requirements is true, don't necessarily return the
|
||||||
# Xcode SDK if the XcodeRequirement is only a build or test requirement.
|
# Xcode SDK if the XcodeRequirement is only a build or test requirement.
|
||||||
@ -132,12 +129,12 @@ module OS
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Returns the path to an SDK or nil, following the rules set by {sdk}.
|
# 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 = sdk(version)
|
||||||
s&.path
|
s&.path
|
||||||
end
|
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.
|
# Prefer CLT SDK when both Xcode and the CLT are installed.
|
||||||
# Expected results:
|
# Expected results:
|
||||||
# 1. On Xcode-only systems, return the Xcode SDK.
|
# 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/13}
|
||||||
# - {https://github.com/Homebrew/legacy-homebrew/issues/41}
|
# - {https://github.com/Homebrew/legacy-homebrew/issues/41}
|
||||||
# - {https://github.com/Homebrew/legacy-homebrew/issues/48}
|
# - {https://github.com/Homebrew/legacy-homebrew/issues/48}
|
||||||
def macports_or_fink
|
def self.macports_or_fink
|
||||||
paths = []
|
paths = []
|
||||||
|
|
||||||
# First look in the path because MacPorts is relocatable and Fink
|
# First look in the path because MacPorts is relocatable and Fink
|
||||||
@ -186,7 +183,7 @@ module OS
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { params(ids: String).returns(T.nilable(Pathname)) }
|
sig { params(ids: String).returns(T.nilable(Pathname)) }
|
||||||
def app_with_bundle_id(*ids)
|
def self.app_with_bundle_id(*ids)
|
||||||
path = mdfind(*ids)
|
path = mdfind(*ids)
|
||||||
.reject { |p| p.include?("/Backups.backupdb/") }
|
.reject { |p| p.include?("/Backups.backupdb/") }
|
||||||
.first
|
.first
|
||||||
@ -194,20 +191,20 @@ module OS
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { params(ids: String).returns(T::Array[String]) }
|
sig { params(ids: String).returns(T::Array[String]) }
|
||||||
def mdfind(*ids)
|
def self.mdfind(*ids)
|
||||||
(@mdfind ||= {}).fetch(ids) do
|
(@mdfind ||= {}).fetch(ids) do
|
||||||
@mdfind[ids] = Utils.popen_read("/usr/bin/mdfind", mdfind_query(*ids)).split("\n")
|
@mdfind[ids] = Utils.popen_read("/usr/bin/mdfind", mdfind_query(*ids)).split("\n")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def pkgutil_info(id)
|
def self.pkgutil_info(id)
|
||||||
(@pkginfo ||= {}).fetch(id) do |key|
|
(@pkginfo ||= {}).fetch(id) do |key|
|
||||||
@pkginfo[key] = Utils.popen_read("/usr/sbin/pkgutil", "--pkg-info", key).strip
|
@pkginfo[key] = Utils.popen_read("/usr/sbin/pkgutil", "--pkg-info", key).strip
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(ids: String).returns(String) }
|
sig { params(ids: String).returns(String) }
|
||||||
def mdfind_query(*ids)
|
def self.mdfind_query(*ids)
|
||||||
ids.map! { |id| "kMDItemCFBundleIdentifier == #{id}" }.join(" || ")
|
ids.map! { |id| "kMDItemCFBundleIdentifier == #{id}" }.join(" || ")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
|
|
||||||
module OS
|
|
||||||
module Mac
|
|
||||||
include Kernel
|
|
||||||
end
|
|
||||||
end
|
|
@ -9,8 +9,6 @@ module OS
|
|||||||
module Xcode
|
module Xcode
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
|
|
||||||
module_function
|
|
||||||
|
|
||||||
DEFAULT_BUNDLE_PATH = Pathname("/Applications/Xcode.app").freeze
|
DEFAULT_BUNDLE_PATH = Pathname("/Applications/Xcode.app").freeze
|
||||||
BUNDLE_ID = "com.apple.dt.Xcode"
|
BUNDLE_ID = "com.apple.dt.Xcode"
|
||||||
OLD_BUNDLE_ID = "com.apple.Xcode"
|
OLD_BUNDLE_ID = "com.apple.Xcode"
|
||||||
@ -20,7 +18,7 @@ module OS
|
|||||||
# CI systems have been updated.
|
# CI systems have been updated.
|
||||||
# This may be a beta version for a beta macOS.
|
# This may be a beta version for a beta macOS.
|
||||||
sig { params(macos: MacOS::Version).returns(String) }
|
sig { params(macos: MacOS::Version).returns(String) }
|
||||||
def latest_version(macos: MacOS.version)
|
def self.latest_version(macos: MacOS.version)
|
||||||
latest_stable = "14.3"
|
latest_stable = "14.3"
|
||||||
case macos
|
case macos
|
||||||
when "13" then latest_stable
|
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
|
# macOS version (which may initially be a beta if that version of macOS is
|
||||||
# also in beta).
|
# also in beta).
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def minimum_version
|
def self.minimum_version
|
||||||
case MacOS.version
|
case MacOS.version
|
||||||
when "13" then "14.1"
|
when "13" then "14.1"
|
||||||
when "12" then "13.1"
|
when "12" then "13.1"
|
||||||
@ -58,19 +56,19 @@ module OS
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def below_minimum_version?
|
def self.below_minimum_version?
|
||||||
return false unless installed?
|
return false unless installed?
|
||||||
|
|
||||||
version < minimum_version
|
version < minimum_version
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def latest_sdk_version?
|
def self.latest_sdk_version?
|
||||||
OS::Mac.full_version >= OS::Mac.latest_sdk_version
|
OS::Mac.full_version >= OS::Mac.latest_sdk_version
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def needs_clt_installed?
|
def self.needs_clt_installed?
|
||||||
return false if latest_sdk_version?
|
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
|
# 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
|
end
|
||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def outdated?
|
def self.outdated?
|
||||||
return false unless installed?
|
return false unless installed?
|
||||||
|
|
||||||
version < latest_version
|
version < latest_version
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def without_clt?
|
def self.without_clt?
|
||||||
!MacOS::CLT.installed?
|
!MacOS::CLT.installed?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a Pathname object corresponding to Xcode.app's Developer
|
# Returns a Pathname object corresponding to Xcode.app's Developer
|
||||||
# directory or nil if Xcode.app is not installed.
|
# directory or nil if Xcode.app is not installed.
|
||||||
sig { returns(T.nilable(Pathname)) }
|
sig { returns(T.nilable(Pathname)) }
|
||||||
def prefix
|
def self.prefix
|
||||||
return @prefix if defined?(@prefix)
|
return @prefix if defined?(@prefix)
|
||||||
|
|
||||||
@prefix = T.let(@prefix, T.nilable(Pathname))
|
@prefix = T.let(@prefix, T.nilable(Pathname))
|
||||||
@ -115,12 +113,12 @@ module OS
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(Pathname) }
|
sig { returns(Pathname) }
|
||||||
def toolchain_path
|
def self.toolchain_path
|
||||||
Pathname("#{prefix}/Toolchains/XcodeDefault.xctoolchain")
|
Pathname("#{prefix}/Toolchains/XcodeDefault.xctoolchain")
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T.nilable(Pathname)) }
|
sig { returns(T.nilable(Pathname)) }
|
||||||
def bundle_path
|
def self.bundle_path
|
||||||
# Use the default location if it exists.
|
# Use the default location if it exists.
|
||||||
return DEFAULT_BUNDLE_PATH if DEFAULT_BUNDLE_PATH.exist?
|
return DEFAULT_BUNDLE_PATH if DEFAULT_BUNDLE_PATH.exist?
|
||||||
|
|
||||||
@ -131,27 +129,27 @@ module OS
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def installed?
|
def self.installed?
|
||||||
!prefix.nil?
|
!prefix.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(XcodeSDKLocator) }
|
sig { returns(XcodeSDKLocator) }
|
||||||
def sdk_locator
|
def self.sdk_locator
|
||||||
@sdk_locator ||= XcodeSDKLocator.new
|
@sdk_locator ||= XcodeSDKLocator.new
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(version: T.nilable(MacOS::Version)).returns(T.nilable(SDK)) }
|
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)
|
sdk_locator.sdk_if_applicable(version)
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(version: T.nilable(MacOS::Version)).returns(T.nilable(Pathname)) }
|
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
|
sdk(version)&.path
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def installation_instructions
|
def self.installation_instructions
|
||||||
if OS::Mac.version.prerelease?
|
if OS::Mac.version.prerelease?
|
||||||
<<~EOS
|
<<~EOS
|
||||||
Xcode can be installed from:
|
Xcode can be installed from:
|
||||||
@ -165,7 +163,7 @@ module OS
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def update_instructions
|
def self.update_instructions
|
||||||
if OS::Mac.version.prerelease?
|
if OS::Mac.version.prerelease?
|
||||||
<<~EOS
|
<<~EOS
|
||||||
Xcode can be updated from:
|
Xcode can be updated from:
|
||||||
@ -179,7 +177,7 @@ module OS
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(::Version) }
|
sig { returns(::Version) }
|
||||||
def version
|
def self.version
|
||||||
# may return a version string
|
# may return a version string
|
||||||
# that is guessed based on the compiler, so do not
|
# that is guessed based on the compiler, so do not
|
||||||
# use it in order to check if Xcode is installed.
|
# use it in order to check if Xcode is installed.
|
||||||
@ -191,7 +189,7 @@ module OS
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T.nilable(String)) }
|
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
|
# 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.
|
# if return is used in the middle, which we do many times in here.
|
||||||
return if !MacOS::Xcode.installed? && !MacOS::CLT.installed?
|
return if !MacOS::Xcode.installed? && !MacOS::CLT.installed?
|
||||||
@ -219,7 +217,7 @@ module OS
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def detect_version_from_clang_version
|
def self.detect_version_from_clang_version
|
||||||
version = DevelopmentTools.clang_version
|
version = DevelopmentTools.clang_version
|
||||||
|
|
||||||
return "dunno" if version.null?
|
return "dunno" if version.null?
|
||||||
@ -252,7 +250,7 @@ module OS
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def default_prefix?
|
def self.default_prefix?
|
||||||
prefix.to_s == "/Applications/Xcode.app/Contents/Developer"
|
prefix.to_s == "/Applications/Xcode.app/Contents/Developer"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -272,37 +270,37 @@ module OS
|
|||||||
|
|
||||||
# Returns true even if outdated tools are installed.
|
# Returns true even if outdated tools are installed.
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def installed?
|
def self.installed?
|
||||||
!version.null?
|
!version.null?
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def separate_header_package?
|
def self.separate_header_package?
|
||||||
version >= "10" && MacOS.version >= "10.14"
|
version >= "10" && MacOS.version >= "10.14"
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def provides_sdk?
|
def self.provides_sdk?
|
||||||
version >= "8"
|
version >= "8"
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(CLTSDKLocator) }
|
sig { returns(CLTSDKLocator) }
|
||||||
def sdk_locator
|
def self.sdk_locator
|
||||||
@sdk_locator ||= CLTSDKLocator.new
|
@sdk_locator ||= CLTSDKLocator.new
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(version: T.nilable(MacOS::Version)).returns(T.nilable(SDK)) }
|
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)
|
sdk_locator.sdk_if_applicable(version)
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(version: T.nilable(MacOS::Version)).returns(T.nilable(Pathname)) }
|
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
|
sdk(version)&.path
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def installation_instructions
|
def self.installation_instructions
|
||||||
if MacOS.version == "10.14"
|
if MacOS.version == "10.14"
|
||||||
# This is not available from `xcode-select`
|
# This is not available from `xcode-select`
|
||||||
<<~EOS
|
<<~EOS
|
||||||
@ -318,7 +316,7 @@ module OS
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def update_instructions
|
def self.update_instructions
|
||||||
software_update_location = if MacOS.version >= "13"
|
software_update_location = if MacOS.version >= "13"
|
||||||
"System Settings"
|
"System Settings"
|
||||||
elsif MacOS.version >= "10.14"
|
elsif MacOS.version >= "10.14"
|
||||||
@ -343,7 +341,7 @@ module OS
|
|||||||
# Bump these when the new version is distributed through Software Update
|
# Bump these when the new version is distributed through Software Update
|
||||||
# and our CI systems have been updated.
|
# and our CI systems have been updated.
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def latest_clang_version
|
def self.latest_clang_version
|
||||||
case MacOS.version
|
case MacOS.version
|
||||||
when "13" then "1403.0.22.14.1"
|
when "13" then "1403.0.22.14.1"
|
||||||
when "12" then "1400.0.29.202"
|
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
|
# without this. Generally this will be the first stable CLT release on
|
||||||
# that macOS version.
|
# that macOS version.
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def minimum_version
|
def self.minimum_version
|
||||||
case MacOS.version
|
case MacOS.version
|
||||||
when "13" then "14.0.0"
|
when "13" then "14.0.0"
|
||||||
when "12" then "13.0.0"
|
when "12" then "13.0.0"
|
||||||
@ -374,14 +372,14 @@ module OS
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def below_minimum_version?
|
def self.below_minimum_version?
|
||||||
return false unless installed?
|
return false unless installed?
|
||||||
|
|
||||||
version < minimum_version
|
version < minimum_version
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def outdated?
|
def self.outdated?
|
||||||
clang_version = detect_clang_version
|
clang_version = detect_clang_version
|
||||||
return false unless clang_version
|
return false unless clang_version
|
||||||
|
|
||||||
@ -389,13 +387,13 @@ module OS
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T.nilable(String)) }
|
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 = Utils.popen_read("#{PKG_PATH}/usr/bin/clang", "--version")
|
||||||
version_output[/clang-(\d+(\.\d+)+)/, 1]
|
version_output[/clang-(\d+(\.\d+)+)/, 1]
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T.nilable(String)) }
|
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.")
|
detect_clang_version&.sub(/^(\d+)0(\d)\./, "\\1.\\2.")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -403,7 +401,7 @@ module OS
|
|||||||
# Note that the different ways of installing the CLTs lead to different
|
# Note that the different ways of installing the CLTs lead to different
|
||||||
# version numbers.
|
# version numbers.
|
||||||
sig { returns(::Version) }
|
sig { returns(::Version) }
|
||||||
def version
|
def self.version
|
||||||
if @version ||= detect_version
|
if @version ||= detect_version
|
||||||
::Version.new @version
|
::Version.new @version
|
||||||
else
|
else
|
||||||
@ -412,7 +410,7 @@ module OS
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T.nilable(String)) }
|
sig { returns(T.nilable(String)) }
|
||||||
def detect_version
|
def self.detect_version
|
||||||
version = T.let(nil, T.nilable(String))
|
version = T.let(nil, T.nilable(String))
|
||||||
[EXECUTABLE_PKG_ID, MAVERICKS_NEW_PKG_ID].each do |id|
|
[EXECUTABLE_PKG_ID, MAVERICKS_NEW_PKG_ID].each do |id|
|
||||||
next unless File.exist?("#{PKG_PATH}/usr/bin/clang")
|
next unless File.exist?("#{PKG_PATH}/usr/bin/clang")
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
|
|
||||||
module OS
|
|
||||||
module Mac
|
|
||||||
module Xcode
|
|
||||||
include Kernel
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
@ -8,9 +8,7 @@ module Homebrew
|
|||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
module Search
|
module Search
|
||||||
module_function
|
def self.query_regexp(query)
|
||||||
|
|
||||||
def query_regexp(query)
|
|
||||||
if (m = query.match(%r{^/(.*)/$}))
|
if (m = query.match(%r{^/(.*)/$}))
|
||||||
Regexp.new(m[1])
|
Regexp.new(m[1])
|
||||||
else
|
else
|
||||||
@ -20,7 +18,7 @@ module Homebrew
|
|||||||
raise "#{query} is not a valid regex."
|
raise "#{query} is not a valid regex."
|
||||||
end
|
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?
|
both = !args.formula? && !args.cask?
|
||||||
eval_all = args.eval_all? || Homebrew::EnvConfig.eval_all?
|
eval_all = args.eval_all? || Homebrew::EnvConfig.eval_all?
|
||||||
|
|
||||||
@ -42,7 +40,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
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)
|
if string_or_regex.is_a?(String) && string_or_regex.match?(HOMEBREW_TAP_FORMULA_REGEX)
|
||||||
return begin
|
return begin
|
||||||
[Formulary.factory(string_or_regex).name]
|
[Formulary.factory(string_or_regex).name]
|
||||||
@ -74,7 +72,7 @@ module Homebrew
|
|||||||
end.compact
|
end.compact
|
||||||
end
|
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)
|
if string_or_regex.is_a?(String) && string_or_regex.match?(HOMEBREW_TAP_CASK_REGEX)
|
||||||
return begin
|
return begin
|
||||||
[Cask::CaskLoader.load(string_or_regex).token]
|
[Cask::CaskLoader.load(string_or_regex).token]
|
||||||
@ -104,7 +102,7 @@ module Homebrew
|
|||||||
end.uniq
|
end.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
def search_names(string_or_regex, args)
|
def self.search_names(string_or_regex, args)
|
||||||
both = !args.formula? && !args.cask?
|
both = !args.formula? && !args.cask?
|
||||||
|
|
||||||
all_formulae = if args.formula? || both
|
all_formulae = if args.formula? || both
|
||||||
@ -122,7 +120,7 @@ module Homebrew
|
|||||||
[all_formulae, all_casks]
|
[all_formulae, all_casks]
|
||||||
end
|
end
|
||||||
|
|
||||||
def search(selectable, string_or_regex, &block)
|
def self.search(selectable, string_or_regex, &block)
|
||||||
case string_or_regex
|
case string_or_regex
|
||||||
when Regexp
|
when Regexp
|
||||||
search_regex(selectable, string_or_regex, &block)
|
search_regex(selectable, string_or_regex, &block)
|
||||||
@ -131,11 +129,11 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def simplify_string(string)
|
def self.simplify_string(string)
|
||||||
string.downcase.gsub(/[^a-z\d]/i, "")
|
string.downcase.gsub(/[^a-z\d]/i, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
def search_regex(selectable, regex)
|
def self.search_regex(selectable, regex)
|
||||||
selectable.select do |*args|
|
selectable.select do |*args|
|
||||||
args = yield(*args) if block_given?
|
args = yield(*args) if block_given?
|
||||||
args = Array(args).flatten.compact
|
args = Array(args).flatten.compact
|
||||||
@ -143,7 +141,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def search_string(selectable, string)
|
def self.search_string(selectable, string)
|
||||||
simplified_string = simplify_string(string)
|
simplified_string = simplify_string(string)
|
||||||
selectable.select do |*args|
|
selectable.select do |*args|
|
||||||
args = yield(*args) if block_given?
|
args = yield(*args) if block_given?
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
|
|
||||||
module Homebrew::Search
|
|
||||||
include Kernel
|
|
||||||
end
|
|
@ -8,9 +8,7 @@ module Homebrew
|
|||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
module Settings
|
module Settings
|
||||||
module_function
|
def self.read(setting, repo: HOMEBREW_REPOSITORY)
|
||||||
|
|
||||||
def read(setting, repo: HOMEBREW_REPOSITORY)
|
|
||||||
return unless (repo/".git/config").exist?
|
return unless (repo/".git/config").exist?
|
||||||
|
|
||||||
value = Utils.popen_read("git", "-C", repo.to_s, "config", "--get", "homebrew.#{setting}").chomp
|
value = Utils.popen_read("git", "-C", repo.to_s, "config", "--get", "homebrew.#{setting}").chomp
|
||||||
@ -20,7 +18,7 @@ module Homebrew
|
|||||||
value
|
value
|
||||||
end
|
end
|
||||||
|
|
||||||
def write(setting, value, repo: HOMEBREW_REPOSITORY)
|
def self.write(setting, value, repo: HOMEBREW_REPOSITORY)
|
||||||
return unless (repo/".git/config").exist?
|
return unless (repo/".git/config").exist?
|
||||||
|
|
||||||
value = value.to_s
|
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)
|
Kernel.system("git", "-C", repo.to_s, "config", "--replace-all", "homebrew.#{setting}", value, exception: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete(setting, repo: HOMEBREW_REPOSITORY)
|
def self.delete(setting, repo: HOMEBREW_REPOSITORY)
|
||||||
return unless (repo/".git/config").exist?
|
return unless (repo/".git/config").exist?
|
||||||
|
|
||||||
return if read(setting, repo: repo).blank?
|
return if read(setting, repo: repo).blank?
|
||||||
|
@ -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
|
|
@ -8,9 +8,7 @@ module Homebrew
|
|||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
module Uninstall
|
module Uninstall
|
||||||
module_function
|
def self.uninstall_kegs(kegs_by_rack, casks: [], force: false, ignore_dependencies: false, named_args: [])
|
||||||
|
|
||||||
def uninstall_kegs(kegs_by_rack, casks: [], force: false, ignore_dependencies: false, named_args: [])
|
|
||||||
handle_unsatisfied_dependents(kegs_by_rack,
|
handle_unsatisfied_dependents(kegs_by_rack,
|
||||||
casks: casks,
|
casks: casks,
|
||||||
ignore_dependencies: ignore_dependencies,
|
ignore_dependencies: ignore_dependencies,
|
||||||
@ -97,7 +95,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
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
|
return if ignore_dependencies
|
||||||
|
|
||||||
all_kegs = kegs_by_rack.values.flatten(1)
|
all_kegs = kegs_by_rack.values.flatten(1)
|
||||||
@ -107,7 +105,7 @@ module Homebrew
|
|||||||
nil
|
nil
|
||||||
end
|
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))
|
return false unless (result = InstalledDependents.find_some_installed_dependents(kegs, casks: casks))
|
||||||
|
|
||||||
if Homebrew::EnvConfig.developer?
|
if Homebrew::EnvConfig.developer?
|
||||||
@ -164,7 +162,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def rm_pin(rack)
|
def self.rm_pin(rack)
|
||||||
Formulary.from_rack(rack).unpin
|
Formulary.from_rack(rack).unpin
|
||||||
rescue
|
rescue
|
||||||
nil
|
nil
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
|
|
||||||
module Homebrew
|
|
||||||
module Uninstall
|
|
||||||
include Kernel
|
|
||||||
end
|
|
||||||
end
|
|
@ -7,33 +7,31 @@ require "utils/tty"
|
|||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
module Formatter
|
module Formatter
|
||||||
module_function
|
def self.arrow(string, color: nil)
|
||||||
|
|
||||||
def arrow(string, color: nil)
|
|
||||||
prefix("==>", string, color)
|
prefix("==>", string, color)
|
||||||
end
|
end
|
||||||
|
|
||||||
def headline(string, color: nil)
|
def self.headline(string, color: nil)
|
||||||
arrow("#{Tty.bold}#{string}#{Tty.reset}", color: color)
|
arrow("#{Tty.bold}#{string}#{Tty.reset}", color: color)
|
||||||
end
|
end
|
||||||
|
|
||||||
def identifier(string)
|
def self.identifier(string)
|
||||||
"#{Tty.green}#{string}#{Tty.default}"
|
"#{Tty.green}#{string}#{Tty.default}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def option(string)
|
def self.option(string)
|
||||||
"#{Tty.bold}#{string}#{Tty.reset}"
|
"#{Tty.bold}#{string}#{Tty.reset}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def success(string, label: nil)
|
def self.success(string, label: nil)
|
||||||
label(label, string, :green)
|
label(label, string, :green)
|
||||||
end
|
end
|
||||||
|
|
||||||
def warning(string, label: nil)
|
def self.warning(string, label: nil)
|
||||||
label(label, string, :yellow)
|
label(label, string, :yellow)
|
||||||
end
|
end
|
||||||
|
|
||||||
def error(string, label: nil)
|
def self.error(string, label: nil)
|
||||||
label(label, string, :red)
|
label(label, string, :red)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -50,7 +48,7 @@ module Formatter
|
|||||||
# so we always wrap one word before an option.
|
# so we always wrap one word before an option.
|
||||||
# @see https://github.com/Homebrew/brew/pull/12672
|
# @see https://github.com/Homebrew/brew/pull/12672
|
||||||
# @see https://macromates.com/blog/2006/wrapping-text-with-regular-expressions/
|
# @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
|
desc = OPTION_DESC_WIDTH
|
||||||
indent = width - desc
|
indent = width - desc
|
||||||
string.gsub(/(?<=\S) *\n(?=\S)/, " ")
|
string.gsub(/(?<=\S) *\n(?=\S)/, " ")
|
||||||
@ -60,17 +58,17 @@ module Formatter
|
|||||||
.gsub(/(.{1,#{width}})( +|$)(?!-)\n?/, "\\1\n")
|
.gsub(/(.{1,#{width}})( +|$)(?!-)\n?/, "\\1\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
def url(string)
|
def self.url(string)
|
||||||
"#{Tty.underline}#{string}#{Tty.no_underline}"
|
"#{Tty.underline}#{string}#{Tty.no_underline}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def label(label, string, color)
|
def self.label(label, string, color)
|
||||||
label = "#{label}:" unless label.nil?
|
label = "#{label}:" unless label.nil?
|
||||||
prefix(label, string, color)
|
prefix(label, string, color)
|
||||||
end
|
end
|
||||||
private_class_method :label
|
private_class_method :label
|
||||||
|
|
||||||
def prefix(prefix, string, color)
|
def self.prefix(prefix, string, color)
|
||||||
if prefix.nil? && color.nil?
|
if prefix.nil? && color.nil?
|
||||||
string
|
string
|
||||||
elsif prefix.nil?
|
elsif prefix.nil?
|
||||||
@ -83,7 +81,7 @@ module Formatter
|
|||||||
end
|
end
|
||||||
private_class_method :prefix
|
private_class_method :prefix
|
||||||
|
|
||||||
def columns(*objects, gap_size: 2)
|
def self.columns(*objects, gap_size: 2)
|
||||||
objects = objects.flatten.map(&:to_s)
|
objects = objects.flatten.map(&:to_s)
|
||||||
|
|
||||||
fallback = proc do
|
fallback = proc do
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
|
|
||||||
module Formatter
|
|
||||||
include Kernel
|
|
||||||
end
|
|
@ -33,8 +33,6 @@ module GitHub
|
|||||||
module API
|
module API
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
|
|
||||||
module_function
|
|
||||||
|
|
||||||
# Generic API error.
|
# Generic API error.
|
||||||
class Error < RuntimeError
|
class Error < RuntimeError
|
||||||
attr_reader :github_message
|
attr_reader :github_message
|
||||||
@ -119,7 +117,7 @@ module GitHub
|
|||||||
# Gets the password field from `git-credential-osxkeychain` for github.com,
|
# Gets the password field from `git-credential-osxkeychain` for github.com,
|
||||||
# but only if that password looks like a GitHub Personal Access Token.
|
# but only if that password looks like a GitHub Personal Access Token.
|
||||||
sig { returns(T.nilable(String)) }
|
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|
|
github_credentials = Utils.popen_write("git", "credential-osxkeychain", "get") do |pipe|
|
||||||
pipe.write "protocol=https\nhost=github.com\n"
|
pipe.write "protocol=https\nhost=github.com\n"
|
||||||
end
|
end
|
||||||
@ -141,12 +139,12 @@ module GitHub
|
|||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def credentials
|
def self.credentials
|
||||||
@credentials ||= Homebrew::EnvConfig.github_api_token || keychain_username_password
|
@credentials ||= Homebrew::EnvConfig.github_api_token || keychain_username_password
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(Symbol) }
|
sig { returns(Symbol) }
|
||||||
def credentials_type
|
def self.credentials_type
|
||||||
if Homebrew::EnvConfig.github_api_token
|
if Homebrew::EnvConfig.github_api_token
|
||||||
:env_token
|
:env_token
|
||||||
elsif keychain_username_password
|
elsif keychain_username_password
|
||||||
@ -158,7 +156,7 @@ module GitHub
|
|||||||
|
|
||||||
# Given an API response from GitHub, warn the user if their credentials
|
# Given an API response from GitHub, warn the user if their credentials
|
||||||
# have insufficient permissions.
|
# 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?
|
return if response_headers.empty?
|
||||||
|
|
||||||
scopes = response_headers["x-accepted-oauth-scopes"].to_s.split(", ")
|
scopes = response_headers["x-accepted-oauth-scopes"].to_s.split(", ")
|
||||||
@ -184,7 +182,7 @@ module GitHub
|
|||||||
EOS
|
EOS
|
||||||
end
|
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.
|
# 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?
|
return block_given? ? yield({}) : {} if Homebrew::EnvConfig.no_github_api?
|
||||||
|
|
||||||
@ -253,7 +251,7 @@ module GitHub
|
|||||||
end
|
end
|
||||||
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|
|
(1..API_MAX_PAGES).each do |page|
|
||||||
result = API.open_rest("#{url}?per_page=#{per_page}&page=#{page}&#{additional_query_params}")
|
result = API.open_rest("#{url}?per_page=#{per_page}&page=#{page}&#{additional_query_params}")
|
||||||
break if result.blank?
|
break if result.blank?
|
||||||
@ -262,7 +260,7 @@ module GitHub
|
|||||||
end
|
end
|
||||||
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 }
|
data = { query: query, variables: variables }
|
||||||
result = open_rest("#{API_URL}/graphql", scopes: scopes, data: data, request_method: "POST")
|
result = open_rest("#{API_URL}/graphql", scopes: scopes, data: data, request_method: "POST")
|
||||||
|
|
||||||
@ -277,7 +275,7 @@ module GitHub
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def raise_error(output, errors, http_code, headers, scopes)
|
def self.raise_error(output, errors, http_code, headers, scopes)
|
||||||
json = begin
|
json = begin
|
||||||
JSON.parse(output)
|
JSON.parse(output)
|
||||||
rescue
|
rescue
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
|
|
||||||
module GitHub::API
|
|
||||||
include Kernel
|
|
||||||
end
|
|
@ -10,8 +10,6 @@ module Utils
|
|||||||
module Gzip
|
module Gzip
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
|
|
||||||
module_function
|
|
||||||
|
|
||||||
sig {
|
sig {
|
||||||
params(
|
params(
|
||||||
path: T.any(String, Pathname),
|
path: T.any(String, Pathname),
|
||||||
@ -20,7 +18,7 @@ module Utils
|
|||||||
output: T.any(String, Pathname),
|
output: T.any(String, Pathname),
|
||||||
).returns(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")
|
output: "#{path}.gz")
|
||||||
# Ideally, we would just set mtime = 0 if SOURCE_DATE_EPOCH is absent, but Ruby's
|
# 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:
|
# Zlib::GzipWriter does not properly handle the case of setting mtime = 0:
|
||||||
@ -55,7 +53,7 @@ module Utils
|
|||||||
mtime: T.any(Integer, Time),
|
mtime: T.any(Integer, Time),
|
||||||
).returns(T::Array[Pathname])
|
).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
|
if reproducible
|
||||||
paths.map do |path|
|
paths.map do |path|
|
||||||
compress_with_options(path, mtime: mtime)
|
compress_with_options(path, mtime: mtime)
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
|
|
||||||
module Utils
|
|
||||||
module Gzip
|
|
||||||
include Kernel
|
|
||||||
end
|
|
||||||
end
|
|
@ -20,8 +20,6 @@ module Utils
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module_function
|
|
||||||
|
|
||||||
# Sometimes we have to change a bit before we install. Mostly we
|
# Sometimes we have to change a bit before we install. Mostly we
|
||||||
# prefer a patch, but if you need the {Formula#prefix prefix} of
|
# prefer a patch, but if you need the {Formula#prefix prefix} of
|
||||||
# this formula in the patch you have to resort to `inreplace`,
|
# this formula in the patch you have to resort to `inreplace`,
|
||||||
@ -47,7 +45,7 @@ module Utils
|
|||||||
audit_result: T::Boolean,
|
audit_result: T::Boolean,
|
||||||
).void
|
).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
|
after = after.to_s if after.is_a? Symbol
|
||||||
|
|
||||||
errors = {}
|
errors = {}
|
||||||
@ -73,7 +71,7 @@ module Utils
|
|||||||
end
|
end
|
||||||
|
|
||||||
# @api private
|
# @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)
|
str = File.binread(path)
|
||||||
contents = StringInreplaceExtension.new(str)
|
contents = StringInreplaceExtension.new(str)
|
||||||
replacement_pairs.each do |old, new|
|
replacement_pairs.each do |old, new|
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
|
|
||||||
module Utils
|
|
||||||
module Inreplace
|
|
||||||
include Kernel
|
|
||||||
end
|
|
||||||
end
|
|
@ -6,9 +6,7 @@ module Utils
|
|||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
module Link
|
module Link
|
||||||
module_function
|
def self.link_src_dst_dirs(src_dir, dst_dir, command, link_dir: false)
|
||||||
|
|
||||||
def link_src_dst_dirs(src_dir, dst_dir, command, link_dir: false)
|
|
||||||
return unless src_dir.exist?
|
return unless src_dir.exist?
|
||||||
|
|
||||||
conflicts = []
|
conflicts = []
|
||||||
@ -42,7 +40,7 @@ module Utils
|
|||||||
end
|
end
|
||||||
private_class_method :link_src_dst_dirs
|
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?
|
return unless src_dir.exist?
|
||||||
|
|
||||||
src_paths = unlink_dir ? [src_dir] : src_dir.find
|
src_paths = unlink_dir ? [src_dir] : src_dir.find
|
||||||
@ -56,27 +54,27 @@ module Utils
|
|||||||
end
|
end
|
||||||
private_class_method :unlink_src_dst_dirs
|
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)
|
link_src_dst_dirs(path/"manpages", HOMEBREW_PREFIX/"share/man/man1", command)
|
||||||
end
|
end
|
||||||
|
|
||||||
def unlink_manpages(path)
|
def self.unlink_manpages(path)
|
||||||
unlink_src_dst_dirs(path/"manpages", HOMEBREW_PREFIX/"share/man/man1")
|
unlink_src_dst_dirs(path/"manpages", HOMEBREW_PREFIX/"share/man/man1")
|
||||||
end
|
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/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/zsh", HOMEBREW_PREFIX/"share/zsh/site-functions", command)
|
||||||
link_src_dst_dirs(path/"completions/fish", HOMEBREW_PREFIX/"share/fish/vendor_completions.d", command)
|
link_src_dst_dirs(path/"completions/fish", HOMEBREW_PREFIX/"share/fish/vendor_completions.d", command)
|
||||||
end
|
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/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/zsh", HOMEBREW_PREFIX/"share/zsh/site-functions")
|
||||||
unlink_src_dst_dirs(path/"completions/fish", HOMEBREW_PREFIX/"share/fish/vendor_completions.d")
|
unlink_src_dst_dirs(path/"completions/fish", HOMEBREW_PREFIX/"share/fish/vendor_completions.d")
|
||||||
end
|
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)
|
link_src_dst_dirs(path/"docs", HOMEBREW_PREFIX/"share/doc/homebrew", command, link_dir: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
|
|
||||||
module Utils
|
|
||||||
module Link
|
|
||||||
include Kernel
|
|
||||||
end
|
|
||||||
end
|
|
@ -9,13 +9,10 @@ require "utils/curl"
|
|||||||
module Repology
|
module Repology
|
||||||
HOMEBREW_CORE = "homebrew"
|
HOMEBREW_CORE = "homebrew"
|
||||||
HOMEBREW_CASK = "homebrew_casks"
|
HOMEBREW_CASK = "homebrew_casks"
|
||||||
|
|
||||||
module_function
|
|
||||||
|
|
||||||
MAX_PAGINATION = 15
|
MAX_PAGINATION = 15
|
||||||
private_constant :MAX_PAGINATION
|
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?
|
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"
|
url = "https://repology.org/api/v1/projects/#{last_package_in_response}?inrepo=#{repository}&outdated=1"
|
||||||
|
|
||||||
@ -31,7 +28,7 @@ module Repology
|
|||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
|
|
||||||
def single_package_query(name, repository:)
|
def self.single_package_query(name, repository:)
|
||||||
url = "https://repology.org/tools/project-by?repo=#{repository}&" \
|
url = "https://repology.org/tools/project-by?repo=#{repository}&" \
|
||||||
"name_type=srcname&target_page=api_v1_project&name=#{name}"
|
"name_type=srcname&target_page=api_v1_project&name=#{name}"
|
||||||
|
|
||||||
@ -50,7 +47,7 @@ module Repology
|
|||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_api_response(limit = nil, last_package = "", repository:)
|
def self.parse_api_response(limit = nil, last_package = "", repository:)
|
||||||
package_term = case repository
|
package_term = case repository
|
||||||
when HOMEBREW_CORE
|
when HOMEBREW_CORE
|
||||||
"formulae"
|
"formulae"
|
||||||
@ -83,7 +80,7 @@ module Repology
|
|||||||
outdated_packages.sort.to_h
|
outdated_packages.sort.to_h
|
||||||
end
|
end
|
||||||
|
|
||||||
def latest_version(repositories)
|
def self.latest_version(repositories)
|
||||||
# The status is "unique" when the package is present only in Homebrew, so
|
# 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.
|
# Repology has no way of knowing if the package is up-to-date.
|
||||||
is_unique = repositories.find do |repo|
|
is_unique = repositories.find do |repo|
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
|
|
||||||
module Repology
|
|
||||||
include Kernel
|
|
||||||
requires_ancestor { Utils::Curl }
|
|
||||||
end
|
|
@ -8,8 +8,6 @@ module Utils
|
|||||||
module Shebang
|
module Shebang
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
|
|
||||||
module_function
|
|
||||||
|
|
||||||
# Specification on how to rewrite a given shebang.
|
# Specification on how to rewrite a given shebang.
|
||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
@ -33,7 +31,7 @@ module Utils
|
|||||||
#
|
#
|
||||||
# @api public
|
# @api public
|
||||||
sig { params(rewrite_info: RewriteInfo, paths: T::Array[T.any(String, Pathname)]).void }
|
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|
|
paths.each do |f|
|
||||||
f = Pathname(f)
|
f = Pathname(f)
|
||||||
next unless f.file?
|
next unless f.file?
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
|
|
||||||
module Utils
|
|
||||||
module Shebang
|
|
||||||
include Kernel
|
|
||||||
end
|
|
||||||
end
|
|
@ -5,12 +5,10 @@ module Utils
|
|||||||
module Shell
|
module Shell
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
|
|
||||||
module_function
|
|
||||||
|
|
||||||
# Take a path and heuristically convert it to a shell name,
|
# Take a path and heuristically convert it to a shell name,
|
||||||
# return `nil` if there's no match.
|
# return `nil` if there's no match.
|
||||||
sig { params(path: String).returns(T.nilable(Symbol)) }
|
sig { params(path: String).returns(T.nilable(Symbol)) }
|
||||||
def from_path(path)
|
def self.from_path(path)
|
||||||
# we only care about the basename
|
# we only care about the basename
|
||||||
shell_name = File.basename(path)
|
shell_name = File.basename(path)
|
||||||
# handle possible version suffix like `zsh-5.2`
|
# handle possible version suffix like `zsh-5.2`
|
||||||
@ -19,23 +17,23 @@ module Utils
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { params(default: String).returns(String) }
|
sig { params(default: String).returns(String) }
|
||||||
def preferred_path(default: "")
|
def self.preferred_path(default: "")
|
||||||
ENV.fetch("SHELL", default)
|
ENV.fetch("SHELL", default)
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T.nilable(Symbol)) }
|
sig { returns(T.nilable(Symbol)) }
|
||||||
def preferred
|
def self.preferred
|
||||||
from_path(preferred_path)
|
from_path(preferred_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T.nilable(Symbol)) }
|
sig { returns(T.nilable(Symbol)) }
|
||||||
def parent
|
def self.parent
|
||||||
from_path(`ps -p #{Process.ppid} -o ucomm=`.strip)
|
from_path(`ps -p #{Process.ppid} -o ucomm=`.strip)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Quote values. Quoting keys is overkill.
|
# Quote values. Quoting keys is overkill.
|
||||||
sig { params(key: String, value: String, shell: T.nilable(Symbol)).returns(T.nilable(String)) }
|
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
|
case shell
|
||||||
when :bash, :ksh, :mksh, :sh, :zsh
|
when :bash, :ksh, :mksh, :sh, :zsh
|
||||||
"export #{key}=\"#{sh_quote(value)}\""
|
"export #{key}=\"#{sh_quote(value)}\""
|
||||||
@ -51,7 +49,7 @@ module Utils
|
|||||||
|
|
||||||
# Return the shell profile file based on user's preferred shell.
|
# Return the shell profile file based on user's preferred shell.
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def profile
|
def self.profile
|
||||||
case preferred
|
case preferred
|
||||||
when :bash
|
when :bash
|
||||||
bash_profile = "#{Dir.home}/.bash_profile"
|
bash_profile = "#{Dir.home}/.bash_profile"
|
||||||
@ -64,7 +62,7 @@ module Utils
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { params(variable: String, value: String).returns(T.nilable(String)) }
|
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
|
case preferred
|
||||||
when :bash, :ksh, :sh, :zsh, nil
|
when :bash, :ksh, :sh, :zsh, nil
|
||||||
"echo 'export #{variable}=#{sh_quote(value)}' >> #{profile}"
|
"echo 'export #{variable}=#{sh_quote(value)}' >> #{profile}"
|
||||||
@ -76,7 +74,7 @@ module Utils
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { params(path: String).returns(T.nilable(String)) }
|
sig { params(path: String).returns(T.nilable(String)) }
|
||||||
def prepend_path_in_profile(path)
|
def self.prepend_path_in_profile(path)
|
||||||
case preferred
|
case preferred
|
||||||
when :bash, :ksh, :mksh, :sh, :zsh, nil
|
when :bash, :ksh, :mksh, :sh, :zsh, nil
|
||||||
"echo 'export PATH=\"#{sh_quote(path)}:$PATH\"' >> #{profile}"
|
"echo 'export PATH=\"#{sh_quote(path)}:$PATH\"' >> #{profile}"
|
||||||
@ -101,7 +99,7 @@ module Utils
|
|||||||
UNSAFE_SHELL_CHAR = %r{([^A-Za-z0-9_\-.,:/@~\n])}.freeze
|
UNSAFE_SHELL_CHAR = %r{([^A-Za-z0-9_\-.,:/@~\n])}.freeze
|
||||||
|
|
||||||
sig { params(str: String).returns(String) }
|
sig { params(str: String).returns(String) }
|
||||||
def csh_quote(str)
|
def self.csh_quote(str)
|
||||||
# ruby's implementation of shell_escape
|
# ruby's implementation of shell_escape
|
||||||
str = str.to_s
|
str = str.to_s
|
||||||
return "''" if str.empty?
|
return "''" if str.empty?
|
||||||
@ -115,7 +113,7 @@ module Utils
|
|||||||
end
|
end
|
||||||
|
|
||||||
sig { params(str: String).returns(String) }
|
sig { params(str: String).returns(String) }
|
||||||
def sh_quote(str)
|
def self.sh_quote(str)
|
||||||
# ruby's implementation of shell_escape
|
# ruby's implementation of shell_escape
|
||||||
str = str.to_s
|
str = str.to_s
|
||||||
return "''" if str.empty?
|
return "''" if str.empty?
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
|
|
||||||
module Utils
|
|
||||||
module Shell
|
|
||||||
include Kernel
|
|
||||||
end
|
|
||||||
end
|
|
@ -7,8 +7,6 @@ require "warning"
|
|||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
module Warnings
|
module Warnings
|
||||||
module_function
|
|
||||||
|
|
||||||
COMMON_WARNINGS = {
|
COMMON_WARNINGS = {
|
||||||
parser_syntax: [
|
parser_syntax: [
|
||||||
%r{warning: parser/current is loading parser/ruby\d+, which recognizes},
|
%r{warning: parser/current is loading parser/ruby\d+, which recognizes},
|
||||||
@ -17,7 +15,7 @@ module Warnings
|
|||||||
],
|
],
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
def ignore(*warnings)
|
def self.ignore(*warnings)
|
||||||
warnings.map! do |warning|
|
warnings.map! do |warning|
|
||||||
next warning if !warning.is_a?(Symbol) || !COMMON_WARNINGS.key?(warning)
|
next warning if !warning.is_a?(Symbol) || !COMMON_WARNINGS.key?(warning)
|
||||||
|
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
|
|
||||||
module Warnings
|
|
||||||
include Kernel
|
|
||||||
end
|
|
Loading…
x
Reference in New Issue
Block a user