1- # typed: true # rubocop:todo Sorbet/StrictSigil
1+ # typed: strict
22# frozen_string_literal: true
33
44require "simulate_system"
55
66module OnSystem
77 ARCH_OPTIONS = [ :intel , :arm ] . freeze
88 BASE_OS_OPTIONS = [ :macos , :linux ] . freeze
9- ALL_OS_OPTIONS = [ *MacOSVersion ::SYMBOLS . keys , :linux ] . freeze
10- ALL_OS_ARCH_COMBINATIONS = ALL_OS_OPTIONS . product ( ARCH_OPTIONS ) . freeze
9+ ALL_OS_OPTIONS = T . let ( [ *MacOSVersion ::SYMBOLS . keys , :linux ] . freeze , T :: Array [ Symbol ] )
10+ ALL_OS_ARCH_COMBINATIONS = T . let ( ALL_OS_OPTIONS . product ( ARCH_OPTIONS ) . freeze , T :: Array [ [ Symbol , Symbol ] ] )
1111
12- VALID_OS_ARCH_TAGS = ALL_OS_ARCH_COMBINATIONS . filter_map do |os , arch |
12+ VALID_OS_ARCH_TAGS = T . let ( ALL_OS_ARCH_COMBINATIONS . filter_map do |os , arch |
1313 tag = Utils ::Bottles ::Tag . new ( system : os , arch :)
1414 next unless tag . valid_combination?
1515
1616 tag
17- end . freeze
17+ end . freeze , T :: Array [ Utils :: Bottles :: Tag ] )
1818
1919 sig { params ( arch : Symbol ) . returns ( T ::Boolean ) }
2020 def self . arch_condition_met? ( arch )
@@ -55,11 +55,11 @@ def self.condition_from_method_name(method_name)
5555 method_name . to_s . sub ( /^on_/ , "" ) . to_sym
5656 end
5757
58- sig { params ( base : Class ) . void }
58+ sig { params ( base : T :: Class [ T . anything ] ) . void }
5959 def self . setup_arch_methods ( base )
6060 ARCH_OPTIONS . each do |arch |
6161 base . define_method ( :"on_#{ arch } " ) do |&block |
62- @on_system_blocks_exist = true
62+ @on_system_blocks_exist = T . let ( true , T . nilable ( TrueClass ) )
6363
6464 return unless OnSystem . arch_condition_met? OnSystem . condition_from_method_name ( T . must ( __method__ ) )
6565
@@ -72,7 +72,7 @@ def self.setup_arch_methods(base)
7272 end
7373
7474 base . define_method ( :on_arch_conditional ) do |arm : nil , intel : nil |
75- @on_system_blocks_exist = true
75+ @on_system_blocks_exist = T . let ( true , T . nilable ( TrueClass ) )
7676
7777 if OnSystem . arch_condition_met? :arm
7878 arm
@@ -82,11 +82,11 @@ def self.setup_arch_methods(base)
8282 end
8383 end
8484
85- sig { params ( base : Class ) . void }
85+ sig { params ( base : T :: Class [ T . anything ] ) . void }
8686 def self . setup_base_os_methods ( base )
8787 BASE_OS_OPTIONS . each do |base_os |
8888 base . define_method ( :"on_#{ base_os } " ) do |&block |
89- @on_system_blocks_exist = true
89+ @on_system_blocks_exist = T . let ( true , T . nilable ( TrueClass ) )
9090
9191 return unless OnSystem . os_condition_met? OnSystem . condition_from_method_name ( T . must ( __method__ ) )
9292
@@ -99,7 +99,7 @@ def self.setup_base_os_methods(base)
9999 end
100100
101101 base . define_method ( :on_system ) do |linux , macos :, &block |
102- @on_system_blocks_exist = true
102+ @on_system_blocks_exist = T . let ( true , T . nilable ( TrueClass ) )
103103
104104 raise ArgumentError , "The first argument to `on_system` must be `:linux`" if linux != :linux
105105
@@ -118,7 +118,7 @@ def self.setup_base_os_methods(base)
118118 end
119119
120120 base . define_method ( :on_system_conditional ) do |macos : nil , linux : nil |
121- @on_system_blocks_exist = true
121+ @on_system_blocks_exist = T . let ( true , T . nilable ( TrueClass ) )
122122
123123 if OnSystem . os_condition_met? ( :macos ) && macos . present?
124124 macos
@@ -128,21 +128,24 @@ def self.setup_base_os_methods(base)
128128 end
129129 end
130130
131- sig { params ( base : Class ) . void }
131+ sig { params ( base : T :: Class [ T . anything ] ) . void }
132132 def self . setup_macos_methods ( base )
133133 MacOSVersion ::SYMBOLS . each_key do |os_name |
134134 base . define_method ( :"on_#{ os_name } " ) do |or_condition = nil , &block |
135- @on_system_blocks_exist = true
135+ @on_system_blocks_exist = T . let ( true , T . nilable ( TrueClass ) )
136136
137137 os_condition = OnSystem . condition_from_method_name T . must ( __method__ )
138138 return unless OnSystem . os_condition_met? os_condition , or_condition
139139
140- @on_system_block_min_os = if or_condition == :or_older
141- @called_in_on_system_block ? @on_system_block_min_os : MacOSVersion . new ( HOMEBREW_MACOS_OLDEST_ALLOWED )
142- else
143- MacOSVersion . from_symbol ( os_condition )
144- end
145- @called_in_on_system_block = true
140+ @on_system_block_min_os = T . let (
141+ if or_condition == :or_older
142+ @called_in_on_system_block ? @on_system_block_min_os : MacOSVersion . new ( HOMEBREW_MACOS_OLDEST_ALLOWED )
143+ else
144+ MacOSVersion . from_symbol ( os_condition )
145+ end ,
146+ T . nilable ( MacOSVersion ) ,
147+ )
148+ @called_in_on_system_block = T . let ( true , T . nilable ( T ::Boolean ) )
146149 result = block . call
147150 @called_in_on_system_block = false
148151
@@ -151,13 +154,13 @@ def self.setup_macos_methods(base)
151154 end
152155 end
153156
154- sig { params ( _base : Class ) . void }
157+ sig { params ( _base : T :: Class [ T . anything ] ) . void }
155158 def self . included ( _base )
156159 raise "Do not include `OnSystem` directly. Instead, include `OnSystem::MacOSAndLinux` or `OnSystem::MacOSOnly`"
157160 end
158161
159162 module MacOSAndLinux
160- sig { params ( base : Class ) . void }
163+ sig { params ( base : T :: Class [ T . anything ] ) . void }
161164 def self . included ( base )
162165 OnSystem . setup_arch_methods ( base )
163166 OnSystem . setup_base_os_methods ( base )
@@ -166,7 +169,7 @@ def self.included(base)
166169 end
167170
168171 module MacOSOnly
169- sig { params ( base : Class ) . void }
172+ sig { params ( base : T :: Class [ T . anything ] ) . void }
170173 def self . included ( base )
171174 OnSystem . setup_arch_methods ( base )
172175 OnSystem . setup_macos_methods ( base )
0 commit comments