Move include Kernel into .rbi files again and split up existing .rbi files.

This commit is contained in:
Markus Reiter 2020-10-10 17:53:31 +02:00
parent e509b1317e
commit 61b79318ed
38 changed files with 350 additions and 295 deletions

View File

@ -0,0 +1,29 @@
# typed: strict
module Homebrew
module CLI
class Args < OpenStruct
def devel?; end
def HEAD?; end
def include_test?; end
def build_bottle?; end
def build_universal?; end
def build_from_source?; end
def named_args; end
def force_bottle?; end
def debug?; end
def quiet?; end
def verbose?; end
end
end
end

View File

@ -0,0 +1,15 @@
# typed: strict
module Homebrew
module CLI
class Parser
module Compat
include Kernel
module DeprecatedArgs
include Kernel
end
end
end
end
end

View File

@ -0,0 +1,9 @@
# typed: strict
module DependenciesHelpers
module Compat
include Kernel
def args_includes_ignores(args); end
end
end

View File

@ -0,0 +1,7 @@
# typed: strict
class NilClass
module Compat
include Kernel
end
end

View File

@ -0,0 +1,7 @@
# typed: strict
class String
module Compat
include Kernel
end
end

View File

@ -0,0 +1,11 @@
# typed: strict
class Formula
module Compat
include Kernel
def any_installed_keg; end
def latest_installed_prefix; end
end
end

View File

@ -0,0 +1,11 @@
# typed: strict
module OS
module Mac
class << self
module Compat
include Kernel
end
end
end
end

View File

@ -0,0 +1,5 @@
# typed: strict
module Dependable
def tags; end
end

View File

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

View File

@ -3,8 +3,11 @@
require "formula" require "formula"
require "os/linux/glibc" require "os/linux/glibc"
require "system_command"
module SystemConfig module SystemConfig
include SystemCommand::Mixin
HOST_RUBY_PATH = "/usr/bin/ruby" HOST_RUBY_PATH = "/usr/bin/ruby"
class << self class << self

View File

@ -1,8 +1,12 @@
# typed: true # typed: true
# frozen_string_literal: true # frozen_string_literal: true
require "system_command"
module SystemConfig module SystemConfig
class << self class << self
include SystemCommand::Mixin
undef describe_java, describe_homebrew_ruby undef describe_java, describe_homebrew_ruby
def describe_java def describe_java

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,37 +0,0 @@
# typed: strict
module Homebrew::CLI
class Args < OpenStruct
def devel?; end
def HEAD?; end
def include_test?; end
def build_bottle?; end
def build_universal?; end
def build_from_source?; end
def named_args; end
def force_bottle?; end
def debug?; end
def quiet?; end
def verbose?; end
end
class Parser
module Compat
include Kernel
module DeprecatedArgs
include Kernel
end
end
end
end

View File

@ -1,65 +0,0 @@
# typed: strict
module Homebrew
include Kernel
end
module Homebrew::Help
include Kernel
end
module Homebrew::Fetch
def args; end
end
module Homebrew::Install
include Kernel
end
module Language::Perl::Shebang
include Kernel
end
module Dependable
def tags; end
end
module DependenciesHelpers
include Kernel
module Compat
include Kernel
def args_includes_ignores(args); end
end
end
class Formula
module Compat
include Kernel
def latest_version_installed?; end
def active_spec; end
def any_installed_keg; end
def latest_installed_prefix; end
def patches; end
end
end
class NilClass
module Compat
include Kernel
end
end
class String
module Compat
include Kernel
def chomp; end
end
end

View File

@ -1,22 +0,0 @@
# typed: true
module OS
module Linux
include Kernel
def which(cmd, path = ENV["PATH"])
end
end
module Mac
include Kernel
end
end
module OS::Mac
class << self
module Compat
include Kernel
end
end
end

View File

@ -1,4 +1,4 @@
# typed: false # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
# Add your extra requires here # Add your extra requires here

View File

