]> git.lizzy.rs Git - rust.git/blob - src/tools/tidy/src/extdeps.rs
Auto merge of #102700 - oli-obk:0xDEAD_TAIT, r=compiler-errors
[rust.git] / src / tools / tidy / src / extdeps.rs
1 //! Check for external package sources. Allow only vendorable packages.
2
3 use std::fs;
4 use std::path::Path;
5
6 /// List of allowed sources for packages.
7 const ALLOWED_SOURCES: &[&str] = &["\"registry+https://github.com/rust-lang/crates.io-index\""];
8
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");
14
15     // Open and read the whole file.
16     let cargo_lock = t!(fs::read_to_string(&path));
17
18     // Process each line.
19     for line in cargo_lock.lines() {
20         // Consider only source entries.
21         if !line.starts_with("source = ") {
22             continue;
23         }
24
25         // Extract source value.
26         let source = line.split_once('=').unwrap().1.trim();
27
28         // Ensure source is allowed.
29         if !ALLOWED_SOURCES.contains(&&*source) {
30             tidy_error!(bad, "invalid source: {}", source);
31         }
32     }
33 }