Skip to content

Commit 6c8f6bd

Browse files
authored
Rollup merge of #163255 - bjorn3:stricter_tidy_dep_check, r=clubby789
Check the entire library and cg_clif workspaces for permitted deps in tidy We ship the entire library workspace in the rust-src component, so even if the standard library doesn't depend on a crate, having it in the library workspace still increases the amount of storage a rust install takes. And for cg_clif I personally want to keep deps to a minimum even those not for the backend itself.
2 parents d63e457 + fc538ec commit 6c8f6bd

1 file changed

Lines changed: 54 additions & 28 deletions

File tree

‎src/tools/tidy/src/deps.rs‎

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,34 @@ pub(crate) struct WorkspaceInfo<'a> {
9595
pub(crate) path: &'a str,
9696
/// The list of license exceptions.
9797
pub(crate) exceptions: ExceptionList,
98-
/// Optionally:
99-
/// * A list of crates for which dependencies need to be explicitly allowed.
100-
/// * The list of allowed dependencies.
101-
/// * The source code location of the allowed dependencies list
102-
crates_and_deps: Option<(&'a [&'a str], &'a [&'a str], ListLocation)>,
98+
/// The list of dependencies that are allowed. If None, any crate with an
99+
/// acceptable license is allowed.
100+
allowed_deps: Option<PermittedDeps<'a>>,
103101
/// Submodules required for the workspace
104102
pub(crate) submodules: &'a [&'a str],
105103
}
106104

105+
#[derive(Clone, Copy)]
106+
struct PermittedDeps<'a> {
107+
/// A list of crates for which dependencies need to be explicitly allowed
108+
/// or None to check the entire workspace.
109+
roots: Option<&'a [&'a str]>,
110+
/// The list of allowed dependencies.
111+
deps: &'a [&'a str],
112+
/// The source code location of the allowed dependencies list.
113+
deps_loc: ListLocation,
114+
}
115+
116+
impl<'a> PermittedDeps<'a> {
117+
const fn new(
118+
roots: Option<&'a [&'a str]>,
119+
deps: &'a [&'a str],
120+
deps_loc: ListLocation,
121+
) -> Self {
122+
Self { roots, deps, deps_loc }
123+
}
124+
}
125+
107126
const WORKSPACE_LOCATION: ListLocation = location!(+4);
108127

