|
10 | 10 |
|
11 | 11 | //! Check license of third-party deps by inspecting src/vendor
|
12 | 12 |
|
13 |
| -use std::collections::{BTreeSet, HashSet}; |
| 13 | +use std::collections::{BTreeSet, HashSet, HashMap}; |
14 | 14 | use std::fs::File;
|
15 | 15 | use std::io::Read;
|
16 | 16 | use std::path::Path;
|
@@ -242,6 +242,8 @@ pub fn check_whitelist(path: &Path, cargo: &Path, bad: &mut bool) {
|
242 | 242 | }
|
243 | 243 | *bad = true;
|
244 | 244 | }
|
| 245 | + |
| 246 | + check_crate_duplicate(&resolve, bad); |
245 | 247 | }
|
246 | 248 |
|
247 | 249 | fn check_license(path: &Path) -> bool {
|
@@ -344,3 +346,30 @@ fn check_crate_whitelist<'a, 'b>(
|
344 | 346 |
|
345 | 347 | unapproved
|
346 | 348 | }
|
| 349 | + |
| 350 | +fn check_crate_duplicate(resolve: &Resolve, bad: &mut bool) { |
| 351 | + const FORBIDDEN_TO_HAVE_DUPLICATES: &[&str] = &[ |
| 352 | + // These two crates take quite a long time to build, let's not let two |
| 353 | + // versions of them accidentally sneak into our dependency graph to |
| 354 | + // ensure we keep our CI times under control |
| 355 | + // "cargo", // FIXME(#53005) |
| 356 | + // "rustc-ap-syntax", // FIXME(#53006) |
| 357 | + ]; |
| 358 | + let mut name_to_id = HashMap::new(); |
| 359 | + for node in resolve.nodes.iter() { |
| 360 | + name_to_id.entry(node.id.split_whitespace().next().unwrap()) |
| 361 | + .or_insert(Vec::new()) |
| 362 | + .push(&node.id); |
| 363 | + } |
| 364 | + |
| 365 | + for name in FORBIDDEN_TO_HAVE_DUPLICATES { |
| 366 | + if name_to_id[name].len() <= 1 { |
| 367 | + continue |
| 368 | + } |
| 369 | + println!("crate `{}` is duplicated in `Cargo.lock`", name); |
| 370 | + for id in name_to_id[name].iter() { |
| 371 | + println!(" * {}", id); |
| 372 | + } |
| 373 | + *bad = true; |
| 374 | + } |
| 375 | +} |
0 commit comments