Check for external package sources in all workspaces

This commit is contained in:
bjorn3 2023-08-25 19:29:28 +00:00
parent 212f273dbc
commit 6baa14787e
2 changed files with 38 additions and 26 deletions

View file

@ -42,21 +42,21 @@ type ExceptionList = &'static [(&'static str, &'static str)];
/// * Optionally a tuple of:
/// * A list of crates for which dependencies need to be explicitly allowed.
/// * The list of allowed dependencies.
const WORKSPACES: &[(&str, ExceptionList, Option<(&[&str], &[&str])>)] = &[
pub(crate) const WORKSPACES: &[(&str, ExceptionList, Option<(&[&str], &[&str])>)] = &[
// The root workspace has to be first for check_rustfix to work.
("Cargo.toml", EXCEPTIONS, Some((&["rustc-main"], PERMITTED_RUSTC_DEPENDENCIES))),
(".", EXCEPTIONS, Some((&["rustc-main"], PERMITTED_RUSTC_DEPENDENCIES))),
// Outside of the alphabetical section because rustfmt formats it using multiple lines.
(
"compiler/rustc_codegen_cranelift/Cargo.toml",
"compiler/rustc_codegen_cranelift",
EXCEPTIONS_CRANELIFT,
Some((&["rustc_codegen_cranelift"], PERMITTED_CRANELIFT_DEPENDENCIES)),
),
// tidy-alphabetical-start
("compiler/rustc_codegen_gcc/Cargo.toml", EXCEPTIONS_GCC, None),
("src/bootstrap/Cargo.toml", EXCEPTIONS_BOOTSTRAP, None),
("src/tools/cargo/Cargo.toml", EXCEPTIONS_CARGO, None),
("src/tools/rust-analyzer/Cargo.toml", EXCEPTIONS_RUST_ANALYZER, None),
("src/tools/x/Cargo.toml", &[], None),
("compiler/rustc_codegen_gcc", EXCEPTIONS_GCC, None),
("src/bootstrap", EXCEPTIONS_BOOTSTRAP, None),
("src/tools/cargo", EXCEPTIONS_CARGO, None),
("src/tools/rust-analyzer", EXCEPTIONS_RUST_ANALYZER, None),
("src/tools/x", &[], None),
// tidy-alphabetical-end
];
@ -438,7 +438,7 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
for &(workspace, exceptions, permitted_deps) in WORKSPACES {
let mut cmd = cargo_metadata::MetadataCommand::new();
cmd.cargo_path(cargo)
.manifest_path(root.join(workspace))
.manifest_path(root.join(workspace).join("Cargo.toml"))
.features(cargo_metadata::CargoOpt::AllFeatures);
let metadata = t!(cmd.exec());
@ -447,12 +447,12 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
check_permitted_dependencies(&metadata, workspace, permitted_deps, crates, bad);
}
if workspace == "Cargo.toml" {
if workspace == "." {
let runtime_ids = compute_runtime_crates(&metadata);
check_runtime_license_exceptions(&metadata, runtime_ids, bad);
checked_runtime_licenses = true;
rust_metadata = Some(metadata);
} else if workspace == "src/tools/cargo/Cargo.toml" {
} else if workspace == "src/tools/cargo" {
check_rustfix(
rust_metadata
.as_ref()

View file

@ -9,25 +9,37 @@ const ALLOWED_SOURCES: &[&str] = &["\"registry+https://github.com/rust-lang/crat
/// Checks for external package sources. `root` is the path to the directory that contains the
/// workspace `Cargo.toml`.
pub fn check(root: &Path, bad: &mut bool) {
// `Cargo.lock` of rust.
let path = root.join("Cargo.lock");
for &(workspace, _, _) in crate::deps::WORKSPACES {
// FIXME check other workspaces too
// `Cargo.lock` of rust.
let path = root.join(workspace).join("Cargo.lock");
// Open and read the whole file.
let cargo_lock = t!(fs::read_to_string(&path));
// Open and read the whole file.
let cargo_lock = t!(fs::read_to_string(&path));
// Process each line.
for line in cargo_lock.lines() {
// Consider only source entries.
if !line.starts_with("source = ") {
continue;
}
// 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();
// Extract source value.
let source = line.split_once('=').unwrap().1.trim();
// Ensure source is allowed.
if !ALLOWED_SOURCES.contains(&&*source) {
tidy_error!(bad, "invalid source: {}", source);
// Ensure source is allowed.
if !ALLOWED_SOURCES.contains(&&*source) {
if workspace == "compiler/rustc_codegen_gcc" {
// FIXME stop using git dependencies for rustc_codegen_gcc?
if source
== "\"git+https://github.com/antoyo/gccjit.rs#d6e52626cfc6f487094a5d5ac66302baf3439984\""
{
continue;
}
}
tidy_error!(bad, "invalid source: {}", source);
}
}
}
}