@@ -49,68 +49,70 @@ static EXCEPTIONS: &'static [&'static str] = &[
49
49
] ;
50
50
51
51
/// Which crates to check against the whitelist?
52
- static WHITELIST_CRATES : & ' static [ Crate ] = & [ Crate ( "rustc" ) , Crate ( "rustc_trans" ) ] ;
52
+ static WHITELIST_CRATES : & ' static [ CrateVersion ] = & [
53
+ CrateVersion ( "rustc" , "0.0.0" ) ,
54
+ CrateVersion ( "rustc_trans" , "0.0.0" ) ,
55
+ ] ;
53
56
54
57
/// Whitelist of crates rustc is allowed to depend on. Avoid adding to the list if possible.
55
58
static WHITELIST : & ' static [ Crate ] = & [
56
- Crate ( "ar" ) ,
57
- Crate ( "arena" ) ,
58
- Crate ( "backtrace" ) ,
59
- Crate ( "backtrace-sys" ) ,
60
- Crate ( "bitflags" ) ,
61
- Crate ( "build_helper" ) ,
62
- Crate ( "byteorder" ) ,
63
- Crate ( "cc" ) ,
64
- Crate ( "cfg-if" ) ,
65
- Crate ( "cmake" ) ,
66
- Crate ( "filetime" ) ,
67
- Crate ( "flate2" ) ,
68
- Crate ( "fmt_macros" ) ,
69
- Crate ( "fuchsia-zircon" ) ,
70
- Crate ( "fuchsia-zircon-sys" ) ,
71
- Crate ( "graphviz" ) ,
72
- Crate ( "jobserver" ) ,
73
- Crate ( "kernel32-sys" ) ,
74
- Crate ( "lazy_static" ) ,
75
- Crate ( "libc" ) ,
76
- Crate ( "log" ) ,
77
- Crate ( "log_settings" ) ,
78
- Crate ( "miniz-sys" ) ,
79
- Crate ( "num_cpus" ) ,
80
- Crate ( "owning_ref" ) ,
81
- Crate ( "parking_lot" ) ,
82
- Crate ( "parking_lot_core" ) ,
83
- Crate ( "rand" ) ,
84
- Crate ( "redox_syscall" ) ,
85
- Crate ( "rustc" ) ,
86
- Crate ( "rustc-demangle" ) ,
87
- Crate ( "rustc_allocator" ) ,
88
- Crate ( "rustc_apfloat" ) ,
89
- Crate ( "rustc_back" ) ,
90
- Crate ( "rustc_binaryen" ) ,
91
- Crate ( "rustc_const_eval" ) ,
92
- Crate ( "rustc_const_math" ) ,
93
- Crate ( "rustc_cratesio_shim" ) ,
94
- Crate ( "rustc_data_structures" ) ,
95
- Crate ( "rustc_errors" ) ,
96
- Crate ( "rustc_incremental" ) ,
97
- Crate ( "rustc_llvm" ) ,
98
- Crate ( "rustc_mir" ) ,
99
- Crate ( "rustc_platform_intrinsics" ) ,
100
- Crate ( "rustc_trans" ) ,
101
- Crate ( "rustc_trans_utils" ) ,
102
- Crate ( "serialize" ) ,
103
- Crate ( "smallvec" ) ,
104
- Crate ( "stable_deref_trait" ) ,
105
- Crate ( "syntax" ) ,
106
- Crate ( "syntax_pos" ) ,
107
- Crate ( "tempdir" ) ,
108
- Crate ( "unicode-width" ) ,
109
- Crate ( "winapi" ) ,
110
- Crate ( "winapi-build" ) ,
111
- Crate ( "proc_macro" ) ,
112
- Crate ( "winapi-i686-pc-windows-gnu" ) ,
113
- Crate ( "winapi-x86_64-pc-windows-gnu" ) ,
59
+ // Crate("ar"),
60
+ // Crate("arena"),
61
+ // Crate("backtrace"),
62
+ // Crate("backtrace-sys"),
63
+ // Crate("bitflags"),
64
+ // Crate("build_helper"),
65
+ // Crate("byteorder"),
66
+ // Crate("cc"),
67
+ // Crate("cfg-if"),
68
+ // Crate("cmake"),
69
+ // Crate("filetime"),
70
+ // Crate("flate2"),
71
+ // Crate("fmt_macros"),
72
+ // Crate("fuchsia-zircon"),
73
+ // Crate("fuchsia-zircon-sys"),
74
+ // Crate("graphviz"),
75
+ // Crate("jobserver"),
76
+ // Crate("kernel32-sys"),
77
+ // Crate("lazy_static"),
78
+ // Crate("libc"),
79
+ // Crate("log"),
80
+ // Crate("log_settings"),
81
+ // Crate("miniz-sys"),
82
+ // Crate("num_cpus"),
83
+ // Crate("owning_ref"),
84
+ // Crate("parking_lot"),
85
+ // Crate("parking_lot_core"),
86
+ // Crate("rand"),
87
+ // Crate("redox_syscall"),
88
+ // Crate("rustc"),
89
+ // Crate("rustc-demangle"),
90
+ // Crate("rustc_allocator"),
91
+ // Crate("rustc_apfloat"),
92
+ // Crate("rustc_back"),
93
+ // Crate("rustc_binaryen"),
94
+ // Crate("rustc_const_eval"),
95
+ // Crate("rustc_const_math"),
96
+ // Crate("rustc_cratesio_shim"),
97
+ // Crate("rustc_data_structures"),
98
+ // Crate("rustc_errors"),
99
+ // Crate("rustc_incremental"),
100
+ // Crate("rustc_llvm"),
101
+ // Crate("rustc_mir"),
102
+ // Crate("rustc_platform_intrinsics"),
103
+ // Crate("rustc_trans"),
104
+ // Crate("rustc_trans_utils"),
105
+ // Crate("serialize"),
106
+ // Crate("smallvec"),
107
+ // Crate("stable_deref_trait"),
108
+ // Crate("syntax"),
109
+ // Crate("syntax_pos"),
110
+ // Crate("tempdir"),
111
+ // Crate("unicode-width"),
112
+ // Crate("winapi"),
113
+ // Crate("winapi-build"),
114
+ // Crate("winapi-i686-pc-windows-gnu"),
115
+ // Crate("winapi-x86_64-pc-windows-gnu"),
114
116
] ;
115
117
116
118
// Some types for Serde to deserialize the output of `cargo metadata` to...
@@ -135,16 +137,32 @@ struct ResolveNode {
135
137
#[ derive( Copy , Clone , PartialOrd , Ord , PartialEq , Eq , Debug , Hash ) ]
136
138
struct Crate < ' a > ( & ' a str ) ; // (name,)
137
139
140
+ #[ derive( Copy , Clone , PartialOrd , Ord , PartialEq , Eq , Debug , Hash ) ]
141
+ struct CrateVersion < ' a > ( & ' a str , & ' a str ) ; // (name, version)
142
+
138
143
impl < ' a > Crate < ' a > {
144
+ pub fn id_str ( & self ) -> String {
145
+ format ! ( "{} " , self . 0 )
146
+ }
147
+ }
148
+
149
+ impl < ' a > CrateVersion < ' a > {
139
150
pub fn from_str ( s : & ' a str ) -> Self {
140
151
let mut parts = s. split ( " " ) ;
141
152
let name = parts. next ( ) . unwrap ( ) ;
153
+ let version = parts. next ( ) . unwrap ( ) ;
142
154
143
- Crate ( name)
155
+ CrateVersion ( name, version )
144
156
}
145
157
146
158
pub fn id_str ( & self ) -> String {
147
- format ! ( "{} " , self . 0 )
159
+ format ! ( "{} {}" , self . 0 , self . 1 )
160
+ }
161
+ }
162
+
163
+ impl < ' a > From < CrateVersion < ' a > > for Crate < ' a > {
164
+ fn from ( cv : CrateVersion < ' a > ) -> Crate < ' a > {
165
+ Crate ( cv. 0 )
148
166
}
149
167
}
150
168
@@ -266,8 +284,8 @@ fn get_deps(path: &Path, cargo: &Path) -> Resolve {
266
284
fn check_crate_whitelist < ' a , ' b > (
267
285
whitelist : & ' a HashSet < Crate > ,
268
286
resolve : & ' a Resolve ,
269
- visited : & ' b mut BTreeSet < Crate < ' a > > ,
270
- krate : Crate < ' a > ,
287
+ visited : & ' b mut BTreeSet < CrateVersion < ' a > > ,
288
+ krate : CrateVersion < ' a > ,
271
289
) -> BTreeSet < Crate < ' a > > {
272
290
// Will contain bad deps
273
291
let mut unapproved = BTreeSet :: new ( ) ;
@@ -280,8 +298,8 @@ fn check_crate_whitelist<'a, 'b>(
280
298
visited. insert ( krate) ;
281
299
282
300
// If this dependency is not on the WHITELIST, add to bad set
283
- if !whitelist. contains ( & krate) {
284
- unapproved. insert ( krate) ;
301
+ if !whitelist. contains ( & krate. into ( ) ) {
302
+ unapproved. insert ( krate. into ( ) ) ;
285
303
}
286
304
287
305
// Do a DFS in the crate graph (it's a DAG, so we know we have no cycles!)
@@ -292,7 +310,7 @@ fn check_crate_whitelist<'a, 'b>(
292
310
. expect ( "crate does not exist" ) ;
293
311
294
312
for dep in to_check. dependencies . iter ( ) {
295
- let krate = Crate :: from_str ( dep) ;
313
+ let krate = CrateVersion :: from_str ( dep) ;
296
314
let mut bad = check_crate_whitelist ( whitelist, resolve, visited, krate) ;
297
315
298
316
unapproved. append ( & mut bad) ;
0 commit comments