@@ -16,6 +16,76 @@ fn error_from_signal(recipe: &str, line_number: Option<usize>, exit_status: Exit
16
16
}
17
17
}
18
18
19
+ #[ derive( Debug ) ]
20
+ struct SystemMap {
21
+ windows : bool ,
22
+ macos : bool ,
23
+ linux : bool ,
24
+ openbsd : bool ,
25
+ unix : bool ,
26
+ }
27
+
28
+ #[ derive( Debug , Clone , Copy ) ]
29
+ enum System {
30
+ Windows ,
31
+ MacOS ,
32
+ Linux ,
33
+ OpenBSD ,
34
+ Unix ,
35
+ }
36
+
37
+ impl System {
38
+ fn current ( ) -> System {
39
+ use System :: * ;
40
+ if cfg ! ( target_os = "linux" ) {
41
+ return Linux ;
42
+ }
43
+ if cfg ! ( target_os = "openbsd" ) {
44
+ return OpenBSD ;
45
+ }
46
+ if cfg ! ( target_os = "macos" ) {
47
+ return MacOS ;
48
+ }
49
+ if cfg ! ( target_os = "windows" ) || cfg ! ( windows) {
50
+ return Windows ;
51
+ }
52
+ if cfg ! ( unix) {
53
+ return Unix ;
54
+ }
55
+ panic ! ( "No recognized system" ) ;
56
+ }
57
+
58
+ fn enabled ( self , enabled : SystemMap , disabled : SystemMap ) -> bool {
59
+ match self {
60
+ System :: Windows => {
61
+ !disabled. windows
62
+ && ( enabled. windows
63
+ || !( enabled. macos || enabled. linux || enabled. openbsd || enabled. unix ) )
64
+ }
65
+ System :: MacOS => {
66
+ !disabled. macos
67
+ && ( ( enabled. macos || enabled. unix )
68
+ || !( enabled. windows || enabled. linux || enabled. openbsd ) )
69
+ }
70
+ System :: Linux => {
71
+ !disabled. linux
72
+ && ( ( enabled. linux || enabled. unix )
73
+ || !( enabled. windows || enabled. macos || enabled. openbsd ) )
74
+ }
75
+ System :: OpenBSD => {
76
+ !disabled. openbsd
77
+ && ( ( enabled. openbsd || enabled. unix )
78
+ || !( enabled. windows || enabled. macos || enabled. linux ) )
79
+ }
80
+ System :: Unix => {
81
+ !disabled. unix
82
+ && ( enabled. unix
83
+ || !( enabled. windows || enabled. macos || enabled. linux || enabled. openbsd ) )
84
+ }
85
+ }
86
+ }
87
+ }
88
+
19
89
/// A recipe, e.g. `foo: bar baz`
20
90
#[ derive( PartialEq , Debug , Clone , Serialize ) ]
21
91
pub ( crate ) struct Recipe < ' src , D = Dependency < ' src > > {
@@ -116,15 +186,7 @@ impl<'src, D> Recipe<'src, D> {
116
186
}
117
187
118
188
pub ( crate ) fn enabled ( & self ) -> bool {
119
- use attribute_set:: InvertedStatus ;
120
-
121
- struct Systems {
122
- linux : bool ,
123
- macos : bool ,
124
- openbsd : bool ,
125
- unix : bool ,
126
- windows : bool ,
127
- }
189
+ use std:: ops:: Not ;
128
190
129
191
let linux = self
130
192
. attributes
@@ -149,48 +211,23 @@ impl<'src, D> Recipe<'src, D> {
149
211
return true ;
150
212
}
151
213
152
- let systems = Systems {
153
- linux : matches ! ( linux , Some ( InvertedStatus :: Normal ) ) ,
154
- macos : matches ! ( macos, Some ( InvertedStatus :: Normal ) ) ,
155
- openbsd : matches ! ( openbsd , Some ( InvertedStatus :: Normal ) ) ,
156
- unix : matches ! ( unix , Some ( InvertedStatus :: Normal ) ) ,
157
- windows : matches ! ( windows , Some ( InvertedStatus :: Normal ) ) ,
214
+ let enabled = SystemMap {
215
+ windows : windows . unwrap_or ( false ) ,
216
+ macos : macos. unwrap_or ( false ) ,
217
+ linux : linux . unwrap_or ( false ) ,
218
+ openbsd : openbsd . unwrap_or ( false ) ,
219
+ unix : unix . unwrap_or ( false ) ,
158
220
} ;
159
221
160
- let disabled = Systems {
161
- linux : matches ! ( linux, Some ( InvertedStatus :: Inverted ) ) ,
162
- macos : matches ! ( macos, Some ( InvertedStatus :: Inverted ) ) ,
163
- openbsd : matches ! ( openbsd, Some ( InvertedStatus :: Inverted ) ) ,
164
- unix : matches ! ( unix, Some ( InvertedStatus :: Inverted ) ) ,
165
- windows : matches ! ( windows, Some ( InvertedStatus :: Inverted ) ) ,
222
+ let disabled = SystemMap {
223
+ linux : linux. is_some_and ( bool :: not ) ,
224
+ macos : macos. is_some_and ( bool :: not ) ,
225
+ openbsd : openbsd. is_some_and ( bool :: not ) ,
226
+ unix : unix. is_some_and ( bool :: not ) ,
227
+ windows : windows. is_some_and ( bool :: not ) ,
166
228
} ;
167
229
168
- if cfg ! ( target_os = "linux" ) {
169
- return !( disabled. linux || disabled. unix )
170
- && ( ( systems. linux || systems. unix )
171
- || ( !systems. openbsd && !systems. windows && !systems. macos ) ) ;
172
- }
173
-
174
- if cfg ! ( target_os = "openbsd" ) {
175
- return !disabled. openbsd
176
- && ( systems. openbsd || ( !systems. windows && !systems. macos && !systems. linux ) ) ;
177
- }
178
-
179
- if cfg ! ( target_os = "windows" ) || cfg ! ( windows) {
180
- return !disabled. windows
181
- && ( systems. windows
182
- || ( !systems. openbsd && !systems. unix && !systems. macos && !systems. linux ) ) ;
183
- }
184
-
185
- if cfg ! ( target_os = "macos" ) {
186
- return !disabled. macos
187
- && ( systems. macos || ( !systems. openbsd && !systems. windows && !systems. linux ) ) ;
188
- }
189
-
190
- if cfg ! ( unix) {
191
- return !( disabled. unix ) && ( systems. unix || !systems. windows ) ;
192
- }
193
- false
230
+ System :: current ( ) . enabled ( enabled, disabled)
194
231
}
195
232
196
233
fn print_exit_message ( & self ) -> bool {
0 commit comments