@ -7,26 +7,25 @@ require "plist"
require "shellwords" require "shellwords"
require "extend/io" require "extend/io"
require "extend/predicable"
require "extend/hash_validator" require "extend/hash_validator"
using HashValidator using HashValidator
# Make `system_command` available everywhere.
#
# @api private
module Kernel
def system_command(*args)
SystemCommand.run(*args)
end
def system_command!(*args)
SystemCommand.run!(*args)
end
end
# Class for running sub-processes and capturing their output and exit status. # Class for running sub-processes and capturing their output and exit status.
# #
# @api private # @api private
class SystemCommand class SystemCommand
# Helper functions for calling `SystemCommand.run`.
module Mixin
def system_command(*args)
SystemCommand.run(*args)
end
def system_command!(*args)
SystemCommand.run!(*args)
end
end
include Context include Context
extend Predicable extend Predicable
@ -248,3 +247,7 @@ class SystemCommand
private :warn_plist_garbage private :warn_plist_garbage
end end
end end
# Make `system_command` available everywhere.
# FIXME: Include this explicitly only where it is needed.
include SystemCommand::Mixin # rubocop:disable Style/MixinUsage

View File

@ -5,12 +5,15 @@ require "hardware"
require "software_spec" require "software_spec"
require "development_tools" require "development_tools"
require "extend/ENV" require "extend/ENV"
require "system_command"
# Helper module for querying information about the system configuration. # Helper module for querying information about the system configuration.
# #
# @api private # @api private
module SystemConfig module SystemConfig
class << self class << self
include SystemCommand::Mixin
def clang def clang
@clang ||= if DevelopmentTools.installed? @clang ||= if DevelopmentTools.installed?
DevelopmentTools.clang_version DevelopmentTools.clang_version

View File

@ -1,10 +1,14 @@
# typed: false # typed: false
# frozen_string_literal: true # frozen_string_literal: true
require "system_command"
# Module containing all available strategies for unpacking archives. # Module containing all available strategies for unpacking archives.
# #
# @api private # @api private
module UnpackStrategy module UnpackStrategy
include SystemCommand::Mixin
# Helper module for identifying the file type. # Helper module for identifying the file type.
module Magic module Magic
# Length of the longest regex (currently Tar). # Length of the longest regex (currently Tar).

View File

@ -1,10 +1,13 @@
# typed: true # typed: true
# frozen_string_literal: true # frozen_string_literal: true
require "system_command"
module UnpackStrategy module UnpackStrategy
# Strategy for unpacking Fossil repositories. # Strategy for unpacking Fossil repositories.
class Fossil class Fossil
include UnpackStrategy include UnpackStrategy
extend SystemCommand::Mixin
using Magic using Magic

View File

@ -1,10 +1,13 @@
# typed: true # typed: true
# frozen_string_literal: true # frozen_string_literal: true
require "system_command"
module UnpackStrategy module UnpackStrategy
# Strategy for unpacking tar archives. # Strategy for unpacking tar archives.
class Tar class Tar
include UnpackStrategy include UnpackStrategy
extend SystemCommand::Mixin
using Magic using Magic

View File

@ -8,7 +8,6 @@ module Utils
# #
# @api private # @api private
module Inreplace module Inreplace
include Kernel
extend T::Sig extend T::Sig
# Error during replacement. # Error during replacement.

View File

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

View File

@ -6,8 +6,6 @@ module Utils
# #
# @api private # @api private
module Link module Link
include Kernel
module_function module_function
def 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)

View File

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

View File

@ -6,8 +6,6 @@ module Utils
# #
# @api private # @api private
module Shebang module Shebang
include Kernel
module_function module_function
# Specification on how to rewrite a given shebang. # Specification on how to rewrite a given shebang.

View File

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

View File

@ -3,7 +3,6 @@
module Utils module Utils
module Shell module Shell
include Kernel
extend T::Sig extend T::Sig
module_function module_function

View File

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

View File

