21
21
//! - libunwind may have platform-specific code.
22
22
//! - other crates in the std facade may not.
23
23
//! - std may have platform-specific code in the following places:
24
- //! - `sys/unix/`
25
- //! - `sys/windows/`
24
+ //! - `sys/`
26
25
//! - `os/`
27
26
//!
28
27
//! `std/sys_common` should _not_ contain platform-specific code.
@@ -36,34 +35,30 @@ use std::path::Path;
36
35
37
36
// Paths that may contain platform-specific code.
38
37
const EXCEPTION_PATHS : & [ & str ] = & [
39
- // std crates
40
38
"library/panic_abort" ,
41
39
"library/panic_unwind" ,
42
40
"library/unwind" ,
43
- "library/std/src/sys/" , // Platform-specific code for std lives here.
44
- // This has the trailing slash so that sys_common is not excepted.
45
- "library/std/src/os" , // Platform-specific public interfaces
46
- "library/rtstartup" , // Not sure what to do about this. magic stuff for mingw
47
- // Integration test for platform-specific run-time feature detection:
48
- "library/std/tests/run-time-detect.rs" ,
49
- "library/std/src/net/test.rs" ,
50
- "library/std/src/net/addr" ,
51
- "library/std/src/net/udp" ,
52
- "library/std/src/sys_common/remutex.rs" ,
53
- "library/std/src/sync/mutex.rs" ,
54
- "library/std/src/sync/rwlock.rs" ,
55
- "library/term" , // Not sure how to make this crate portable, but test crate needs it.
56
- "library/test" , // Probably should defer to unstable `std::sys` APIs.
57
- // std testing crates, okay for now at least
58
- "library/core/tests" ,
59
- "library/alloc/tests/lib.rs" ,
60
- "library/alloc/benches/lib.rs" ,
41
+ "library/rtstartup" , // Not sure what to do about this. magic stuff for mingw
42
+ "library/term" , // Not sure how to make this crate portable, but test crate needs it.
43
+ "library/test" , // Probably should defer to unstable `std::sys` APIs.
61
44
// The `VaList` implementation must have platform specific code.
62
45
// The Windows implementation of a `va_list` is always a character
63
46
// pointer regardless of the target architecture. As a result,
64
47
// we must use `#[cfg(windows)]` to conditionally compile the
65
48
// correct `VaList` structure for windows.
66
49
"library/core/src/ffi.rs" ,
50
+ "library/std/src/sys/" , // Platform-specific code for std lives here.
51
+ "library/std/src/os" , // Platform-specific public interfaces
52
+ // Temporary `std` exceptions
53
+ // FIXME: platform-specific code should be moved to `sys`
54
+ "library/std/src/io/copy.rs" ,
55
+ "library/std/src/io/stdio.rs" ,
56
+ "library/std/src/f32.rs" ,
57
+ "library/std/src/f64.rs" ,
58
+ "library/std/src/path.rs" ,
59
+ "library/std/src/thread/available_concurrency.rs" ,
60
+ "library/std/src/sys_common" , // Should only contain abstractions over platforms
61
+ "library/std/src/net/test.rs" , // Utility helpers for tests
67
62
] ;
68
63
69
64
pub fn check ( path : & Path , bad : & mut bool ) {
@@ -82,6 +77,11 @@ pub fn check(path: &Path, bad: &mut bool) {
82
77
return ;
83
78
}
84
79
80
+ // exclude tests and benchmarks as some platforms do not support all tests
81
+ if filestr. contains ( "tests" ) || filestr. contains ( "benches" ) {
82
+ return ;
83
+ }
84
+
85
85
check_cfgs ( contents, & file, bad, & mut saw_target_arch, & mut saw_cfg_bang) ;
86
86
} ) ;
87
87
@@ -96,9 +96,6 @@ fn check_cfgs(
96
96
saw_target_arch : & mut bool ,
97
97
saw_cfg_bang : & mut bool ,
98
98
) {
99
- // For now it's ok to have platform-specific code after 'mod tests'.
100
- let mod_tests_idx = find_test_mod ( contents) ;
101
- let contents = & contents[ ..mod_tests_idx] ;
102
99
// Pull out all `cfg(...)` and `cfg!(...)` strings.
103
100
let cfgs = parse_cfgs ( contents) ;
104
101
@@ -149,39 +146,22 @@ fn check_cfgs(
149
146
continue ;
150
147
}
151
148
152
- err ( idx, cfg) ;
153
- }
154
- }
155
-
156
- fn find_test_mod ( contents : & str ) -> usize {
157
- if let Some ( mod_tests_idx) = contents. find ( "mod tests" ) {
158
- // Also capture a previous line indicating that "mod tests" is cfg'd out.
159
- let prev_newline_idx = contents[ ..mod_tests_idx] . rfind ( '\n' ) . unwrap_or ( mod_tests_idx) ;
160
- let prev_newline_idx = contents[ ..prev_newline_idx] . rfind ( '\n' ) ;
161
- if let Some ( nl) = prev_newline_idx {
162
- let prev_line = & contents[ nl + 1 ..mod_tests_idx] ;
163
- if prev_line. contains ( "cfg(all(test, not(target_os" )
164
- || prev_line. contains ( "cfg(all(test, not(any(target_os" )
165
- {
166
- nl
167
- } else {
168
- mod_tests_idx
169
- }
170
- } else {
171
- mod_tests_idx
149
+ // exclude tests as some platforms do not support all tests
150
+ if cfg. contains ( "test" ) {
151
+ continue ;
172
152
}
173
- } else {
174
- contents . len ( )
153
+
154
+ err ( idx , cfg ) ;
175
155
}
176
156
}
177
157
178
- fn parse_cfgs < ' a > ( contents : & ' a str ) -> Vec < ( usize , & ' a str ) > {
158
+ fn parse_cfgs ( contents : & str ) -> Vec < ( usize , & str ) > {
179
159
let candidate_cfgs = contents. match_indices ( "cfg" ) ;
180
160
let candidate_cfg_idxs = candidate_cfgs. map ( |( i, _) | i) ;
181
161
// This is puling out the indexes of all "cfg" strings
182
162
// that appear to be tokens followed by a parenthesis.
183
163
let cfgs = candidate_cfg_idxs. filter ( |i| {
184
- let pre_idx = i. saturating_sub ( * i ) ;
164
+ let pre_idx = i. saturating_sub ( 1 ) ;
185
165
let succeeds_non_ident = !contents
186
166
. as_bytes ( )
187
167
. get ( pre_idx)
0 commit comments