1
- # typed: true # rubocop:todo Sorbet/StrictSigil
1
+ # typed: strict
2
2
# frozen_string_literal: true
3
3
4
4
require "simulate_system"
5
5
6
6
module OnSystem
7
- ARCH_OPTIONS = [ :intel , :arm ] . freeze
8
- 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
11
-
12
- VALID_OS_ARCH_TAGS = ALL_OS_ARCH_COMBINATIONS . filter_map do |os , arch |
13
- tag = Utils ::Bottles ::Tag . new ( system : os , arch :)
14
- next unless tag . valid_combination?
15
-
16
- tag
17
- end . freeze
7
+ ARCH_OPTIONS = T . let ( [ :intel , :arm ] . freeze , T ::Array [ Symbol ] )
8
+ BASE_OS_OPTIONS = T . let ( [ :macos , :linux ] . freeze , T ::Array [ Symbol ] )
9
+ ALL_OS_OPTIONS = T . let ( [ *MacOSVersion ::SYMBOLS . keys , :linux ] . freeze , T ::Array [ Symbol ] )
10
+ ALL_OS_ARCH_COMBINATIONS = T . let (
11
+ ALL_OS_OPTIONS . product ( ARCH_OPTIONS ) . freeze ,
12
+ T ::Array [ [ Symbol , Symbol ] ] ,
13
+ )
14
+
15
+ VALID_OS_ARCH_TAGS = T . let (
16
+ ALL_OS_ARCH_COMBINATIONS . filter_map do |os , arch |
17
+ tag = Utils ::Bottles ::Tag . new ( system : os , arch :)
18
+ next unless tag . valid_combination?
19
+
20
+ tag
21
+ end . freeze ,
22
+ T ::Array [ Utils ::Bottles ::Tag ] ,
23
+ )
18
24
19
25
sig { params ( arch : Symbol ) . returns ( T ::Boolean ) }
20
26
def self . arch_condition_met? ( arch )
@@ -55,15 +61,15 @@ def self.condition_from_method_name(method_name)
55
61
method_name . to_s . sub ( /^on_/ , "" ) . to_sym
56
62
end
57
63
58
- sig { params ( base : Class ) . void }
64
+ sig { params ( base : T :: Class [ T . anything ] ) . void }
59
65
def self . setup_arch_methods ( base )
60
66
ARCH_OPTIONS . each do |arch |
61
67
base . define_method ( :"on_#{ arch } " ) do |&block |
62
- @on_system_blocks_exist = true
68
+ @on_system_blocks_exist = T . let ( true , T . nilable ( T :: Boolean ) )
63
69
64
70
return unless OnSystem . arch_condition_met? OnSystem . condition_from_method_name ( T . must ( __method__ ) )
65
71
66
- @called_in_on_system_block = true
72
+ @called_in_on_system_block = T . let ( true , T . nilable ( T :: Boolean ) )
67
73
result = block . call
68
74
@called_in_on_system_block = false
69
75
@@ -82,7 +88,7 @@ def self.setup_arch_methods(base)
82
88
end
83
89
end
84
90
85
- sig { params ( base : Class ) . void }
91
+ sig { params ( base : T :: Class [ T . anything ] ) . void }
86
92
def self . setup_base_os_methods ( base )
87
93
BASE_OS_OPTIONS . each do |base_os |
88
94
base . define_method ( :"on_#{ base_os } " ) do |&block |
@@ -128,7 +134,7 @@ def self.setup_base_os_methods(base)
128
134
end
129
135
end
130
136
131
- sig { params ( base : Class ) . void }
137
+ sig { params ( base : T :: Class [ T . anything ] ) . void }
132
138
def self . setup_macos_methods ( base )
133
139
MacOSVersion ::SYMBOLS . each_key do |os_name |
134
140
base . define_method ( :"on_#{ os_name } " ) do |or_condition = nil , &block |
@@ -137,11 +143,14 @@ def self.setup_macos_methods(base)
137
143
os_condition = OnSystem . condition_from_method_name T . must ( __method__ )
138
144
return unless OnSystem . os_condition_met? os_condition , or_condition
139
145
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
146
+ @on_system_block_min_os = T . let (
147
+ if or_condition == :or_older
148
+ @called_in_on_system_block ? @on_system_block_min_os : MacOSVersion . new ( HOMEBREW_MACOS_OLDEST_ALLOWED )
149
+ else
150
+ MacOSVersion . from_symbol ( os_condition )
151
+ end ,
152
+ T . nilable ( MacOSVersion ) ,
153
+ )
145
154
@called_in_on_system_block = true
146
155
result = block . call
147
156
@called_in_on_system_block = false
@@ -151,13 +160,13 @@ def self.setup_macos_methods(base)
151
160
end
152
161
end
153
162
154
- sig { params ( _base : Class ) . void }
163
+ sig { params ( _base : T :: Class [ T . anything ] ) . void }
155
164
def self . included ( _base )
156
165
raise "Do not include `OnSystem` directly. Instead, include `OnSystem::MacOSAndLinux` or `OnSystem::MacOSOnly`"
157
166
end
158
167
159
168
module MacOSAndLinux
160
- sig { params ( base : Class ) . void }
169
+ sig { params ( base : T :: Class [ T . anything ] ) . void }
161
170
def self . included ( base )
162
171
OnSystem . setup_arch_methods ( base )
163
172
OnSystem . setup_base_os_methods ( base )
@@ -166,7 +175,7 @@ def self.included(base)
166
175
end
167
176
168
177
module MacOSOnly
169
- sig { params ( base : Class ) . void }
178
+ sig { params ( base : T :: Class [ T . anything ] ) . void }
170
179
def self . included ( base )
171
180
OnSystem . setup_arch_methods ( base )
172
181
OnSystem . setup_macos_methods ( base )
0 commit comments