Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove misleading upstream.rbi, enable types in on_system #15019

Merged
merged 1 commit into from Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Library/Homebrew/cask/config.rb
Expand Up @@ -169,10 +169,12 @@ def languages=(languages)

DEFAULT_DIRS.each_key do |dir|
define_method(dir) do
T.bind(self, Config)
explicit.fetch(dir, env.fetch(dir, default.fetch(dir)))
end

define_method(:"#{dir}=") do |path|
T.bind(self, Config)
explicit[dir] = Pathname(path).expand_path
end
end
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/cask/dsl.rb
Expand Up @@ -339,6 +339,7 @@ def livecheckable?

ORDINARY_ARTIFACT_CLASSES.each do |klass|
define_method(klass.dsl_key) do |*args, **kwargs|
T.bind(self, DSL)
if [*artifacts.map(&:class), klass].include?(Artifact::StageOnly) &&
(artifacts.map(&:class) & ACTIVATABLE_ARTIFACT_CLASSES).any?
raise CaskInvalidError.new(cask, "'stage_only' must be the only activatable artifact.")
Expand All @@ -355,6 +356,7 @@ def livecheckable?
ARTIFACT_BLOCK_CLASSES.each do |klass|
[klass.dsl_key, klass.uninstall_dsl_key].each do |dsl_key|
define_method(dsl_key) do |&block|
T.bind(self, DSL)
artifacts.add(klass.new(cask, dsl_key => block))
end
end
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/cask/dsl/version.rb
Expand Up @@ -32,6 +32,7 @@ def define_divider_methods(divider)
def define_divider_deletion_method(divider)
method_name = deletion_method_name(divider)
define_method(method_name) do
T.bind(self, Version)
version { delete(divider) }
end
end
Expand All @@ -49,6 +50,7 @@ def define_divider_conversion_methods(left_divider)
def define_divider_conversion_method(left_divider, right_divider)
method_name = conversion_method_name(left_divider, right_divider)
define_method(method_name) do
T.bind(self, Version)
version { gsub(left_divider, right_divider) }
end
end
Expand Down
22 changes: 10 additions & 12 deletions Library/Homebrew/extend/on_system.rb
@@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true

require "simulate_system"
Expand All @@ -9,17 +9,15 @@ module OnSystem
ARCH_OPTIONS = [:intel, :arm].freeze
BASE_OS_OPTIONS = [:macos, :linux].freeze

module_function

sig { params(arch: Symbol).returns(T::Boolean) }
def arch_condition_met?(arch)
def self.arch_condition_met?(arch)
raise ArgumentError, "Invalid arch condition: #{arch.inspect}" if ARCH_OPTIONS.exclude?(arch)

arch == Homebrew::SimulateSystem.current_arch
end

sig { params(os_name: Symbol, or_condition: T.nilable(Symbol)).returns(T::Boolean) }
def os_condition_met?(os_name, or_condition = nil)
def self.os_condition_met?(os_name, or_condition = nil)
return Homebrew::SimulateSystem.send("simulating_or_running_on_#{os_name}?") if BASE_OS_OPTIONS.include?(os_name)

raise ArgumentError, "Invalid OS condition: #{os_name.inspect}" unless MacOSVersions::SYMBOLS.key?(os_name)
Expand All @@ -46,17 +44,17 @@ def os_condition_met?(os_name, or_condition = nil)
end

sig { params(method_name: Symbol).returns(Symbol) }
def condition_from_method_name(method_name)
def self.condition_from_method_name(method_name)
method_name.to_s.sub(/^on_/, "").to_sym
end

sig { params(base: Class).void }
def setup_arch_methods(base)
def self.setup_arch_methods(base)
ARCH_OPTIONS.each do |arch|
base.define_method("on_#{arch}") do |&block|
@on_system_blocks_exist = true

return unless OnSystem.arch_condition_met? OnSystem.condition_from_method_name(__method__)
return unless OnSystem.arch_condition_met? OnSystem.condition_from_method_name(T.must(__method__))

@called_in_on_system_block = true
result = block.call
Expand All @@ -75,12 +73,12 @@ def setup_arch_methods(base)
end

sig { params(base: Class).void }
def setup_base_os_methods(base)
def self.setup_base_os_methods(base)
BASE_OS_OPTIONS.each do |base_os|
base.define_method("on_#{base_os}") do |&block|
@on_system_blocks_exist = true

return unless OnSystem.os_condition_met? OnSystem.condition_from_method_name(__method__)
return unless OnSystem.os_condition_met? OnSystem.condition_from_method_name(T.must(__method__))

@called_in_on_system_block = true
result = block.call
Expand Down Expand Up @@ -118,12 +116,12 @@ def setup_base_os_methods(base)
end

sig { params(base: Class).void }
def setup_macos_methods(base)
def self.setup_macos_methods(base)
MacOSVersions::SYMBOLS.each_key do |os_name|
base.define_method("on_#{os_name}") do |or_condition = nil, &block|
@on_system_blocks_exist = true

os_condition = OnSystem.condition_from_method_name __method__
os_condition = OnSystem.condition_from_method_name T.must(__method__)
return unless OnSystem.os_condition_met? os_condition, or_condition

@called_in_on_system_block = true
Expand Down
23 changes: 0 additions & 23 deletions Library/Homebrew/sorbet/rbi/upstream.rbi

This file was deleted.