mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Bump more files to Sorbet typed: strict
This commit is contained in:
parent
0c268f9234
commit
268f801038
@ -284,6 +284,7 @@ Sorbet/StrictSigil:
|
|||||||
- "Taps/**/*"
|
- "Taps/**/*"
|
||||||
- "/**/{Formula,Casks}/**/*.rb"
|
- "/**/{Formula,Casks}/**/*.rb"
|
||||||
- "**/{Formula,Casks}/**/*.rb"
|
- "**/{Formula,Casks}/**/*.rb"
|
||||||
|
- "Homebrew/utils/ruby_check_version_script.rb" # A standalone script.
|
||||||
- "Homebrew/{standalone,startup}/*.rb" # These are loaded before sorbet-runtime
|
- "Homebrew/{standalone,startup}/*.rb" # These are loaded before sorbet-runtime
|
||||||
- "Homebrew/test/**/*.rb"
|
- "Homebrew/test/**/*.rb"
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# typed: true # rubocop:todo Sorbet/StrictSigil
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "extend/cachable"
|
require "extend/cachable"
|
||||||
@ -15,7 +15,7 @@ module Homebrew
|
|||||||
|
|
||||||
private_class_method :cache
|
private_class_method :cache
|
||||||
|
|
||||||
sig { params(name: String).returns(Hash) }
|
sig { params(name: String).returns(T::Hash[String, T.untyped]) }
|
||||||
def self.fetch(name)
|
def self.fetch(name)
|
||||||
Homebrew::API.fetch "formula/#{name}.json"
|
Homebrew::API.fetch "formula/#{name}.json"
|
||||||
end
|
end
|
||||||
@ -41,6 +41,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(Pathname) }
|
||||||
def self.cached_json_file_path
|
def self.cached_json_file_path
|
||||||
if Homebrew::API.internal_json_v3?
|
if Homebrew::API.internal_json_v3?
|
||||||
HOMEBREW_CACHE_API/INTERNAL_V3_API_FILENAME
|
HOMEBREW_CACHE_API/INTERNAL_V3_API_FILENAME
|
||||||
@ -75,7 +76,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
private_class_method :download_and_cache_data!
|
private_class_method :download_and_cache_data!
|
||||||
|
|
||||||
sig { returns(T::Hash[String, Hash]) }
|
sig { returns(T::Hash[String, T.untyped]) }
|
||||||
def self.all_formulae
|
def self.all_formulae
|
||||||
unless cache.key?("formulae")
|
unless cache.key?("formulae")
|
||||||
json_updated = download_and_cache_data!
|
json_updated = download_and_cache_data!
|
||||||
@ -105,7 +106,7 @@ module Homebrew
|
|||||||
cache["renames"]
|
cache["renames"]
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(Hash) }
|
sig { returns(T::Hash[String, T.untyped]) }
|
||||||
def self.tap_migrations
|
def self.tap_migrations
|
||||||
# Not sure that we need to reload here.
|
# Not sure that we need to reload here.
|
||||||
unless cache.key?("tap_migrations")
|
unless cache.key?("tap_migrations")
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# typed: true # rubocop:todo Sorbet/StrictSigil
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "system_command"
|
require "system_command"
|
||||||
@ -51,14 +51,15 @@ module Homebrew
|
|||||||
# Remove version from short version, if present.
|
# Remove version from short version, if present.
|
||||||
short_version = short_version&.sub(/\s*\(#{Regexp.escape(version)}\)\Z/, "") if version
|
short_version = short_version&.sub(/\s*\(#{Regexp.escape(version)}\)\Z/, "") if version
|
||||||
|
|
||||||
@short_version = short_version.presence
|
@short_version = T.let(short_version.presence, T.nilable(String))
|
||||||
@version = version.presence
|
@version = T.let(version.presence, T.nilable(String))
|
||||||
|
|
||||||
return if @short_version || @version
|
return if @short_version || @version
|
||||||
|
|
||||||
raise ArgumentError, "`short_version` and `version` cannot both be `nil` or empty"
|
raise ArgumentError, "`short_version` and `version` cannot both be `nil` or empty"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(other: BundleVersion).returns(T.any(Integer, NilClass)) }
|
||||||
def <=>(other)
|
def <=>(other)
|
||||||
return super unless instance_of?(other.class)
|
return super unless instance_of?(other.class)
|
||||||
|
|
||||||
@ -82,6 +83,7 @@ module Homebrew
|
|||||||
difference
|
difference
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(other: BundleVersion).returns(T::Boolean) }
|
||||||
def ==(other)
|
def ==(other)
|
||||||
instance_of?(other.class) && short_version == other.short_version && version == other.version
|
instance_of?(other.class) && short_version == other.short_version && version == other.version
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# typed: true # rubocop:todo Sorbet/StrictSigil
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "requirement"
|
require "requirement"
|
||||||
@ -12,66 +12,82 @@ class CaskDependent
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(Cask::Cask) }
|
||||||
attr_reader :cask
|
attr_reader :cask
|
||||||
|
|
||||||
|
sig { params(cask: Cask::Cask).void }
|
||||||
def initialize(cask)
|
def initialize(cask)
|
||||||
@cask = cask
|
@cask = T.let(cask, Cask::Cask)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(String) }
|
||||||
def name
|
def name
|
||||||
@cask.token
|
@cask.token
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(String) }
|
||||||
def full_name
|
def full_name
|
||||||
@cask.full_name
|
@cask.full_name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Array[Dependency]) }
|
||||||
def runtime_dependencies
|
def runtime_dependencies
|
||||||
deps.flat_map { |dep| [dep, *dep.to_formula.runtime_dependencies] }.uniq
|
deps.flat_map { |dep| [dep, *dep.to_formula.runtime_dependencies] }.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Array[Dependency]) }
|
||||||
def deps
|
def deps
|
||||||
@deps ||= @cask.depends_on.formula.map do |f|
|
@deps ||= T.let(
|
||||||
Dependency.new f
|
@cask.depends_on.formula.map do |f|
|
||||||
end
|
Dependency.new f
|
||||||
|
end,
|
||||||
|
T.nilable(T::Array[Dependency]),
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Array[CaskDependent::Requirement]) }
|
||||||
def requirements
|
def requirements
|
||||||
@requirements ||= begin
|
@requirements ||= T.let(
|
||||||
requirements = []
|
begin
|
||||||
dsl_reqs = @cask.depends_on
|
requirements = []
|
||||||
|
dsl_reqs = @cask.depends_on
|
||||||
|
|
||||||
dsl_reqs.arch&.each do |arch|
|
dsl_reqs.arch&.each do |arch|
|
||||||
arch = if arch[:bits] == 64
|
arch = if arch[:bits] == 64
|
||||||
if arch[:type] == :intel
|
if arch[:type] == :intel
|
||||||
:x86_64
|
:x86_64
|
||||||
|
else
|
||||||
|
:"#{arch[:type]}64"
|
||||||
|
end
|
||||||
|
elsif arch[:type] == :intel && arch[:bits] == 32
|
||||||
|
:i386
|
||||||
else
|
else
|
||||||
:"#{arch[:type]}64"
|
arch[:type]
|
||||||
end
|
end
|
||||||
elsif arch[:type] == :intel && arch[:bits] == 32
|
requirements << ArchRequirement.new([arch])
|
||||||
:i386
|
|
||||||
else
|
|
||||||
arch[:type]
|
|
||||||
end
|
end
|
||||||
requirements << ArchRequirement.new([arch])
|
dsl_reqs.cask.each do |cask_ref|
|
||||||
end
|
requirements << CaskDependent::Requirement.new([{ cask: cask_ref }])
|
||||||
dsl_reqs.cask.each do |cask_ref|
|
end
|
||||||
requirements << CaskDependent::Requirement.new([{ cask: cask_ref }])
|
requirements << dsl_reqs.macos if dsl_reqs.macos
|
||||||
end
|
|
||||||
requirements << dsl_reqs.macos if dsl_reqs.macos
|
|
||||||
|
|
||||||
requirements
|
requirements
|
||||||
end
|
end,
|
||||||
|
T.nilable(T::Array[CaskDependent::Requirement]),
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(block: T.nilable(T.proc.returns(T::Array[Dependency]))).returns(T::Array[Dependency]) }
|
||||||
def recursive_dependencies(&block)
|
def recursive_dependencies(&block)
|
||||||
Dependency.expand(self, &block)
|
Dependency.expand(self, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(block: T.nilable(T.proc.returns(CaskDependent::Requirement))).returns(Requirements) }
|
||||||
def recursive_requirements(&block)
|
def recursive_requirements(&block)
|
||||||
Requirement.expand(self, &block)
|
Requirement.expand(self, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Boolean) }
|
||||||
def any_version_installed?
|
def any_version_installed?
|
||||||
@cask.installed?
|
@cask.installed?
|
||||||
end
|
end
|
||||||
|
@ -186,8 +186,8 @@ module Homebrew
|
|||||||
cask: Cask::Cask,
|
cask: Cask::Cask,
|
||||||
new_hash: T.any(NilClass, String, Symbol),
|
new_hash: T.any(NilClass, String, Symbol),
|
||||||
new_version: BumpVersionParser,
|
new_version: BumpVersionParser,
|
||||||
replacement_pairs: T::Array[[T.any(Regexp, String), T.any(Regexp, String)]],
|
replacement_pairs: T::Array[[T.any(Regexp, String), T.any(Pathname, String)]],
|
||||||
).returns(T::Array[[T.any(Regexp, String), T.any(Regexp, String)]])
|
).returns(T::Array[[T.any(Regexp, String), T.any(Pathname, String)]])
|
||||||
}
|
}
|
||||||
def replace_version_and_checksum(cask, new_hash, new_version, replacement_pairs)
|
def replace_version_and_checksum(cask, new_hash, new_version, replacement_pairs)
|
||||||
# When blocks are absent, arch is not relevant. For consistency, we simulate the arm architecture.
|
# When blocks are absent, arch is not relevant. For consistency, we simulate the arm architecture.
|
||||||
|
@ -1,17 +1,20 @@
|
|||||||
# typed: true # rubocop:todo Sorbet/StrictSigil
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# Formula information drawn from an external `brew info --json` call.
|
# Formula information drawn from an external `brew info --json` call.
|
||||||
class FormulaInfo
|
class FormulaInfo
|
||||||
# The whole info structure parsed from the JSON.
|
# The whole info structure parsed from the JSON.
|
||||||
|
sig { returns(T::Hash[String, T.untyped]) }
|
||||||
attr_accessor :info
|
attr_accessor :info
|
||||||
|
|
||||||
|
sig { params(info: T::Hash[String, T.untyped]).void }
|
||||||
def initialize(info)
|
def initialize(info)
|
||||||
@info = info
|
@info = T.let(info, T::Hash[String, T.untyped])
|
||||||
end
|
end
|
||||||
|
|
||||||
# Looks up formula on disk and reads its info.
|
# Looks up formula on disk and reads its info.
|
||||||
# Returns nil if formula is absent or if there was an error reading it.
|
# Returns nil if formula is absent or if there was an error reading it.
|
||||||
|
sig { params(name: Pathname).returns(T.nilable(FormulaInfo)) }
|
||||||
def self.lookup(name)
|
def self.lookup(name)
|
||||||
json = Utils.popen_read(
|
json = Utils.popen_read(
|
||||||
*HOMEBREW_RUBY_EXEC_ARGS,
|
*HOMEBREW_RUBY_EXEC_ARGS,
|
||||||
@ -27,12 +30,16 @@ class FormulaInfo
|
|||||||
FormulaInfo.new(JSON.parse(json)[0])
|
FormulaInfo.new(JSON.parse(json)[0])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Array[String]) }
|
||||||
def bottle_tags
|
def bottle_tags
|
||||||
return [] unless info["bottle"]["stable"]
|
return [] unless info["bottle"]["stable"]
|
||||||
|
|
||||||
info["bottle"]["stable"]["files"].keys
|
info["bottle"]["stable"]["files"].keys
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig {
|
||||||
|
params(my_bottle_tag: T.any(Utils::Bottles::Tag, T.nilable(String))).returns(T.nilable(T::Hash[String, String]))
|
||||||
|
}
|
||||||
def bottle_info(my_bottle_tag = Utils::Bottles.tag)
|
def bottle_info(my_bottle_tag = Utils::Bottles.tag)
|
||||||
tag_s = my_bottle_tag.to_s
|
tag_s = my_bottle_tag.to_s
|
||||||
return unless info["bottle"]["stable"]
|
return unless info["bottle"]["stable"]
|
||||||
@ -43,29 +50,35 @@ class FormulaInfo
|
|||||||
{ "url" => btl_info["url"], "sha256" => btl_info["sha256"] }
|
{ "url" => btl_info["url"], "sha256" => btl_info["sha256"] }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T.nilable(T::Hash[String, String])) }
|
||||||
def bottle_info_any
|
def bottle_info_any
|
||||||
bottle_info(any_bottle_tag)
|
bottle_info(any_bottle_tag)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T.nilable(String)) }
|
||||||
def any_bottle_tag
|
def any_bottle_tag
|
||||||
tag = Utils::Bottles.tag.to_s
|
tag = Utils::Bottles.tag.to_s
|
||||||
# Prefer native bottles as a convenience for download caching
|
# Prefer native bottles as a convenience for download caching
|
||||||
bottle_tags.include?(tag) ? tag : bottle_tags.first
|
bottle_tags.include?(tag) ? tag : bottle_tags.first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(spec_type: Symbol).returns(Version) }
|
||||||
def version(spec_type)
|
def version(spec_type)
|
||||||
version_str = info["versions"][spec_type.to_s]
|
version_str = info["versions"][spec_type.to_s]
|
||||||
version_str && Version.new(version_str)
|
Version.new(version_str)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(spec_type: Symbol).returns(PkgVersion) }
|
||||||
def pkg_version(spec_type = :stable)
|
def pkg_version(spec_type = :stable)
|
||||||
PkgVersion.new(version(spec_type), revision)
|
PkgVersion.new(version(spec_type), revision)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(Integer) }
|
||||||
def revision
|
def revision
|
||||||
info["revision"]
|
info["revision"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(str: String).void }
|
||||||
def self.force_utf8!(str)
|
def self.force_utf8!(str)
|
||||||
str.force_encoding("UTF-8") if str.respond_to?(:force_encoding)
|
str.force_encoding("UTF-8") if str.respond_to?(:force_encoding)
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# typed: true # rubocop:todo Sorbet/StrictSigil
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "utils/string_inreplace_extension"
|
require "utils/string_inreplace_extension"
|
||||||
@ -8,6 +8,7 @@ module Utils
|
|||||||
module Inreplace
|
module Inreplace
|
||||||
# Error during text replacement.
|
# Error during text replacement.
|
||||||
class Error < RuntimeError
|
class Error < RuntimeError
|
||||||
|
sig { params(errors: T::Hash[String, T::Array[String]]).void }
|
||||||
def initialize(errors)
|
def initialize(errors)
|
||||||
formatted_errors = errors.reduce(+"inreplace failed\n") do |s, (path, errs)|
|
formatted_errors = errors.reduce(+"inreplace failed\n") do |s, (path, errs)|
|
||||||
s << "#{path}:\n" << errs.map { |e| " #{e}\n" }.join
|
s << "#{path}:\n" << errs.map { |e| " #{e}\n" }.join
|
||||||
@ -82,12 +83,19 @@ module Utils
|
|||||||
raise Utils::Inreplace::Error, errors if errors.present?
|
raise Utils::Inreplace::Error, errors if errors.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig {
|
||||||
|
params(
|
||||||
|
path: T.any(String, Pathname),
|
||||||
|
replacement_pairs: T::Array[[T.any(Regexp, Pathname, String), T.any(Pathname, String)]],
|
||||||
|
read_only_run: T::Boolean,
|
||||||
|
silent: T::Boolean,
|
||||||
|
).returns(String)
|
||||||
|
}
|
||||||
def self.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|
|
||||||
ohai "replace #{old.inspect} with #{new.inspect}" unless silent
|
if old.blank?
|
||||||
unless old
|
|
||||||
contents.errors << "No old value for new value #{new}! Did you pass the wrong arguments?"
|
contents.errors << "No old value for new value #{new}! Did you pass the wrong arguments?"
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# typed: true # rubocop:todo Sorbet/StrictSigil
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "utils/curl"
|
require "utils/curl"
|
||||||
@ -10,6 +10,7 @@ module Repology
|
|||||||
MAX_PAGINATION = 15
|
MAX_PAGINATION = 15
|
||||||
private_constant :MAX_PAGINATION
|
private_constant :MAX_PAGINATION
|
||||||
|
|
||||||
|
sig { params(last_package_in_response: T.nilable(String), repository: String).returns(T::Hash[String, T.untyped]) }
|
||||||
def self.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"
|
||||||
@ -27,6 +28,7 @@ module Repology
|
|||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(name: String, repository: String).returns(T.nilable(T::Hash[String, T.untyped])) }
|
||||||
def self.single_package_query(name, repository:)
|
def self.single_package_query(name, repository:)
|
||||||
url = "https://repology.org/api/v1/project/#{name}"
|
url = "https://repology.org/api/v1/project/#{name}"
|
||||||
|
|
||||||
@ -47,6 +49,13 @@ module Repology
|
|||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig {
|
||||||
|
params(
|
||||||
|
limit: T.nilable(Integer),
|
||||||
|
last_package: T.nilable(String),
|
||||||
|
repository: String,
|
||||||
|
).returns(T::Hash[String, T.untyped])
|
||||||
|
}
|
||||||
def self.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
|
||||||
@ -80,6 +89,7 @@ module Repology
|
|||||||
outdated_packages.sort.to_h
|
outdated_packages.sort.to_h
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(repositories: T::Array[String]).returns(T.any(String, Version)) }
|
||||||
def self.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.
|
||||||
@ -97,6 +107,6 @@ module Repology
|
|||||||
# scheme
|
# scheme
|
||||||
return "no latest version" if latest_version.blank?
|
return "no latest version" if latest_version.blank?
|
||||||
|
|
||||||
Version.new(latest_version["version"])
|
Version.new(T.must(latest_version["version"]))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
# typed: true # rubocop:todo Sorbet/StrictSigil
|
# typed: true
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
HOMEBREW_REQUIRED_RUBY_VERSION = ARGV.first.freeze
|
HOMEBREW_REQUIRED_RUBY_VERSION = ARGV.first.freeze
|
||||||
|
Loading…
x
Reference in New Issue
Block a user