@ -8,36 +8,36 @@ module Utils
# #
# @api private # @api private
module Svn module Svn
include Kernel class << self
extend T::Sig extend T::Sig
module_function include SystemCommand::Mixin
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def available? def available?
version.present? version.present?
end end
sig { returns(T.nilable(String)) } sig { returns(T.nilable(String)) }
def version def version
return @version if defined?(@version) return @version if defined?(@version)
stdout, _, status = system_command(HOMEBREW_SHIMS_PATH/"scm/svn", args: ["--version"], print_stderr: false) stdout, _, status = system_command(HOMEBREW_SHIMS_PATH/"scm/svn", args: ["--version"], print_stderr: false)
@version = status.success? ? stdout.chomp[/svn, version (\d+(?:\.\d+)*)/, 1] : nil @version = status.success? ? stdout.chomp[/svn, version (\d+(?:\.\d+)*)/, 1] : nil
end end
sig { params(url: String).returns(T::Boolean) } sig { params(url: String).returns(T::Boolean) }
def remote_exists?(url) def remote_exists?(url)
return true unless available? return true unless available?
# OK to unconditionally trust here because we're just checking if # OK to unconditionally trust here because we're just checking if a URL exists.
# a URL exists. system_command("svn", args: ["ls", url, "--depth", "empty",
quiet_system "svn", "ls", url, "--depth", "empty", "--non-interactive", "--trust-server-cert"], print_stderr: false).success?
"--non-interactive", "--trust-server-cert" end
end
def clear_version_cache def clear_version_cache
remove_instance_variable(:@version) if defined?(@version) remove_instance_variable(:@version) if defined?(@version)
end
end end
end end
end end

View File

@ -6,36 +6,34 @@ module Utils
# #
# @api private # @api private
module Tar module Tar
include Kernel class << self
TAR_FILE_EXTENSIONS = %w[.tar .tb2 .tbz .tbz2 .tgz .tlz .txz .tZ].freeze
module_function def available?
executable.present?
end
TAR_FILE_EXTENSIONS = %w[.tar .tb2 .tbz .tbz2 .tgz .tlz .txz .tZ].freeze def executable
return @executable if defined?(@executable)
def available? gnu_tar_gtar_path = HOMEBREW_PREFIX/"opt/gnu-tar/bin/gtar"
executable.present? gnu_tar_gtar = gnu_tar_gtar_path if gnu_tar_gtar_path.executable?
end @executable = which("gtar") || gnu_tar_gtar || which("tar")
end
def executable def validate_file(path)
return @executable if defined?(@executable) return unless available?
gnu_tar_gtar_path = HOMEBREW_PREFIX/"opt/gnu-tar/bin/gtar" path = Pathname.new(path)
gnu_tar_gtar = gnu_tar_gtar_path if gnu_tar_gtar_path.executable? return unless TAR_FILE_EXTENSIONS.include? path.extname
@executable = which("gtar") || gnu_tar_gtar || which("tar") return if Utils.popen_read(executable, "-tf", path).match?(%r{/.*\.})
end
def validate_file(path) odie "#{path} is not a valid tar file!"
return unless available? end
path = Pathname.new(path) def clear_executable_cache
return unless TAR_FILE_EXTENSIONS.include? path.extname remove_instance_variable(:@executable) if defined?(@executable)
return if Utils.popen_read(executable, "-tf", path).match?(%r{/.*\.}) end
odie "#{path} is not a valid tar file!"
end
def clear_executable_cache
remove_instance_variable(:@executable) if defined?(@executable)
end end
end end
end end

View File

