1use std::fs;
4use std::path::Path;
5
6use crate::deps::WorkspaceInfo;
7use crate::diagnostics::TidyCtx;
8
9const ALLOWED_SOURCES: &[&str] = &[
11 r#""registry+https://github.com/rust-lang/crates.io-index""#,
12 r#""git+https://github.com/rust-lang/team#a5260e76d3aa894c64c56e6ddc8545b9a98043ec""#,
14];
15
16pub fn check(root: &Path, tidy_ctx: TidyCtx) {
19 let mut check = tidy_ctx.start_check("extdeps");
20
21 for &WorkspaceInfo { path, submodules, .. } in crate::deps::WORKSPACES {
22 if crate::deps::has_missing_submodule(root, submodules) {
23 continue;
24 }
25
26 let lockfile = root.join(path).join("Cargo.lock");
29
30 if !lockfile.exists() {
31 check.error(format!("the `{path}` workspace doesn't have a Cargo.lock"));
32 continue;
33 }
34
35 let cargo_lock = t!(fs::read_to_string(&lockfile));
37
38 for line in cargo_lock.lines() {
40 if !line.starts_with("source = ") {
42 continue;
43 }
44
45 let source = line.split_once('=').unwrap().1.trim();
47
48 if !ALLOWED_SOURCES.contains(&source) {
50 check.error(format!("invalid source: {}", source));
51 }
52 }
53 }
54}