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
7
ARCH_OPTIONS = [ :intel , :arm ] . freeze
8
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
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 ] ] )
11
11
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 |
13
13
tag = Utils ::Bottles ::Tag . new ( system : os , arch :)
14
14
next unless tag . valid_combination?
15
15
16
16
tag
17
- end . freeze
17
+ end . freeze , T :: Array [ Utils :: Bottles :: Tag ] )
18
18
19
19
sig { params ( arch : Symbol ) . returns ( T ::Boolean ) }
20
20
def self . arch_condition_met? ( arch )
@@ -55,11 +55,11 @@ def self.condition_from_method_name(method_name)
55
55
method_name . to_s . sub ( /^on_/ , "" ) . to_sym
56
56
end
57
57
58
- sig { params ( base : Class ) . void }
58
+ sig { params ( base : T :: Class [ T . anything ] ) . void }
59
59
def self . setup_arch_methods ( base )
60
60
ARCH_OPTIONS . each do |arch |
61
61
base . define_method ( :"on_#{ arch } " ) do |&block |
62
- @on_system_blocks_exist = true
62
+ @on_system_blocks_exist = T . let ( true , T . nilable ( TrueClass ) )
63
63
64
64
return unless OnSystem . arch_condition_met? OnSystem . condition_from_method_name ( T . must ( __method__ ) )
65
65
@@ -72,7 +72,7 @@ def self.setup_arch_methods(base)
72
72
end
73
73
74
74
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 ) )
76
76
77
77
if OnSystem . arch_condition_met? :arm
78
78
arm
@@ -82,11 +82,11 @@ def self.setup_arch_methods(base)
82
82
end
83
83
end
84
84
85
- sig { params ( base : Class ) . void }
85
+ sig { params ( base : T :: Class [ T . anything ] ) . void }
86
86
def self . setup_base_os_methods ( base )
87
87
BASE_OS_OPTIONS . each do |base_os |
88
88
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 ) )
90
90
91
91
return unless OnSystem . os_condition_met? OnSystem . condition_from_method_name ( T . must ( __method__ ) )
92
92
@@ -99,7 +99,7 @@ def self.setup_base_os_methods(base)
99
99
end
100
100
101
101
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 ) )
103
103
104
104
raise ArgumentError , "The first argument to `on_system` must be `:linux`" if linux != :linux
105
105
@@ -118,7 +118,7 @@ def self.setup_base_os_methods(base)
118
118
end
119
119
120
120
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 ) )
122
122
123
123
if OnSystem . os_condition_met? ( :macos ) && macos . present?
124
124
macos
@@ -128,21 +128,24 @@ def self.setup_base_os_methods(base)
128
128
end
129
129
end
130
130
131
- sig { params ( base : Class ) . void }
131
+ sig { params ( base : T :: Class [ T . anything ] ) . void }
132
132
def self . setup_macos_methods ( base )
133
133
MacOSVersion ::SYMBOLS . each_key do |os_name |
134
134
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 ) )
136
136
137
137
os_condition = OnSystem . condition_from_method_name T . must ( __method__ )
138
138
return unless OnSystem . os_condition_met? os_condition , or_condition
139
139
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 ) )
146
149
result = block . call
147
150
@called_in_on_system_block = false
148
151
@@ -151,13 +154,13 @@ def self.setup_macos_methods(base)
151
154
end
152
155
end
153
156
154
- sig { params ( _base : Class ) . void }
157
+ sig { params ( _base : T :: Class [ T . anything ] ) . void }
155
158
def self . included ( _base )
156
159
raise "Do not include `OnSystem` directly. Instead, include `OnSystem::MacOSAndLinux` or `OnSystem::MacOSOnly`"
157
160
end
158
161
159
162
module MacOSAndLinux
160
- sig { params ( base : Class ) . void }
163
+ sig { params ( base : T :: Class [ T . anything ] ) . void }
161
164
def self . included ( base )
162
165
OnSystem . setup_arch_methods ( base )
163
166
OnSystem . setup_base_os_methods ( base )
@@ -166,7 +169,7 @@ def self.included(base)
166
169
end
167
170
168
171
module MacOSOnly
169
- sig { params ( base : Class ) . void }
172
+ sig { params ( base : T :: Class [ T . anything ] ) . void }
170
173
def self . included ( base )
171
174
OnSystem . setup_arch_methods ( base )
172
175
OnSystem . setup_macos_methods ( base )
0 commit comments