Skip to content
Open
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
42 changes: 29 additions & 13 deletions src/tools/tidy/src/deps.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Checks the licenses of third-party dependencies.

use std::collections::{HashMap, HashSet};
use std::fmt::{Display, Formatter};
use std::fs::{File, read_dir};
use std::io::Write;
use std::path::Path;
Expand All @@ -14,6 +15,25 @@ use crate::diagnostics::{RunningCheck, TidyCtx};
#[path = "../../../bootstrap/src/utils/proc_macro_deps.rs"]
mod proc_macro_deps;

#[derive(Clone, Copy)]
struct ListLocation {
path: &'static str,
line: u32,
}

impl Display for ListLocation {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}:{}", self.path, self.line)
}
}

/// Creates a [`ListLocation`] for the current location (with an additional offset to the actual list start);
macro_rules! location {
(+ $offset:literal) => {
ListLocation { path: file!(), line: line!() + $offset }
};
}

/// These are licenses that are allowed for all crates, including the runtime,
/// rustc, tools, etc.
#[rustfmt::skip]
Expand Down Expand Up @@ -87,6 +107,8 @@ pub(crate) struct WorkspaceInfo<'a> {
pub(crate) submodules: &'a [&'a str],
}

const WORKSPACE_LOCATION: ListLocation = location!(+4);

/// The workspaces to check for licensing and optionally permitted dependencies.
// FIXME auto detect all cargo workspaces
pub(crate) const WORKSPACES: &[WorkspaceInfo<'static>] = &[
Expand Down Expand Up @@ -248,19 +270,6 @@ const EXCEPTIONS_BOOTSTRAP: ExceptionList = &[];

const EXCEPTIONS_UEFI_QEMU_TEST: ExceptionList = &[];

#[derive(Clone, Copy)]
struct ListLocation {
path: &'static str,
line: u32,
}

/// Creates a [`ListLocation`] for the current location (with an additional offset to the actual list start);
macro_rules! location {
(+ $offset:literal) => {
ListLocation { path: file!(), line: line!() + $offset }
};
}

const PERMITTED_RUSTC_DEPS_LOCATION: ListLocation = location!(+6);

/// Crates rustc is allowed to depend on. Avoid adding to the list if possible.
Expand Down Expand Up @@ -646,6 +655,13 @@ pub fn check(root: &Path, cargo: &Path, tidy_ctx: TidyCtx) {
.other_options(vec!["--locked".to_owned()]);
let metadata = t!(cmd.exec());

// Check for packages which have been moved into a different workspace and not updated
let canonicalized_root =
if path == "." { root.to_path_buf() } else { t!(root.join(path).canonicalize()) };
let canonicalized_root_real = t!(metadata.workspace_root.canonicalize());
if canonicalized_root_real != canonicalized_root {
check.error(format!("{path} is part of another workspace, remove from `WORKSPACES` ({WORKSPACE_LOCATION})"));
}
check_license_exceptions(&metadata, path, exceptions, &mut check);
if let Some((crates, permitted_deps, location)) = crates_and_deps {
let descr = crates.get(0).unwrap_or(&path);
Expand Down
Loading