mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Enable more typing
This commit is contained in:
parent
b4aac9d4a0
commit
04fa6e24d7
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
# This script is loaded by formula_installer as a separate instance.
|
||||
@ -235,12 +235,12 @@ rescue Exception => e # rubocop:disable Lint/RescueException
|
||||
# BuildErrors are specific to build processes and not other
|
||||
# children, which is why we create the necessary state here
|
||||
# and not in Utils.safe_fork.
|
||||
case error_hash["json_class"]
|
||||
when "BuildError"
|
||||
case e
|
||||
when BuildError
|
||||
error_hash["cmd"] = e.cmd
|
||||
error_hash["args"] = e.args
|
||||
error_hash["env"] = e.env
|
||||
when "ErrorDuringExecution"
|
||||
when ErrorDuringExecution
|
||||
error_hash["cmd"] = e.cmd
|
||||
error_hash["status"] = if e.status.is_a?(Process::Status)
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cask/cask_loader"
|
||||
@ -83,6 +83,19 @@ module Cask
|
||||
@tap
|
||||
end
|
||||
|
||||
sig {
|
||||
params(
|
||||
token: String,
|
||||
sourcefile_path: T.nilable(Pathname),
|
||||
source: T.nilable(String),
|
||||
tap: T.nilable(Tap),
|
||||
loaded_from_api: T::Boolean,
|
||||
config: T.nilable(Config),
|
||||
allow_reassignment: T::Boolean,
|
||||
loader: T.nilable(CaskLoader::ILoader),
|
||||
block: T.nilable(T.proc.bind(DSL).void),
|
||||
).void
|
||||
}
|
||||
def initialize(token, sourcefile_path: nil, source: nil, tap: nil, loaded_from_api: false,
|
||||
config: nil, allow_reassignment: false, loader: nil, &block)
|
||||
@token = token
|
||||
@ -92,7 +105,8 @@ module Cask
|
||||
@allow_reassignment = allow_reassignment
|
||||
@loaded_from_api = loaded_from_api
|
||||
@loader = loader
|
||||
@block = block
|
||||
# https://github.com/sorbet/sorbet/issues/6843
|
||||
instance_variable_set(:@block, block)
|
||||
|
||||
@default_config = config || Config.new
|
||||
|
||||
@ -123,9 +137,10 @@ module Cask
|
||||
|
||||
sig { returns(T::Array[[String, String]]) }
|
||||
def timestamped_versions
|
||||
Pathname.glob(metadata_timestamped_path(version: "*", timestamp: "*"))
|
||||
relative_paths = Pathname.glob(metadata_timestamped_path(version: "*", timestamp: "*"))
|
||||
.map { |p| p.relative_path_from(p.parent.parent) }
|
||||
.sort_by(&:basename) # sort by timestamp
|
||||
# https://github.com/sorbet/sorbet/issues/6844
|
||||
T.unsafe(relative_paths).sort_by(&:basename) # sort by timestamp
|
||||
.map { |p| p.split.map(&:to_s) }
|
||||
end
|
||||
|
||||
@ -150,7 +165,7 @@ module Cask
|
||||
|
||||
version_os_hash
|
||||
ensure
|
||||
MacOS.full_version = actual_version
|
||||
MacOS.full_version = actual_version || MacOS.full_version.to_s
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cask/cache"
|
||||
@ -12,8 +12,18 @@ module Cask
|
||||
module CaskLoader
|
||||
extend Context
|
||||
|
||||
module ILoader
|
||||
extend T::Sig
|
||||
extend T::Helpers
|
||||
interface!
|
||||
|
||||
sig { abstract.params(config: Config).returns(Cask) }
|
||||
def load(config:); end
|
||||
end
|
||||
|
||||
# Loads a cask from a string.
|
||||
class FromContentLoader
|
||||
include ILoader
|
||||
attr_reader :content, :tap
|
||||
|
||||
def self.can_load?(ref)
|
||||
@ -112,7 +122,6 @@ module Cask
|
||||
return false unless ref.to_s.match?(@uri_regex)
|
||||
|
||||
uri = URI(ref)
|
||||
return false unless uri
|
||||
return false unless uri.path
|
||||
|
||||
true
|
||||
@ -123,7 +132,7 @@ module Cask
|
||||
sig { params(url: T.any(URI::Generic, String)).void }
|
||||
def initialize(url)
|
||||
@url = URI(url)
|
||||
super Cache.path/File.basename(@url.path)
|
||||
super Cache.path/File.basename(T.must(@url.path))
|
||||
end
|
||||
|
||||
def load(config:)
|
||||
@ -185,6 +194,7 @@ module Cask
|
||||
|
||||
# Loads a cask from an existing {Cask} instance.
|
||||
class FromInstanceLoader
|
||||
include ILoader
|
||||
def self.can_load?(ref)
|
||||
ref.is_a?(Cask)
|
||||
end
|
||||
@ -200,6 +210,7 @@ module Cask
|
||||
|
||||
# Loads a cask from the JSON API.
|
||||
class FromAPILoader
|
||||
include ILoader
|
||||
attr_reader :token, :path
|
||||
|
||||
def self.can_load?(ref)
|
||||
|
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "locale"
|
||||
@ -196,7 +196,7 @@ module Cask
|
||||
|
||||
# @api public
|
||||
def url(*args, **options, &block)
|
||||
caller_location = caller_locations[0]
|
||||
caller_location = T.must(caller_locations).fetch(0)
|
||||
|
||||
set_unique_stanza(:url, args.empty? && options.empty? && !block) do
|
||||
if block
|
||||
@ -237,14 +237,14 @@ module Cask
|
||||
set_unique_stanza(:sha256, should_return) do
|
||||
@on_system_blocks_exist = true if arm.present? || intel.present?
|
||||
|
||||
arg ||= on_arch_conditional(arm: arm, intel: intel)
|
||||
case arg
|
||||
val = arg || on_arch_conditional(arm: arm, intel: intel)
|
||||
case val
|
||||
when :no_check
|
||||
arg
|
||||
val
|
||||
when String
|
||||
Checksum.new(arg)
|
||||
Checksum.new(val)
|
||||
else
|
||||
raise CaskInvalidError.new(cask, "invalid 'sha256' value: #{arg.inspect}")
|
||||
raise CaskInvalidError.new(cask, "invalid 'sha256' value: #{val.inspect}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cask/utils"
|
||||
@ -26,7 +26,7 @@ module Cask
|
||||
# rubocop:disable Style/MissingRespondToMissing
|
||||
def method_missing(method, *)
|
||||
if method
|
||||
underscored_class = self.class.name.gsub(/([[:lower:]])([[:upper:]][[:lower:]])/, '\1_\2').downcase
|
||||
underscored_class = T.must(self.class.name).gsub(/([[:lower:]])([[:upper:]][[:lower:]])/, '\1_\2').downcase
|
||||
section = underscored_class.split("::").last
|
||||
Utils.method_missing_message(method, @cask.to_s, section)
|
||||
nil
|
||||
|
6
Library/Homebrew/extend/on_system.rbi
Normal file
6
Library/Homebrew/extend/on_system.rbi
Normal file
@ -0,0 +1,6 @@
|
||||
# typed: strict
|
||||
|
||||
module OnSystem::MacOSOnly
|
||||
sig { params(arm: T.nilable(String), intel: T.nilable(String)).returns(T.nilable(String)) }
|
||||
def on_arch_conditional(arm: nil, intel: nil); end
|
||||
end
|
@ -82,7 +82,7 @@ module OS
|
||||
nil
|
||||
end
|
||||
|
||||
def sdk_path
|
||||
def sdk_path(_version = nil)
|
||||
nil
|
||||
end
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "os/mac/version"
|
||||
@ -38,7 +38,7 @@ module OS
|
||||
end
|
||||
end
|
||||
|
||||
sig { params(version: Version).void }
|
||||
sig { params(version: String).void }
|
||||
def full_version=(version)
|
||||
@full_version = Version.new(version.chomp)
|
||||
@version = nil
|
||||
|
Loading…
x
Reference in New Issue
Block a user