Enable types in Library/Homebrew/cask
This commit is contained in:
parent
e89492fc38
commit
abfe29040b
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "delegate"
|
||||
@ -24,14 +24,14 @@ module Cask
|
||||
def initialize(**options)
|
||||
options.assert_valid_keys!(*VALID_KEYS)
|
||||
|
||||
conflicts = options.transform_values { |v| Set.new(Array(v)) }
|
||||
conflicts = options.transform_values { |v| Set.new(Kernel.Array(v)) }
|
||||
conflicts.default = Set.new
|
||||
|
||||
super(conflicts)
|
||||
end
|
||||
|
||||
def to_json(generator)
|
||||
transform_values(&:to_a).to_json(generator)
|
||||
__getobj__.transform_values(&:to_a).to_json(generator)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "delegate"
|
||||
@ -38,7 +38,7 @@ module Cask
|
||||
pairs.each do |key, value|
|
||||
raise "invalid depends_on key: '#{key.inspect}'" unless VALID_KEYS.include?(key)
|
||||
|
||||
self[key] = send(:"#{key}=", *value)
|
||||
__getobj__[key] = send(:"#{key}=", *value)
|
||||
end
|
||||
end
|
||||
|
||||
@ -54,15 +54,18 @@ module Cask
|
||||
def macos=(*args)
|
||||
raise "Only a single 'depends_on macos' is allowed." if defined?(@macos)
|
||||
|
||||
# workaround for https://github.com/sorbet/sorbet/issues/6860
|
||||
first_arg = args.first&.to_s
|
||||
|
||||
begin
|
||||
@macos = if args.count > 1
|
||||
MacOSRequirement.new([args], comparator: "==")
|
||||
elsif MacOSVersions::SYMBOLS.key?(args.first)
|
||||
MacOSRequirement.new([args.first], comparator: "==")
|
||||
elsif /^\s*(?<comparator><|>|[=<>]=)\s*:(?<version>\S+)\s*$/ =~ args.first
|
||||
MacOSRequirement.new([version.to_sym], comparator: comparator)
|
||||
elsif /^\s*(?<comparator><|>|[=<>]=)\s*(?<version>\S+)\s*$/ =~ args.first
|
||||
MacOSRequirement.new([version], comparator: comparator)
|
||||
elsif (md = /^\s*(?<comparator><|>|[=<>]=)\s*:(?<version>\S+)\s*$/.match(first_arg))
|
||||
MacOSRequirement.new([T.must(md[:version]).to_sym], comparator: md[:comparator])
|
||||
elsif (md = /^\s*(?<comparator><|>|[=<>]=)\s*(?<version>\S+)\s*$/.match(first_arg))
|
||||
MacOSRequirement.new([md[:version]], comparator: md[:comparator])
|
||||
else # rubocop:disable Lint/DuplicateBranch
|
||||
MacOSRequirement.new([args.first], comparator: "==")
|
||||
end
|
||||
|
5
Library/Homebrew/cask/dsl/depends_on.rbi
Normal file
5
Library/Homebrew/cask/dsl/depends_on.rbi
Normal file
@ -0,0 +1,5 @@
|
||||
# typed: strict
|
||||
|
||||
class Cask::DSL::DependsOn
|
||||
include Kernel
|
||||
end
|
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "formula_installer"
|
||||
@ -241,7 +241,7 @@ module Cask
|
||||
save_download_sha if @cask.version.latest?
|
||||
rescue => e
|
||||
begin
|
||||
already_installed_artifacts.each do |artifact|
|
||||
already_installed_artifacts&.each do |artifact|
|
||||
if artifact.respond_to?(:uninstall_phase)
|
||||
odebug "Reverting installation of artifact of class #{artifact.class}"
|
||||
artifact.uninstall_phase(command: @command, verbose: verbose?, force: force?)
|
||||
@ -296,7 +296,7 @@ module Cask
|
||||
|
||||
graph = ::Utils::TopologicalHash.graph_package_dependencies(@cask)
|
||||
|
||||
raise CaskSelfReferencingDependencyError, cask.token if graph[@cask].include?(@cask)
|
||||
raise CaskSelfReferencingDependencyError, @cask.token if graph[@cask].include?(@cask)
|
||||
|
||||
::Utils::TopologicalHash.graph_package_dependencies(primary_container.dependencies, graph)
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "development_tools"
|
||||
@ -11,29 +11,27 @@ module Cask
|
||||
module Quarantine
|
||||
extend T::Sig
|
||||
|
||||
module_function
|
||||
|
||||
QUARANTINE_ATTRIBUTE = "com.apple.quarantine"
|
||||
|
||||
QUARANTINE_SCRIPT = (HOMEBREW_LIBRARY_PATH/"cask/utils/quarantine.swift").freeze
|
||||
|
||||
def swift
|
||||
def self.swift
|
||||
@swift ||= DevelopmentTools.locate("swift")
|
||||
end
|
||||
private :swift
|
||||
private_class_method :swift
|
||||
|
||||
def xattr
|
||||
def self.xattr
|
||||
@xattr ||= DevelopmentTools.locate("xattr")
|
||||
end
|
||||
private :xattr
|
||||
private_class_method :xattr
|
||||
|
||||
def swift_target_args
|
||||
def self.swift_target_args
|
||||
["-target", "#{Hardware::CPU.arch}-apple-macosx#{MacOS.version}"]
|
||||
end
|
||||
private :swift_target_args
|
||||
private_class_method :swift_target_args
|
||||
|
||||
sig { returns(Symbol) }
|
||||
def check_quarantine_support
|
||||
def self.check_quarantine_support
|
||||
odebug "Checking quarantine support"
|
||||
|
||||
if !system_command(xattr, args: ["-h"], print_stderr: false).success?
|
||||
@ -58,13 +56,13 @@ module Cask
|
||||
end
|
||||
end
|
||||
|
||||
def available?
|
||||
def self.available?
|
||||
@status ||= check_quarantine_support
|
||||
|
||||
@status == :quarantine_available
|
||||
end
|
||||
|
||||
def detect(file)
|
||||
def self.detect(file)
|
||||
return if file.nil?
|
||||
|
||||
odebug "Verifying Gatekeeper status of #{file}"
|
||||
@ -76,13 +74,13 @@ module Cask
|
||||
quarantine_status
|
||||
end
|
||||
|
||||
def status(file)
|
||||
def self.status(file)
|
||||
system_command(xattr,
|
||||
args: ["-p", QUARANTINE_ATTRIBUTE, file],
|
||||
print_stderr: false).stdout.rstrip
|
||||
end
|
||||
|
||||
def toggle_no_translocation_bit(attribute)
|
||||
def self.toggle_no_translocation_bit(attribute)
|
||||
fields = attribute.split(";")
|
||||
|
||||
# Fields: status, epoch, download agent, event ID
|
||||
@ -94,7 +92,7 @@ module Cask
|
||||
fields.join(";")
|
||||
end
|
||||
|
||||
def release!(download_path: nil)
|
||||
def self.release!(download_path: nil)
|
||||
return unless detect(download_path)
|
||||
|
||||
odebug "Releasing #{download_path} from quarantine"
|
||||
@ -112,7 +110,7 @@ module Cask
|
||||
raise CaskQuarantineReleaseError.new(download_path, quarantiner.stderr)
|
||||
end
|
||||
|
||||
def cask!(cask: nil, download_path: nil, action: true)
|
||||
def self.cask!(cask: nil, download_path: nil, action: true)
|
||||
return if cask.nil? || download_path.nil?
|
||||
|
||||
return if detect(download_path)
|
||||
@ -139,7 +137,7 @@ module Cask
|
||||
end
|
||||
end
|
||||
|
||||
def propagate(from: nil, to: nil)
|
||||
def self.propagate(from: nil, to: nil)
|
||||
return if from.nil? || to.nil?
|
||||
|
||||
raise CaskError, "#{from} was not quarantined properly." unless detect(from)
|
||||
|
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "env_config"
|
||||
@ -124,7 +124,9 @@ module Cask
|
||||
|
||||
return true if caught_exceptions.empty?
|
||||
raise MultipleCaskErrors, caught_exceptions if caught_exceptions.count > 1
|
||||
raise caught_exceptions.first if caught_exceptions.count == 1
|
||||
raise caught_exceptions.fetch(0) if caught_exceptions.count == 1
|
||||
|
||||
false
|
||||
end
|
||||
|
||||
def self.upgrade_cask(
|
||||
|
Loading…
x
Reference in New Issue
Block a user