Merge pull request #14937 from dduugg/enable-typing
Enable typing in a few more files
This commit is contained in:
commit
0c1031f2fd
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Cask
|
||||
|
||||
7
Library/Homebrew/cask/metdata.rbi
Normal file
7
Library/Homebrew/cask/metdata.rbi
Normal file
@ -0,0 +1,7 @@
|
||||
# typed: strict
|
||||
|
||||
module Cask
|
||||
module Metadata
|
||||
requires_ancestor { Cask }
|
||||
end
|
||||
end
|
||||
@ -1,5 +1,4 @@
|
||||
# typed: strict
|
||||
# typed: false
|
||||
|
||||
class URL
|
||||
include Kernel
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "formula"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "timeout"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "formulary"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cli/parser"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cli/parser"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cli/parser"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cli/parser"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cli/parser"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "keg"
|
||||
@ -31,7 +31,7 @@ module Homebrew
|
||||
|
||||
def self.checks(type, fatal: true)
|
||||
@checks ||= Checks.new
|
||||
failed = false
|
||||
failed = T.let(false, T::Boolean)
|
||||
@checks.public_send(type).each do |check|
|
||||
out = @checks.public_send(check)
|
||||
next if out.nil?
|
||||
@ -64,6 +64,7 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
|
||||
sig { params(list: T::Array[String], string: String).returns(String) }
|
||||
def inject_file_list(list, string)
|
||||
list.reduce(string.dup) { |acc, elem| acc << " #{elem}\n" }
|
||||
.freeze
|
||||
@ -642,10 +643,11 @@ module Homebrew
|
||||
EOS
|
||||
end
|
||||
|
||||
sig { returns(T.nilable(String)) }
|
||||
def check_git_status
|
||||
return unless Utils::Git.available?
|
||||
|
||||
message = nil
|
||||
message = T.let(nil, T.nilable(String))
|
||||
|
||||
repos = {
|
||||
"Homebrew/brew" => HOMEBREW_REPOSITORY,
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Stdenv
|
||||
@ -7,7 +7,7 @@ module Stdenv
|
||||
undef homebrew_extra_pkg_config_paths
|
||||
|
||||
def homebrew_extra_pkg_config_paths
|
||||
["#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.version}"]
|
||||
[Pathname("#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.version}")]
|
||||
end
|
||||
|
||||
def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false,
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Superenv
|
||||
@ -29,7 +29,7 @@ module Superenv
|
||||
|
||||
# @private
|
||||
def homebrew_extra_pkg_config_paths
|
||||
["/usr/lib/pkgconfig", "#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.version}"]
|
||||
[Pathname("/usr/lib/pkgconfig"), Pathname("#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.version}")]
|
||||
end
|
||||
|
||||
# @private
|
||||
@ -68,7 +68,7 @@ module Superenv
|
||||
end
|
||||
|
||||
def homebrew_extra_cmake_library_paths
|
||||
["#{self["HOMEBREW_SDKROOT"]}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries"]
|
||||
[Pathname("#{self["HOMEBREW_SDKROOT"]}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries")]
|
||||
end
|
||||
|
||||
def homebrew_extra_cmake_frameworks_paths
|
||||
@ -96,7 +96,7 @@ module Superenv
|
||||
end
|
||||
|
||||
self["HOMEBREW_DEVELOPER_DIR"] = if is_xcode_sdk
|
||||
MacOS::Xcode.prefix
|
||||
MacOS::Xcode.prefix.to_s
|
||||
else
|
||||
MacOS::CLT::PKG_PATH
|
||||
end
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Homebrew
|
||||
|
||||
5
Library/Homebrew/formula_assertions.rbi
Normal file
5
Library/Homebrew/formula_assertions.rbi
Normal file
@ -0,0 +1,5 @@
|
||||
# typed: strict
|
||||
|
||||
module Homebrew::Assertions
|
||||
include Kernel
|
||||
end
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Keg
|
||||
@ -44,7 +44,7 @@ class Keg
|
||||
key.is_a?(String) ? key.length : 999
|
||||
end.reverse
|
||||
|
||||
any_changed = false
|
||||
any_changed = T.let(nil, T.nilable(String))
|
||||
sorted_keys.each do |key|
|
||||
changed = text.gsub!(key, replacements[key])
|
||||
any_changed ||= changed
|
||||
@ -144,7 +144,7 @@ class Keg
|
||||
def replace_text_in_files(relocation, files: nil)
|
||||
files ||= text_files | libtool_files
|
||||
|
||||
changed_files = []
|
||||
changed_files = T.let([], Array)
|
||||
files.map(&path.method(:join)).group_by { |f| f.stat.ino }.each_value do |first, *rest|
|
||||
s = first.open("rb", &:read)
|
||||
|
||||
@ -179,11 +179,11 @@ class Keg
|
||||
binary = File.binread file
|
||||
odebug "Replacing build prefix in: #{file}"
|
||||
binary_strings = binary.split(/#{NULL_BYTE}/o, -1)
|
||||
match_indices = binary_strings.each_index.select { |i| binary_strings[i].include?(old_prefix) }
|
||||
match_indices = binary_strings.each_index.select { |i| binary_strings.fetch(i).include?(old_prefix) }
|
||||
|
||||
# Only perform substitution on strings which match prefix regex.
|
||||
match_indices.each do |i|
|
||||
s = binary_strings[i]
|
||||
s = binary_strings.fetch(i)
|
||||
binary_strings[i] = s.gsub(old_prefix, new_prefix)
|
||||
.ljust(s.size, NULL_BYTE)
|
||||
end
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Language
|
||||
|
||||
11
Library/Homebrew/language/python.rbi
Normal file
11
Library/Homebrew/language/python.rbi
Normal file
@ -0,0 +1,11 @@
|
||||
# typed: strict
|
||||
|
||||
module Language::Python
|
||||
module Shebang
|
||||
include Kernel
|
||||
end
|
||||
|
||||
module Virtualenv
|
||||
requires_ancestor { Formula }
|
||||
end
|
||||
end
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
raise "#{__FILE__} must not be loaded via `require`." if $PROGRAM_NAME != __FILE__
|
||||
@ -38,12 +38,10 @@ begin
|
||||
formula.extend(Debrew::Formula) if args.debug?
|
||||
|
||||
ENV.extend(Stdenv)
|
||||
T.cast(ENV, Stdenv).setup_build_environment(formula: formula, testing_formula: true)
|
||||
ENV.setup_build_environment(formula: formula, testing_formula: true)
|
||||
|
||||
# tests can also return false to indicate failure
|
||||
run_test = proc do
|
||||
raise "test returned false" if formula.run_test(keep_tmp: args.keep_tmp?) == false
|
||||
end
|
||||
run_test = proc { |_ = nil| raise "test returned false" if formula.run_test(keep_tmp: args.keep_tmp?) == false }
|
||||
if args.debug? # --debug is interactive
|
||||
run_test.call
|
||||
else
|
||||
|
||||
@ -1,12 +1,10 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Homebrew
|
||||
# Provides helper methods for unlinking formulae and kegs with consistent output.
|
||||
module Unlink
|
||||
module_function
|
||||
|
||||
def unlink_versioned_formulae(formula, verbose: false)
|
||||
def self.unlink_versioned_formulae(formula, verbose: false)
|
||||
formula.versioned_formulae
|
||||
.select(&:keg_only?)
|
||||
.select(&:linked?)
|
||||
@ -18,7 +16,7 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
|
||||
def unlink(keg, dry_run: false, verbose: false)
|
||||
def self.unlink(keg, dry_run: false, verbose: false)
|
||||
options = { dry_run: dry_run, verbose: verbose }
|
||||
|
||||
keg.lock do
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "context"
|
||||
@ -42,7 +42,6 @@ module Utils
|
||||
--data av=#{HOMEBREW_VERSION}
|
||||
]
|
||||
metadata.each do |key, value|
|
||||
next unless key
|
||||
next unless value
|
||||
|
||||
key = ERB::Util.url_encode key
|
||||
@ -146,13 +145,13 @@ module Utils
|
||||
report_influx(measurement, package_and_options, on_request, additional_tags_influx)
|
||||
end
|
||||
|
||||
sig { params(exception: Exception).void }
|
||||
sig { params(exception: BuildError).void }
|
||||
def report_build_error(exception)
|
||||
report_google_build_error(exception)
|
||||
report_influx_error(exception)
|
||||
end
|
||||
|
||||
sig { params(exception: Exception).void }
|
||||
sig { params(exception: BuildError).void }
|
||||
def report_google_build_error(exception)
|
||||
return if not_this_run? || disabled?
|
||||
|
||||
@ -165,10 +164,10 @@ module Utils
|
||||
else
|
||||
formula_full_name
|
||||
end
|
||||
report_google_event("BuildError", package_and_options)
|
||||
report_google_event(:BuildError, package_and_options)
|
||||
end
|
||||
|
||||
sig { params(exception: Exception).void }
|
||||
sig { params(exception: BuildError).void }
|
||||
def report_influx_error(exception)
|
||||
return if not_this_run? || disabled?
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Utils
|
||||
@ -25,7 +25,7 @@ module Utils
|
||||
def formulae_with_no_formula_dependents(formulae)
|
||||
return [] if formulae.blank?
|
||||
|
||||
dependents = []
|
||||
dependents = T.let([], T::Array[Formula])
|
||||
formulae.each do |formula|
|
||||
dependents += formula.runtime_formula_dependencies
|
||||
|
||||
@ -33,7 +33,7 @@ module Utils
|
||||
next if Tab.for_keg(formula.any_installed_keg).poured_from_bottle
|
||||
|
||||
formula.deps.select(&:build?).each do |dep|
|
||||
suppress(FormulaUnavailableError) { dependents << dep.to_formula }
|
||||
Kernel.suppress(FormulaUnavailableError) { dependents << dep.to_formula }
|
||||
end
|
||||
end
|
||||
formulae - dependents
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "open3"
|
||||
@ -243,8 +243,8 @@ module Utils
|
||||
return unless url.start_with? "http"
|
||||
|
||||
secure_url = url.sub(/\Ahttp:/, "https:")
|
||||
secure_details = nil
|
||||
hash_needed = false
|
||||
secure_details = T.let(nil, T.nilable(T::Hash[Symbol, T.untyped]))
|
||||
hash_needed = T.let(false, T::Boolean)
|
||||
if url != secure_url
|
||||
user_agents.each do |user_agent|
|
||||
secure_details = begin
|
||||
@ -267,7 +267,7 @@ module Utils
|
||||
end
|
||||
end
|
||||
|
||||
details = nil
|
||||
details = T.let(nil, T.nilable(T::Hash[Symbol, T.untyped]))
|
||||
user_agents.each do |user_agent|
|
||||
details =
|
||||
curl_http_content_headers_and_checksum(
|
||||
@ -414,7 +414,7 @@ module Utils
|
||||
# Unknown charset in Content-Type header
|
||||
end
|
||||
end
|
||||
file_contents = File.read(file.path, **open_args)
|
||||
file_contents = File.read(T.must(file.path), **open_args)
|
||||
file_hash = Digest::SHA2.hexdigest(file_contents) if hash_needed
|
||||
end
|
||||
|
||||
@ -430,7 +430,7 @@ module Utils
|
||||
responses: responses,
|
||||
}
|
||||
ensure
|
||||
file.unlink
|
||||
T.must(file).unlink
|
||||
end
|
||||
|
||||
def curl_supports_tls13?
|
||||
@ -547,7 +547,7 @@ module Utils
|
||||
return response unless response_text.match?(HTTP_STATUS_LINE_REGEX)
|
||||
|
||||
# Parse the status line and remove it
|
||||
match = response_text.match(HTTP_STATUS_LINE_REGEX)
|
||||
match = T.must(response_text.match(HTTP_STATUS_LINE_REGEX))
|
||||
response[:status_code] = match["code"] if match["code"].present?
|
||||
response[:status_text] = match["text"] if match["text"].present?
|
||||
response_text = response_text.sub(%r{^HTTP/.* (\d+).*$\s*}, "")
|
||||
|
||||
6
Library/Homebrew/utils/curl.rbi
Normal file
6
Library/Homebrew/utils/curl.rbi
Normal file
@ -0,0 +1,6 @@
|
||||
# typed: strict
|
||||
|
||||
module Utils::Curl
|
||||
include Kernel
|
||||
requires_ancestor { SystemCommand::Mixin }
|
||||
end
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "utils/tty"
|
||||
@ -91,11 +91,11 @@ module Formatter
|
||||
end
|
||||
|
||||
fallback.call if objects.empty?
|
||||
fallback.call if respond_to?(:tty?) ? !tty? : !$stdout.tty?
|
||||
fallback.call if respond_to?(:tty?) ? !T.unsafe(self).tty? : !$stdout.tty?
|
||||
|
||||
console_width = Tty.width
|
||||
object_lengths = objects.map { |obj| Tty.strip_ansi(obj).length }
|
||||
cols = (console_width + gap_size) / (object_lengths.max + gap_size)
|
||||
cols = (console_width + gap_size) / (T.must(object_lengths.max) + gap_size)
|
||||
|
||||
fallback.call if cols < 2
|
||||
|
||||
@ -109,14 +109,14 @@ module Formatter
|
||||
output = +""
|
||||
|
||||
rows.times do |row_index|
|
||||
item_indices_for_row = row_index.step(objects.size - 1, rows).to_a
|
||||
item_indices_for_row = T.cast(row_index.step(objects.size - 1, rows).to_a, T::Array[Integer])
|
||||
|
||||
first_n = item_indices_for_row[0...-1].map do |index|
|
||||
objects[index] + "".rjust(col_width - object_lengths[index])
|
||||
first_n = T.must(item_indices_for_row[0...-1]).map do |index|
|
||||
objects[index] + "".rjust(col_width - object_lengths.fetch(index))
|
||||
end
|
||||
|
||||
# don't add trailing whitespace to last column
|
||||
last = objects.values_at(item_indices_for_row.last)
|
||||
last = objects.values_at(item_indices_for_row.fetch(-1))
|
||||
|
||||
output.concat((first_n + last)
|
||||
.join(gap_string))
|
||||
|
||||
5
Library/Homebrew/utils/formatter.rbi
Normal file
5
Library/Homebrew/utils/formatter.rbi
Normal file
@ -0,0 +1,5 @@
|
||||
# typed: strict
|
||||
|
||||
module Formatter
|
||||
include Kernel
|
||||
end
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "tempfile"
|
||||
@ -214,7 +214,7 @@ module GitHub
|
||||
|
||||
headers_tmpfile = Tempfile.new("github_api_headers", HOMEBREW_TEMP)
|
||||
begin
|
||||
if data
|
||||
if data_tmpfile
|
||||
data_tmpfile.write data
|
||||
data_tmpfile.close
|
||||
args += ["--data", "@#{data_tmpfile.path}"]
|
||||
@ -222,7 +222,7 @@ module GitHub
|
||||
args += ["--request", request_method.to_s] if request_method
|
||||
end
|
||||
|
||||
args += ["--dump-header", headers_tmpfile.path]
|
||||
args += ["--dump-header", T.must(headers_tmpfile.path)]
|
||||
|
||||
output, errors, status = curl_output("--location", url.to_s, *args, secrets: [token])
|
||||
output, _, http_code = output.rpartition("\n")
|
||||
|
||||
5
Library/Homebrew/utils/github/api.rbi
Normal file
5
Library/Homebrew/utils/github/api.rbi
Normal file
@ -0,0 +1,5 @@
|
||||
# typed: strict
|
||||
|
||||
module GitHub::API
|
||||
include Kernel
|
||||
end
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "utils/curl"
|
||||
|
||||
6
Library/Homebrew/utils/repology.rbi
Normal file
6
Library/Homebrew/utils/repology.rbi
Normal file
@ -0,0 +1,6 @@
|
||||
# typed: strict
|
||||
|
||||
module Repology
|
||||
include Kernel
|
||||
requires_ancestor { Utils::Curl }
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user