@ -5,122 +5,116 @@
# #
# @api private # @api private
module Tty module Tty
include Kernel
extend T::Sig
@stream = $stdout @stream = $stdout
module_function class << self
extend T::Sig
sig { params(stream: IO, _block: T.proc.params(arg0: IO).void).void } sig { params(stream: T.any(IO, StringIO), _block: T.proc.params(arg0: T.any(IO, StringIO)).void).void }
def with(stream, &_block) def with(stream, &_block)
previous_stream = @stream previous_stream = @stream
@stream = stream @stream = stream
yield stream yield stream
ensure ensure
@stream = previous_stream @stream = previous_stream
end
sig { params(string: String).returns(String) }
def strip_ansi(string)
string.gsub(/\033\[\d+(;\d+)*m/, "")
end
sig { returns(Integer) }
def width
@width ||= begin
_, width = `/bin/stty size 2>/dev/null`.split
width, = `/usr/bin/tput cols 2>/dev/null`.split if width.to_i.zero?
width ||= 80
width.to_i
end end
end
sig { params(string: String).returns(String) } sig { params(string: String).returns(String) }
def truncate(string) def strip_ansi(string)
(w = width).zero? ? string.to_s : (string.to_s[0, w - 4] || "") string.gsub(/\033\[\d+(;\d+)*m/, "")
end
COLOR_CODES = {
red: 31,
green: 32,
yellow: 33,
blue: 34,
magenta: 35,
cyan: 36,
default: 39,
}.freeze
STYLE_CODES = {
reset: 0,
bold: 1,
italic: 3,
underline: 4,
strikethrough: 9,
no_underline: 24,
}.freeze
SPECIAL_CODES = {
up: "1A",
down: "1B",
right: "1C",
left: "1D",
erase_line: "K",
erase_char: "P",
}.freeze
CODES = COLOR_CODES.merge(STYLE_CODES).freeze
sig { params(code: Integer).returns(T.self_type) }
def append_to_escape_sequence(code)
@escape_sequence ||= []
@escape_sequence << code
self
end
sig { returns(String) }
def current_escape_sequence
return "" if @escape_sequence.nil?
"\033[#{@escape_sequence.join(";")}m"
end
sig { void }
def reset_escape_sequence!
@escape_sequence = nil
end
CODES.each do |name, code|
define_singleton_method(name) do
append_to_escape_sequence(code)
end end
end
SPECIAL_CODES.each do |name, code| sig { returns(Integer) }
define_singleton_method(name) do def width
if @stream.tty? @width ||= begin
"\033[#{code}" _, width = `/bin/stty size 2>/dev/null`.split
else width, = `/usr/bin/tput cols 2>/dev/null`.split if width.to_i.zero?
"" width ||= 80
width.to_i
end end
end end
end
sig { returns(String) } sig { params(string: String).returns(String) }
def to_s def truncate(string)
return "" unless color? (w = width).zero? ? string.to_s : (string.to_s[0, w - 4] || "")
end
current_escape_sequence COLOR_CODES = {
ensure red: 31,
reset_escape_sequence! green: 32,
end yellow: 33,
blue: 34,
magenta: 35,
cyan: 36,
default: 39,
}.freeze
sig { returns(T::Boolean) } STYLE_CODES = {
def color? reset: 0,
return false if Homebrew::EnvConfig.no_color? bold: 1,
return true if Homebrew::EnvConfig.color? italic: 3,
underline: 4,
strikethrough: 9,
no_underline: 24,
}.freeze
@stream.tty? SPECIAL_CODES = {
end up: "1A",
down: "1B",
right: "1C",
left: "1D",
erase_line: "K",
erase_char: "P",
}.freeze
CODES = COLOR_CODES.merge(STYLE_CODES).freeze
sig { returns(String) }
def current_escape_sequence
return "" if @escape_sequence.nil?
"\033[#{@escape_sequence.join(";")}m"
end
sig { void }
def reset_escape_sequence!
@escape_sequence = nil
end
CODES.each do |name, code|
define_method(name) do
@escape_sequence ||= []
@escape_sequence << code
self
end
end
SPECIAL_CODES.each do |name, code|
define_method(name) do
if @stream.tty?
"\033[#{code}"
else
""
end
end
end
sig { returns(String) }
def to_s
return "" unless color?
current_escape_sequence
ensure
reset_escape_sequence!
end
sig { returns(T::Boolean) }
def color?
return false if Homebrew::EnvConfig.no_color?
return true if Homebrew::EnvConfig.color?
@stream.tty?
end
end
end end

View File

@ -10,9 +10,10 @@ require "system_command"
# #
# @api private # @api private
class User < SimpleDelegator class User < SimpleDelegator
include Kernel
extend T::Sig extend T::Sig
include SystemCommand::Mixin
# Return whether the user has an active GUI session. # Return whether the user has an active GUI session.
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def gui? def gui?