Merge pull request #15057 from dduugg/enable-types
Enable types in Formula files
This commit is contained in:
commit
b97db86a26
@ -1,6 +0,0 @@
|
|||||||
# typed: strict
|
|
||||||
|
|
||||||
class Object
|
|
||||||
sig { returns(T::Boolean) }
|
|
||||||
def present?; end
|
|
||||||
end
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
# typed: false
|
# typed: true
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "cache_store"
|
require "cache_store"
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# typed: false
|
# typed: true
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "deprecate_disable"
|
require "deprecate_disable"
|
||||||
@ -391,7 +391,7 @@ module Homebrew
|
|||||||
"canonical name (#{conflicting_formula.name}) instead of #{conflict.name}"
|
"canonical name (#{conflicting_formula.name}) instead of #{conflict.name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
reverse_conflict_found = false
|
reverse_conflict_found = T.let(false, T::Boolean)
|
||||||
conflicting_formula.conflicts.each do |reverse_conflict|
|
conflicting_formula.conflicts.each do |reverse_conflict|
|
||||||
reverse_conflict_formula = Formulary.factory(reverse_conflict.name)
|
reverse_conflict_formula = Formulary.factory(reverse_conflict.name)
|
||||||
if tap.formula_renames.key?(reverse_conflict.name) || tap.aliases.include?(reverse_conflict.name)
|
if tap.formula_renames.key?(reverse_conflict.name) || tap.aliases.include?(reverse_conflict.name)
|
||||||
@ -732,14 +732,14 @@ module Homebrew
|
|||||||
current_revision = formula.revision
|
current_revision = formula.revision
|
||||||
current_url = formula.stable.url
|
current_url = formula.stable.url
|
||||||
|
|
||||||
previous_version = nil
|
previous_version = T.let(nil, T.nilable(Version))
|
||||||
previous_version_scheme = nil
|
previous_version_scheme = T.let(nil, T.nilable(Integer))
|
||||||
previous_revision = nil
|
previous_revision = T.let(nil, T.nilable(Integer))
|
||||||
|
|
||||||
newest_committed_version = nil
|
newest_committed_version = T.let(nil, T.nilable(Version))
|
||||||
newest_committed_checksum = nil
|
newest_committed_checksum = T.let(nil, T.nilable(String))
|
||||||
newest_committed_revision = nil
|
newest_committed_revision = T.let(nil, T.nilable(Integer))
|
||||||
newest_committed_url = nil
|
newest_committed_url = T.let(nil, T.nilable(String))
|
||||||
|
|
||||||
fv.rev_list("origin/HEAD") do |rev|
|
fv.rev_list("origin/HEAD") do |rev|
|
||||||
begin
|
begin
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# typed: false
|
# typed: true
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "utils/shell"
|
require "utils/shell"
|
||||||
@ -7,6 +7,17 @@ require "utils/shell"
|
|||||||
#
|
#
|
||||||
# @api private
|
# @api private
|
||||||
module FormulaCellarChecks
|
module FormulaCellarChecks
|
||||||
|
extend T::Sig
|
||||||
|
extend T::Helpers
|
||||||
|
|
||||||
|
abstract!
|
||||||
|
|
||||||
|
sig { abstract.returns(Formula) }
|
||||||
|
def formula; end
|
||||||
|
|
||||||
|
sig { abstract.params(output: T.nilable(String)).void }
|
||||||
|
def problem_if_output(output); end
|
||||||
|
|
||||||
def check_env_path(bin)
|
def check_env_path(bin)
|
||||||
# warn the user if stuff was installed outside of their PATH
|
# warn the user if stuff was installed outside of their PATH
|
||||||
return unless bin.directory?
|
return unless bin.directory?
|
||||||
@ -407,7 +418,7 @@ module FormulaCellarChecks
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
has_cpuid_instruction = false
|
has_cpuid_instruction = T.let(false, T::Boolean)
|
||||||
Utils.popen_read(objdump, "--disassemble", file) do |io|
|
Utils.popen_read(objdump, "--disassemble", file) do |io|
|
||||||
until io.eof?
|
until io.eof?
|
||||||
instruction = io.readline.split("\t")[@instruction_column_index[objdump]]&.strip
|
instruction = io.readline.split("\t")[@instruction_column_index[objdump]]&.strip
|
||||||
|
|||||||
5
Library/Homebrew/formula_cellar_checks.rbi
Normal file
5
Library/Homebrew/formula_cellar_checks.rbi
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# typed: strict
|
||||||
|
|
||||||
|
module FormulaCellarChecks
|
||||||
|
include Kernel
|
||||||
|
end
|
||||||
@ -1,4 +1,4 @@
|
|||||||
# typed: false
|
# typed: true
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "formula"
|
require "formula"
|
||||||
@ -653,7 +653,7 @@ on_request: installed_on_request?, options: options)
|
|||||||
inherited_options
|
inherited_options
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(deps: T::Array[[Formula, Options]]).void }
|
sig { params(deps: T::Array[[Dependency, Options]]).void }
|
||||||
def install_dependencies(deps)
|
def install_dependencies(deps)
|
||||||
if deps.empty? && only_deps?
|
if deps.empty? && only_deps?
|
||||||
puts "All dependencies for #{formula.full_name} are satisfied."
|
puts "All dependencies for #{formula.full_name} are satisfied."
|
||||||
@ -745,7 +745,7 @@ on_request: installed_on_request?, options: options)
|
|||||||
fi.finish
|
fi.finish
|
||||||
rescue Exception => e # rubocop:disable Lint/RescueException
|
rescue Exception => e # rubocop:disable Lint/RescueException
|
||||||
ignore_interrupts do
|
ignore_interrupts do
|
||||||
tmp_keg.rename(installed_keg) if tmp_keg && !installed_keg.directory?
|
tmp_keg.rename(installed_keg.to_path) if tmp_keg && !installed_keg.directory?
|
||||||
linked_keg.link(verbose: verbose?) if keg_was_linked
|
linked_keg.link(verbose: verbose?) if keg_was_linked
|
||||||
end
|
end
|
||||||
raise unless e.is_a? FormulaInstallationAlreadyAttemptedError
|
raise unless e.is_a? FormulaInstallationAlreadyAttemptedError
|
||||||
@ -1266,7 +1266,7 @@ on_request: installed_on_request?, options: options)
|
|||||||
keg.relocate_build_prefix(keg, prefix, HOMEBREW_PREFIX)
|
keg.relocate_build_prefix(keg, prefix, HOMEBREW_PREFIX)
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(output: T.nilable(String)).void }
|
sig { override.params(output: T.nilable(String)).void }
|
||||||
def problem_if_output(output)
|
def problem_if_output(output)
|
||||||
return unless output
|
return unless output
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# typed: false
|
# typed: true
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "digest/md5"
|
require "digest/md5"
|
||||||
@ -56,7 +56,7 @@ module Formulary
|
|||||||
namespace = Utils.deconstantize(klass.name)
|
namespace = Utils.deconstantize(klass.name)
|
||||||
next if Utils.deconstantize(namespace) != name
|
next if Utils.deconstantize(namespace) != name
|
||||||
|
|
||||||
remove_const(Utils.demodulize(namespace))
|
remove_const(Utils.demodulize(namespace).to_sym)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -67,6 +67,7 @@ module Formulary
|
|||||||
module PathnameWriteMkpath
|
module PathnameWriteMkpath
|
||||||
refine Pathname do
|
refine Pathname do
|
||||||
def write(content, offset = nil, **open_args)
|
def write(content, offset = nil, **open_args)
|
||||||
|
T.bind(self, Pathname)
|
||||||
raise "Will not overwrite #{self}" if exist? && !offset && !open_args[:mode]&.match?(/^a\+?$/)
|
raise "Will not overwrite #{self}" if exist? && !offset && !open_args[:mode]&.match?(/^a\+?$/)
|
||||||
|
|
||||||
dirname.mkpath
|
dirname.mkpath
|
||||||
@ -129,7 +130,7 @@ module Formulary
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.load_formula_from_api(name, flags:)
|
def self.load_formula_from_api(name, flags:)
|
||||||
namespace = "FormulaNamespaceAPI#{Digest::MD5.hexdigest(name)}"
|
namespace = :"FormulaNamespaceAPI#{Digest::MD5.hexdigest(name)}"
|
||||||
|
|
||||||
mod = Module.new
|
mod = Module.new
|
||||||
remove_const(namespace) if const_defined?(namespace)
|
remove_const(namespace) if const_defined?(namespace)
|
||||||
@ -268,6 +269,7 @@ module Formulary
|
|||||||
service_hash = Homebrew::Service.deserialize(service_hash)
|
service_hash = Homebrew::Service.deserialize(service_hash)
|
||||||
run_params = service_hash.delete(:run)
|
run_params = service_hash.delete(:run)
|
||||||
service do
|
service do
|
||||||
|
T.bind(self, Homebrew::Service)
|
||||||
if run_params.is_a?(Hash)
|
if run_params.is_a?(Hash)
|
||||||
run(**run_params)
|
run(**run_params)
|
||||||
else
|
else
|
||||||
@ -306,7 +308,7 @@ module Formulary
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
klass.loaded_from_api = true
|
T.cast(klass, T.class_of(Formula)).loaded_from_api = true
|
||||||
mod.const_set(class_s, klass)
|
mod.const_set(class_s, klass)
|
||||||
|
|
||||||
cache[:api] ||= {}
|
cache[:api] ||= {}
|
||||||
@ -351,7 +353,7 @@ module Formulary
|
|||||||
|
|
||||||
def self.class_s(name)
|
def self.class_s(name)
|
||||||
class_name = name.capitalize
|
class_name = name.capitalize
|
||||||
class_name.gsub!(/[-_.\s]([a-zA-Z0-9])/) { Regexp.last_match(1).upcase }
|
class_name.gsub!(/[-_.\s]([a-zA-Z0-9])/) { T.must(Regexp.last_match(1)).upcase }
|
||||||
class_name.tr!("+", "x")
|
class_name.tr!("+", "x")
|
||||||
class_name.sub!(/(.)@(\d)/, "\\1AT\\2")
|
class_name.sub!(/(.)@(\d)/, "\\1AT\\2")
|
||||||
class_name
|
class_name
|
||||||
@ -489,17 +491,20 @@ module Formulary
|
|||||||
def initialize(url, from: nil)
|
def initialize(url, from: nil)
|
||||||
@url = url
|
@url = url
|
||||||
@from = from
|
@from = from
|
||||||
uri = URI(url)
|
uri_path = URI(url).path
|
||||||
formula = File.basename(uri.path, ".rb")
|
raise ArgumentError, "URL has no path component" unless uri_path
|
||||||
super formula, HOMEBREW_CACHE_FORMULA/File.basename(uri.path)
|
|
||||||
|
formula = File.basename(uri_path, ".rb")
|
||||||
|
super formula, HOMEBREW_CACHE_FORMULA/File.basename(uri_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_file(flags:, ignore_errors:)
|
def load_file(flags:, ignore_errors:)
|
||||||
if @from != :formula_installer
|
if @from != :formula_installer
|
||||||
if %r{githubusercontent.com/[\w-]+/[\w-]+/[a-f0-9]{40}(?:/Formula)?/(?<formula_name>[\w+-.@]+).rb} =~ url
|
match = url.match(%r{githubusercontent.com/[\w-]+/[\w-]+/[a-f0-9]{40}(?:/Formula)?/(?<name>[\w+-.@]+).rb})
|
||||||
|
if match
|
||||||
raise UnsupportedInstallationMethod,
|
raise UnsupportedInstallationMethod,
|
||||||
"Installation of #{formula_name} from a GitHub commit URL is unsupported! " \
|
"Installation of #{match[:name]} from a GitHub commit URL is unsupported! " \
|
||||||
"`brew extract #{formula_name}` to a stable tap on GitHub instead."
|
"`brew extract #{match[:name]}` to a stable tap on GitHub instead."
|
||||||
elsif url.match?(%r{^(https?|ftp)://})
|
elsif url.match?(%r{^(https?|ftp)://})
|
||||||
raise UnsupportedInstallationMethod,
|
raise UnsupportedInstallationMethod,
|
||||||
"Non-checksummed download of #{name} formula file from an arbitrary URL is unsupported! " \
|
"Non-checksummed download of #{name} formula file from an arbitrary URL is unsupported! " \
|
||||||
@ -512,8 +517,8 @@ module Formulary
|
|||||||
curl_download url, to: path
|
curl_download url, to: path
|
||||||
super
|
super
|
||||||
rescue MethodDeprecatedError => e
|
rescue MethodDeprecatedError => e
|
||||||
if %r{github.com/(?<user>[\w-]+)/(?<repo>[\w-]+)/} =~ url
|
if (match_data = url.match(%r{github.com/(?<user>[\w-]+)/(?<repo>[\w-]+)/}))
|
||||||
e.issues_url = "https://github.com/#{user}/#{repo}/issues/new"
|
e.issues_url = "https://github.com/#{match_data[:user]}/#{match_data[:repo]}/issues/new"
|
||||||
end
|
end
|
||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
|
|||||||
5
Library/Homebrew/formulary.rbi
Normal file
5
Library/Homebrew/formulary.rbi
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# typed: strict
|
||||||
|
|
||||||
|
module Formulary
|
||||||
|
include Kernel
|
||||||
|
end
|
||||||
@ -28,6 +28,7 @@ class Resource
|
|||||||
# formula name before initialization of the formula.
|
# formula name before initialization of the formula.
|
||||||
attr_accessor :name
|
attr_accessor :name
|
||||||
|
|
||||||
|
sig { params(name: T.nilable(String), block: T.nilable(T.proc.bind(Resource).void)).void }
|
||||||
def initialize(name = nil, &block)
|
def initialize(name = nil, &block)
|
||||||
# Ensure this is synced with `initialize_dup` and `freeze` (excluding simple objects like integers and booleans)
|
# Ensure this is synced with `initialize_dup` and `freeze` (excluding simple objects like integers and booleans)
|
||||||
@name = name
|
@name = name
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user