109128
/// The workspaces to check for licensing and optionally permitted dependencies.
@@ -113,8 +132,8 @@ pub(crate) const WORKSPACES: &[WorkspaceInfo<'static>] = &[
113132
WorkspaceInfo {
114133
path: ".",
115134
exceptions: EXCEPTIONS,
116-
crates_and_deps: Some((
117-
&["rustc-main"],
135+
allowed_deps: Some(PermittedDeps::new(
136+
Some(&["rustc-main"]),
118137
PERMITTED_RUSTC_DEPENDENCIES,
119138
PERMITTED_RUSTC_DEPS_LOCATION,
120139
)),
@@ -123,8 +142,8 @@ pub(crate) const WORKSPACES: &[WorkspaceInfo<'static>] = &[
123142
WorkspaceInfo {
124143
path: "library",
125144
exceptions: EXCEPTIONS_STDLIB,
126-
crates_and_deps: Some((
127-
&["sysroot"],
145+
allowed_deps: Some(PermittedDeps::new(
146+
None,
128147
PERMITTED_STDLIB_DEPENDENCIES,
129148
PERMITTED_STDLIB_DEPS_LOCATION,
130149
)),
@@ -133,14 +152,14 @@ pub(crate) const WORKSPACES: &[WorkspaceInfo<'static>] = &[
133152
WorkspaceInfo {
134153
path: "library/stdarch",
135154
exceptions: EXCEPTIONS_STDARCH,
136-
crates_and_deps: None,
155+
allowed_deps: None,
137156
submodules: &[],
138157
},
139158
WorkspaceInfo {
140159
path: "compiler/rustc_codegen_cranelift",
141160
exceptions: EXCEPTIONS_CRANELIFT,
142-
crates_and_deps: Some((
143-
&["rustc_codegen_cranelift"],
161+
allowed_deps: Some(PermittedDeps::new(
162+
None,
144163
PERMITTED_CRANELIFT_DEPENDENCIES,
145164
PERMITTED_CRANELIFT_DEPS_LOCATION,
146165
)),
@@ -149,19 +168,19 @@ pub(crate) const WORKSPACES: &[WorkspaceInfo<'static>] = &[
149168
WorkspaceInfo {
150169
path: "compiler/rustc_codegen_gcc",
151170
exceptions: EXCEPTIONS_GCC,
152-
crates_and_deps: None,
171+
allowed_deps: None,
153172
submodules: &[],
154173
},
155174
WorkspaceInfo {
156175
path: "src/bootstrap",
157176
exceptions: EXCEPTIONS_BOOTSTRAP,
158-
crates_and_deps: None,
177+
allowed_deps: None,
159178
submodules: &[],
160179
},
161180
WorkspaceInfo {
162181
path: "src/tools/cargo",
163182
exceptions: EXCEPTIONS_CARGO,
164-
crates_and_deps: None,
183+
allowed_deps: None,
165184
submodules: &["src/tools/cargo"],
166185
},
167186
// FIXME uncomment once all deps are vendored
@@ -178,25 +197,25 @@ pub(crate) const WORKSPACES: &[WorkspaceInfo<'static>] = &[
178197
WorkspaceInfo {
179198
path: "src/tools/rust-analyzer",
180199
exceptions: EXCEPTIONS_RUST_ANALYZER,
181-
crates_and_deps: None,
200+
allowed_deps: None,
182201
submodules: &[],
183202
},
184203
WorkspaceInfo {
185204
path: "src/tools/rustbook",
186205
exceptions: EXCEPTIONS_RUSTBOOK,
187-
crates_and_deps: None,
206+
allowed_deps: None,
188207
submodules: &["src/doc/book", "src/doc/reference"],
189208
},
190209
WorkspaceInfo {
191210
path: "src/tools/rustc-perf",
192211
exceptions: EXCEPTIONS_RUSTC_PERF,
193-
crates_and_deps: None,
212+
allowed_deps: None,
194213
submodules: &["src/tools/rustc-perf"],
195214
},
196215
WorkspaceInfo {
197216
path: "tests/run-make-cargo/uefi-qemu/uefi_qemu_test",
198217
exceptions: EXCEPTIONS_UEFI_QEMU_TEST,
199-
crates_and_deps: None,
218+
allowed_deps: None,
200219
submodules: &[],
201220
},
202221
];
@@ -638,7 +657,8 @@ pub fn check(root: &Path, cargo: &Path, tidy_ctx: TidyCtx) {
638657

639658
check_proc_macro_dep_list(root, cargo, bless, &mut check);
640659

641-
for &WorkspaceInfo { path, exceptions, crates_and_deps, submodules } in WORKSPACES {
660+
for &WorkspaceInfo { path, exceptions, allowed_deps: crates_and_deps, submodules } in WORKSPACES
661+
{
642662
if has_missing_submodule(root, submodules, tidy_ctx.is_running_on_ci()) {
643663
continue;
644664
}
@@ -663,14 +683,14 @@ pub fn check(root: &Path, cargo: &Path, tidy_ctx: TidyCtx) {
663683
check.error(format!("{path} is part of another workspace ({} != {}), remove from `WORKSPACES` ({WORKSPACE_LOCATION})", absolute_root.display(), absolute_root_real.display()));
664684
}
665685
check_license_exceptions(&metadata, path, exceptions, &mut check);
666-
if let Some((crates, permitted_deps, location)) = crates_and_deps {
667-
let descr = crates.get(0).unwrap_or(&path);
686+
if let Some(PermittedDeps { roots, deps: permitted_deps, deps_loc }) = crates_and_deps {
687+
let descr = roots.map_or(path, |roots| roots.get(0).unwrap_or(&path));
668688
check_permitted_dependencies(
669689
&metadata,
670690
descr,
671691
permitted_deps,
672-
crates,
673-
location,
692+
roots,
693+
deps_loc,
674694
&mut check,
675695
);
676696
}
@@ -927,15 +947,21 @@ fn check_permitted_dependencies(
927947
metadata: &Metadata,
928948
descr: &str,
929949
permitted_dependencies: &[&'static str],
930-
restricted_dependency_crates: &[&'static str],
950+
restricted_dependency_crates: Option<&[&'static str]>,
931951
permitted_location: ListLocation,
932952
check: &mut RunningCheck,
933953
) {
934954
let mut has_permitted_dep_error = false;
935955
let mut deps = HashSet::new();
936-
for to_check in restricted_dependency_crates {
937-
let to_check = pkg_from_name(metadata, to_check);
938-
deps_of(metadata, &to_check.id, &mut deps);
956+
if let Some(restricted_dependency_crates) = restricted_dependency_crates {
957+
for to_check in restricted_dependency_crates {
958+
let to_check = pkg_from_name(metadata, to_check);
959+
deps_of(metadata, &to_check.id, &mut deps);
960+
}
961+
} else {
962+
for to_check in &metadata.packages {
963+
deps_of(metadata, &to_check.id, &mut deps);
964+
}
939965
}
940966

941967
// Check that the PERMITTED_DEPENDENCIES does not have unused entries.

0 commit comments

Comments
 (0)