Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions src/tools/tidy/src/extdeps.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
//! Check for external package sources. Allow only vendorable packages.

use std::fs;
use std::io::{BufRead as _, BufReader};
use std::path::Path;

use crate::deps::WorkspaceInfo;
use crate::diagnostics::DiagCtx;

/// List of allowed sources for packages.
const ALLOWED_SOURCES: &[&str] = &[
r#""registry+https://github.com/rust-lang/crates.io-index""#,
"registry+https://github.com/rust-lang/crates.io-index",
// This is `rust_team_data` used by `site` in src/tools/rustc-perf,
r#""git+https://github.com/rust-lang/team#a5260e76d3aa894c64c56e6ddc8545b9a98043ec""#,
"git+https://github.com/rust-lang/team#a5260e76d3aa894c64c56e6ddc8545b9a98043ec",
];

/// Checks for external package sources. `root` is the path to the directory that contains the
Expand All @@ -23,30 +24,23 @@ pub fn check(root: &Path, diag_ctx: DiagCtx) {
continue;
}

// FIXME check other workspaces too
// `Cargo.lock` of rust.
let lockfile = root.join(path).join("Cargo.lock");

if !lockfile.exists() {
check.error(format!("the `{path}` workspace doesn't have a Cargo.lock"));
continue;
}

// Open and read the whole file.
let cargo_lock = t!(fs::read_to_string(&lockfile));
// At the time of writing, longest line in lockfile is 82 bytes.
let cargo_lock = BufReader::with_capacity(128, t!(fs::File::open(&lockfile)));
let mut lines = cargo_lock.lines();

// Process each line.
for line in cargo_lock.lines() {
// Consider only source entries.
if !line.starts_with("source = ") {
continue;
}

// Extract source value.
let source = line.split_once('=').unwrap().1.trim();

// Ensure source is allowed.
if !ALLOWED_SOURCES.contains(&source) {
while let Some(line) = t!(lines.next().transpose()) {
if let Some(source) = line.strip_prefix(r#"source = ""#)
&& let Some(source) = source.strip_suffix(r#"""#)
&& !ALLOWED_SOURCES.contains(&source)
{
check.error(format!("invalid source: {}", source));
}
}
Expand Down
Loading