1 //! Check for external package sources. Allow only vendorable packages.
6 /// List of allowed sources for packages.
7 const ALLOWED_SOURCES: &[&str] = &["\"registry+https://github.com/rust-lang/crates.io-index\""];
9 /// Checks for external package sources. `root` is the path to the directory that contains the
10 /// workspace `Cargo.toml`.
11 pub fn check(root: &Path, bad: &mut bool) {
12 // `Cargo.lock` of rust.
13 let path = root.join("Cargo.lock");
15 // Open and read the whole file.
16 let cargo_lock = t!(fs::read_to_string(&path));
19 for line in cargo_lock.lines() {
20 // Consider only source entries.
21 if !line.starts_with("source = ") {
25 // Extract source value.
26 let source = line.split_once('=').unwrap().1.trim();
28 // Ensure source is allowed.
29 if !ALLOWED_SOURCES.contains(&&*source) {
30 tidy_error!(bad, "invalid source: {}", source);