Skip to content

Commit 18f0533

Browse files
committed
different versions may have different deps
1 parent 0fc5dae commit 18f0533

File tree

1 file changed

+84
-66
lines changed

1 file changed

+84
-66
lines changed

src/tools/tidy/src/deps.rs

Lines changed: 84 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -49,68 +49,70 @@ static EXCEPTIONS: &'static [&'static str] = &[
4949
];
5050

5151
/// 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+
];
5356

5457
/// Whitelist of crates rustc is allowed to depend on. Avoid adding to the list if possible.
5558
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"),
114116
];
115117

116118
// Some types for Serde to deserialize the output of `cargo metadata` to...
@@ -135,16 +137,32 @@ struct ResolveNode {
135137
#[derive(Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Debug, Hash)]
136138
struct Crate<'a>(&'a str); // (name,)
137139

140+
#[derive(Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Debug, Hash)]
141+
struct CrateVersion<'a>(&'a str, &'a str); // (name, version)
142+
138143
impl<'a> Crate<'a> {
144+
pub fn id_str(&self) -> String {
145+
format!("{} ", self.0)
146+
}
147+
}
148+
149+
impl<'a> CrateVersion<'a> {
139150
pub fn from_str(s: &'a str) -> Self {
140151
let mut parts = s.split(" ");
141152
let name = parts.next().unwrap();
153+
let version = parts.next().unwrap();
142154

143-
Crate(name)
155+
CrateVersion(name, version)
144156
}
145157

146158
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)
148166
}
149167
}
150168

@@ -266,8 +284,8 @@ fn get_deps(path: &Path, cargo: &Path) -> Resolve {
266284
fn check_crate_whitelist<'a, 'b>(
267285
whitelist: &'a HashSet<Crate>,
268286
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>,
271289
) -> BTreeSet<Crate<'a>> {
272290
// Will contain bad deps
273291
let mut unapproved = BTreeSet::new();
@@ -280,8 +298,8 @@ fn check_crate_whitelist<'a, 'b>(
280298
visited.insert(krate);
281299

282300
// 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());
285303
}
286304

287305
// 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>(
292310
.expect("crate does not exist");
293311

294312
for dep in to_check.dependencies.iter() {
295-
let krate = Crate::from_str(dep);
313+
let krate = CrateVersion::from_str(dep);
296314
let mut bad = check_crate_whitelist(whitelist, resolve, visited, krate);
297315

298316
unapproved.append(&mut bad);

0 commit comments

Comments
 (0)