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 "os/linux/glibc"
require "system_command"
module SystemConfig
include SystemCommand::Mixin
HOST_RUBY_PATH = "/usr/bin/ruby"
class << self

View File

@ -1,8 +1,12 @@
# typed: true
# frozen_string_literal: true
require "system_command"
module SystemConfig
class << self
include SystemCommand::Mixin
undef describe_java, describe_homebrew_ruby
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
# Add your extra requires here

View File

@ -7,26 +7,25 @@ require "plist"
require "shellwords"
require "extend/io"
require "extend/predicable"
require "extend/hash_validator"
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.
#
# @api private
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
extend Predicable
@ -248,3 +247,7 @@ class SystemCommand
private :warn_plist_garbage
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 "development_tools"
require "extend/ENV"
require "system_command"
# Helper module for querying information about the system configuration.
#
# @api private
module SystemConfig
class << self
include SystemCommand::Mixin
def clang
@clang ||= if DevelopmentTools.installed?
DevelopmentTools.clang_version

View File

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

View File

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

View File

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

View File

@ -8,7 +8,6 @@ module Utils
#
# @api private
module Inreplace
include Kernel
extend T::Sig
# 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
module Link
include Kernel
module_function
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
module Shebang
include Kernel
module_function
# 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 Shell
include Kernel
extend T::Sig
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
module Svn
include Kernel
extend T::Sig
class << self
extend T::Sig
module_function
include SystemCommand::Mixin
sig { returns(T::Boolean) }
def available?
version.present?
end
sig { returns(T::Boolean) }
def available?
version.present?
end
sig { returns(T.nilable(String)) }
def version
return @version if defined?(@version)
sig { returns(T.nilable(String)) }
def version
return @version if defined?(@version)
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
end
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
end
sig { params(url: String).returns(T::Boolean) }
def remote_exists?(url)
return true unless available?
sig { params(url: String).returns(T::Boolean) }
def remote_exists?(url)
return true unless available?
# OK to unconditionally trust here because we're just checking if
# a URL exists.
quiet_system "svn", "ls", url, "--depth", "empty",
"--non-interactive", "--trust-server-cert"
end
# OK to unconditionally trust here because we're just checking if a URL exists.
system_command("svn", args: ["ls", url, "--depth", "empty",
"--non-interactive", "--trust-server-cert"], print_stderr: false).success?
end
def clear_version_cache
remove_instance_variable(:@version) if defined?(@version)
def clear_version_cache
remove_instance_variable(:@version) if defined?(@version)
end
end
end
end

View File

@ -6,36 +6,34 @@ module Utils
#
# @api private
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?
executable.present?
end
gnu_tar_gtar_path = HOMEBREW_PREFIX/"opt/gnu-tar/bin/gtar"
gnu_tar_gtar = gnu_tar_gtar_path if gnu_tar_gtar_path.executable?
@executable = which("gtar") || gnu_tar_gtar || which("tar")
end
def executable
return @executable if defined?(@executable)
def validate_file(path)
return unless available?
gnu_tar_gtar_path = HOMEBREW_PREFIX/"opt/gnu-tar/bin/gtar"
gnu_tar_gtar = gnu_tar_gtar_path if gnu_tar_gtar_path.executable?
@executable = which("gtar") || gnu_tar_gtar || which("tar")
end
path = Pathname.new(path)
return unless TAR_FILE_EXTENSIONS.include? path.extname
return if Utils.popen_read(executable, "-tf", path).match?(%r{/.*\.})
def validate_file(path)
return unless available?
odie "#{path} is not a valid tar file!"
end
path = Pathname.new(path)
return unless TAR_FILE_EXTENSIONS.include? path.extname
return if Utils.popen_read(executable, "-tf", path).match?(%r{/.*\.})
odie "#{path} is not a valid tar file!"
end
def clear_executable_cache
remove_instance_variable(:@executable) if defined?(@executable)
def clear_executable_cache
remove_instance_variable(:@executable) if defined?(@executable)
end
end
end
end

View File

@ -5,122 +5,116 @@
#
# @api private
module Tty
include Kernel
extend T::Sig
@stream = $stdout
module_function
class << self
extend T::Sig
sig { params(stream: IO, _block: T.proc.params(arg0: IO).void).void }
def with(stream, &_block)
previous_stream = @stream
@stream = stream
sig { params(stream: T.any(IO, StringIO), _block: T.proc.params(arg0: T.any(IO, StringIO)).void).void }
def with(stream, &_block)
previous_stream = @stream
@stream = stream
yield stream
ensure
@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
yield stream
ensure
@stream = previous_stream
end
end
sig { params(string: String).returns(String) }
def truncate(string)
(w = width).zero? ? string.to_s : (string.to_s[0, w - 4] || "")
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)
sig { params(string: String).returns(String) }
def strip_ansi(string)
string.gsub(/\033\[\d+(;\d+)*m/, "")
end
end
SPECIAL_CODES.each do |name, code|
define_singleton_method(name) do
if @stream.tty?
"\033[#{code}"
else
""
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 { returns(String) }
def to_s
return "" unless color?
sig { params(string: String).returns(String) }
def truncate(string)
(w = width).zero? ? string.to_s : (string.to_s[0, w - 4] || "")
end
current_escape_sequence
ensure
reset_escape_sequence!
end
COLOR_CODES = {
red: 31,
green: 32,
yellow: 33,
blue: 34,
magenta: 35,
cyan: 36,
default: 39,
}.freeze
sig { returns(T::Boolean) }
def color?
return false if Homebrew::EnvConfig.no_color?
return true if Homebrew::EnvConfig.color?
STYLE_CODES = {
reset: 0,
bold: 1,
italic: 3,
underline: 4,
strikethrough: 9,
no_underline: 24,
}.freeze
@stream.tty?
end
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 { 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

View File

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