Skip to content

Commit f1b3570

Browse files
Auto merge of #149417 - clubby789:stale-workspace-list, r=<try>
tidy: Detect outdated workspaces in workspace list try-job: x86_64-msvc-2
2 parents a9ac706 + 4e51a8d commit f1b3570

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

src/tools/tidy/src/deps.rs

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Checks the licenses of third-party dependencies.
22
33
use std::collections::{HashMap, HashSet};
4+
use std::fmt::{Display, Formatter};
45
use std::fs::{File, read_dir};
56
use std::io::Write;
67
use std::path::Path;
@@ -14,6 +15,25 @@ use crate::diagnostics::{RunningCheck, TidyCtx};
1415
#[path = "../../../bootstrap/src/utils/proc_macro_deps.rs"]
1516
mod proc_macro_deps;
1617

18+
#[derive(Clone, Copy)]
19+
struct ListLocation {
20+
path: &'static str,
21+
line: u32,
22+
}
23+
24+
impl Display for ListLocation {
25+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
26+
write!(f, "{}:{}", self.path, self.line)
27+
}
28+
}
29+
30+
/// Creates a [`ListLocation`] for the current location (with an additional offset to the actual list start);
31+
macro_rules! location {
32+
(+ $offset:literal) => {
33+
ListLocation { path: file!(), line: line!() + $offset }
34+
};
35+
}
36+
1737
/// These are licenses that are allowed for all crates, including the runtime,
1838
/// rustc, tools, etc.
1939
#[rustfmt::skip]
@@ -87,6 +107,8 @@ pub(crate) struct WorkspaceInfo<'a> {
87107
pub(crate) submodules: &'a [&'a str],
88108
}
89109

110+
const WORKSPACE_LOCATION: ListLocation = location!(+4);
111+
90112
/// The workspaces to check for licensing and optionally permitted dependencies.
91113
// FIXME auto detect all cargo workspaces
92114
pub(crate) const WORKSPACES: &[WorkspaceInfo<'static>] = &[
@@ -242,19 +264,6 @@ const EXCEPTIONS_BOOTSTRAP: ExceptionList = &[];
242264

243265
const EXCEPTIONS_UEFI_QEMU_TEST: ExceptionList = &[];
244266

245-
#[derive(Clone, Copy)]
246-
struct ListLocation {
247-
path: &'static str,
248-
line: u32,
249-
}
250-
251-
/// Creates a [`ListLocation`] for the current location (with an additional offset to the actual list start);
252-
macro_rules! location {
253-
(+ $offset:literal) => {
254-
ListLocation { path: file!(), line: line!() + $offset }
255-
};
256-
}
257-
258267
const PERMITTED_RUSTC_DEPS_LOCATION: ListLocation = location!(+6);
259268

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

653+
// Check for packages which have been moved into a different workspace and not updated
654+
let absolute_root =
655+
if path == "." { root.to_path_buf() } else { t!(std::path::absolute(root.join(path))) };
656+
let absolute_root_real = t!(std::path::absolute(&metadata.workspace_root));
657+
if absolute_root_real != absolute_root {
658+
check.error(format!("{path} is part of another workspace ({} != {}), remove from `WORKSPACES` ({WORKSPACE_LOCATION})", absolute_root.display(), absolute_root_real.display()));
659+
}
644660
check_license_exceptions(&metadata, path, exceptions, &mut check);
645661
if let Some((crates, permitted_deps, location)) = crates_and_deps {
646662
let descr = crates.get(0).unwrap_or(&path);

0 commit comments

Comments
 (0)