Skip to content

Commit 11a22b3

Browse files
committed
tidy: Add specific line info for allowed dependencies
1 parent adfb6ec commit 11a22b3

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

src/tools/tidy/src/deps.rs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const LICENSES: &[&str] = &[
4848

4949
type ExceptionList = &'static [(&'static str, &'static str)];
5050

51+
#[derive(Clone, Copy)]
5152
pub(crate) struct WorkspaceInfo<'a> {
5253
/// Path to the directory containing the workspace root Cargo.toml file.
5354
pub(crate) path: &'a str,
@@ -56,7 +57,8 @@ pub(crate) struct WorkspaceInfo<'a> {
5657
/// Optionally:
5758
/// * A list of crates for which dependencies need to be explicitly allowed.
5859
/// * The list of allowed dependencies.
59-
pub(crate) crates_and_deps: Option<(&'a [&'a str], &'a [&'a str])>,
60+
/// * The source code location of the allowed dependencies list
61+
crates_and_deps: Option<(&'a [&'a str], &'a [&'a str], ListLocation)>,
6062
/// Submodules required for the workspace
6163
pub(crate) submodules: &'a [&'a str],
6264
}
@@ -65,7 +67,7 @@ impl<'a> WorkspaceInfo<'a> {
6567
const fn new(
6668
path: &'a str,
6769
exceptions: ExceptionList,
68-
crates_and_deps: Option<(&'a [&str], &'a [&str])>,
70+
crates_and_deps: Option<(&'a [&str], &'a [&str], ListLocation)>,
6971
submodules: &'a [&str],
7072
) -> Self {
7173
Self { path, exceptions, crates_and_deps, submodules }
@@ -76,18 +78,27 @@ impl<'a> WorkspaceInfo<'a> {
7678
// FIXME auto detect all cargo workspaces
7779
pub(crate) const WORKSPACES: &[WorkspaceInfo<'static>] = &[
7880
// The root workspace has to be first for check_rustfix to work.
79-
WorkspaceInfo::new(".", EXCEPTIONS, Some((&["rustc-main"], PERMITTED_RUSTC_DEPENDENCIES)), &[]),
81+
WorkspaceInfo::new(
82+
".",
83+
EXCEPTIONS,
84+
Some((&["rustc-main"], PERMITTED_RUSTC_DEPENDENCIES, PERMITTED_RUSTC_DEPS_LOCATION)),
85+
&[],
86+
),
8087
WorkspaceInfo::new(
8188
"library",
8289
EXCEPTIONS_STDLIB,
83-
Some((&["sysroot"], PERMITTED_STDLIB_DEPENDENCIES)),
90+
Some((&["sysroot"], PERMITTED_STDLIB_DEPENDENCIES, PERMITTED_STDLIB_DEPS_LOCATION)),
8491
&[],
8592
),
8693
// Outside of the alphabetical section because rustfmt formats it using multiple lines.
8794
WorkspaceInfo::new(
8895
"compiler/rustc_codegen_cranelift",
8996
EXCEPTIONS_CRANELIFT,
90-
Some((&["rustc_codegen_cranelift"], PERMITTED_CRANELIFT_DEPENDENCIES)),
97+
Some((
98+
&["rustc_codegen_cranelift"],
99+
PERMITTED_CRANELIFT_DEPENDENCIES,
100+
PERMITTED_CRANELIFT_DEPS_LOCATION,
101+
)),
91102
&[],
92103
),
93104
// tidy-alphabetical-start
@@ -261,6 +272,7 @@ const EXCEPTIONS_UEFI_QEMU_TEST: ExceptionList = &[
261272
("r-efi", "MIT OR Apache-2.0 OR LGPL-2.1-or-later"), // LGPL is not acceptable, but we use it under MIT OR Apache-2.0
262273
];
263274

275+
#[derive(Clone, Copy)]
264276
struct ListLocation {
265277
path: &'static str,
266278
line: u32,
@@ -499,6 +511,8 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
499511
// tidy-alphabetical-end
500512
];
501513

514+
const PERMITTED_STDLIB_DEPS_LOCATION: ListLocation = location!(+2);
515+
502516
const PERMITTED_STDLIB_DEPENDENCIES: &[&str] = &[
503517
// tidy-alphabetical-start
504518
"addr2line",
@@ -540,6 +554,8 @@ const PERMITTED_STDLIB_DEPENDENCIES: &[&str] = &[
540554
// tidy-alphabetical-end
541555
];
542556

557+
const PERMITTED_CRANELIFT_DEPS_LOCATION: ListLocation = location!(+2);
558+
543559
const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[
544560
// tidy-alphabetical-start
545561
"allocator-api2",
@@ -632,9 +648,9 @@ pub fn check(root: &Path, cargo: &Path, bless: bool, bad: &mut bool) {
632648
let metadata = t!(cmd.exec());
633649

634650
check_license_exceptions(&metadata, path, exceptions, bad);
635-
if let Some((crates, permitted_deps)) = crates_and_deps {
651+
if let Some((crates, permitted_deps, location)) = crates_and_deps {
636652
let descr = crates.get(0).unwrap_or(&path);
637-
check_permitted_dependencies(&metadata, descr, permitted_deps, crates, bad);
653+
check_permitted_dependencies(&metadata, descr, permitted_deps, crates, location, bad);
638654
}
639655

640656
if path == "library" {
@@ -882,6 +898,7 @@ fn check_permitted_dependencies(
882898
descr: &str,
883899
permitted_dependencies: &[&'static str],
884900
restricted_dependency_crates: &[&'static str],
901+
permitted_location: ListLocation,
885902
bad: &mut bool,
886903
) {
887904
let mut has_permitted_dep_error = false;
@@ -942,8 +959,7 @@ fn check_permitted_dependencies(
942959
}
943960

944961
if has_permitted_dep_error {
945-
let ListLocation { path, line } = PERMITTED_RUSTC_DEPS_LOCATION;
946-
eprintln!("Go to `{path}:{line}` for the list.");
962+
eprintln!("Go to `{}:{}` for the list.", permitted_location.path, permitted_location.line);
947963
}
948964
}
949965

0 commit comments

Comments
 (0)