Skip to content

Commit e8ef886

Browse files
committed
Fix tidy check if book submodule is not checked out
1 parent 8bfcae7 commit e8ef886

File tree

2 files changed

+29
-33
lines changed

2 files changed

+29
-33
lines changed

Diff for: src/tools/tidy/src/deps.rs

+26-21
Original file line numberDiff line numberDiff line change
@@ -48,31 +48,33 @@ type ExceptionList = &'static [(&'static str, &'static str)];
4848
/// * Optionally a tuple of:
4949
/// * A list of crates for which dependencies need to be explicitly allowed.
5050
/// * The list of allowed dependencies.
51+
/// * Submodules required for the workspace.
5152
// FIXME auto detect all cargo workspaces
52-
pub(crate) const WORKSPACES: &[(&str, ExceptionList, Option<(&[&str], &[&str])>)] = &[
53+
pub(crate) const WORKSPACES: &[(&str, ExceptionList, Option<(&[&str], &[&str])>, &[&str])] = &[
5354
// The root workspace has to be first for check_rustfix to work.
54-
(".", EXCEPTIONS, Some((&["rustc-main"], PERMITTED_RUSTC_DEPENDENCIES))),
55+
(".", EXCEPTIONS, Some((&["rustc-main"], PERMITTED_RUSTC_DEPENDENCIES)), &[]),
5556
// Outside of the alphabetical section because rustfmt formats it using multiple lines.
5657
(
5758
"compiler/rustc_codegen_cranelift",
5859
EXCEPTIONS_CRANELIFT,
5960
Some((&["rustc_codegen_cranelift"], PERMITTED_CRANELIFT_DEPENDENCIES)),
61+
&[],
6062
),
6163
// tidy-alphabetical-start
62-
("compiler/rustc_codegen_gcc", EXCEPTIONS_GCC, None),
64+
("compiler/rustc_codegen_gcc", EXCEPTIONS_GCC, None, &[]),
6365
//("library/backtrace", &[], None), // FIXME uncomment once rust-lang/backtrace#562 has been synced back to the rust repo
6466
//("library/portable-simd", &[], None), // FIXME uncomment once rust-lang/portable-simd#363 has been synced back to the rust repo
6567
//("library/stdarch", EXCEPTIONS_STDARCH, None), // FIXME uncomment once rust-lang/stdarch#1462 has been synced back to the rust repo
66-
("src/bootstrap", EXCEPTIONS_BOOTSTRAP, None),
67-
("src/ci/docker/host-x86_64/test-various/uefi_qemu_test", EXCEPTIONS_UEFI_QEMU_TEST, None),
68-
("src/etc/test-float-parse", EXCEPTIONS, None),
69-
("src/tools/cargo", EXCEPTIONS_CARGO, None),
68+
("src/bootstrap", EXCEPTIONS_BOOTSTRAP, None, &[]),
69+
("src/ci/docker/host-x86_64/test-various/uefi_qemu_test", EXCEPTIONS_UEFI_QEMU_TEST, None, &[]),
70+
("src/etc/test-float-parse", EXCEPTIONS, None, &[]),
71+
("src/tools/cargo", EXCEPTIONS_CARGO, None, &["src/tools/cargo"]),
7072
//("src/tools/miri/test-cargo-miri", &[], None), // FIXME uncomment once all deps are vendored
7173
//("src/tools/miri/test_dependencies", &[], None), // FIXME uncomment once all deps are vendored
72-
("src/tools/rust-analyzer", EXCEPTIONS_RUST_ANALYZER, None),
73-
("src/tools/rustbook", EXCEPTIONS_RUSTBOOK, None),
74-
("src/tools/rustc-perf", EXCEPTIONS_RUSTC_PERF, None),
75-
("src/tools/x", &[], None),
74+
("src/tools/rust-analyzer", EXCEPTIONS_RUST_ANALYZER, None, &[]),
75+
("src/tools/rustbook", EXCEPTIONS_RUSTBOOK, None, &["src/doc/book"]),
76+
("src/tools/rustc-perf", EXCEPTIONS_RUSTC_PERF, None, &["src/tools/rustc-perf"]),
77+
("src/tools/x", &[], None, &[]),
7678
// tidy-alphabetical-end
7779
];
7880

@@ -531,16 +533,8 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[
531533
pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
532534
let mut checked_runtime_licenses = false;
533535

534-
let submodules = build_helper::util::parse_gitmodules(root);
535-
for &(workspace, exceptions, permitted_deps) in WORKSPACES {
536-
// Skip if it's a submodule, not in a CI environment, and not initialized.
537-
//
538-
// This prevents enforcing developers to fetch submodules for tidy.
539-
if submodules.contains(&workspace.into())
540-
&& !CiEnv::is_ci()
541-
// If the directory is empty, we can consider it as an uninitialized submodule.
542-
&& read_dir(root.join(workspace)).unwrap().next().is_none()
543-
{
536+
for &(workspace, exceptions, permitted_deps, submodules) in WORKSPACES {
537+
if has_missing_submodule(root, submodules) {
544538
continue;
545539
}
546540

@@ -573,6 +567,17 @@ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
573567
assert!(checked_runtime_licenses);
574568
}
575569

570+
/// Used to skip a check if a submodule is not checked out, and not in a CI environment.
571+
///
572+
/// This helps prevent enforcing developers to fetch submodules for tidy.
573+
pub fn has_missing_submodule(root: &Path, submodules: &[&str]) -> bool {
574+
!CiEnv::is_ci()
575+
&& submodules.iter().any(|submodule| {
576+
// If the directory is empty, we can consider it as an uninitialized submodule.
577+
read_dir(root.join(submodule)).unwrap().next().is_none()
578+
})
579+
}
580+
576581
/// Check that all licenses of runtime dependencies are in the valid list in `LICENSES`.
577582
///
578583
/// Unlike for tools we don't allow exceptions to the `LICENSES` list for the runtime with the sole

Diff for: src/tools/tidy/src/extdeps.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Check for external package sources. Allow only vendorable packages.
22
3-
use build_helper::ci::CiEnv;
4-
use std::fs::{self, read_dir};
3+
use std::fs;
54
use std::path::Path;
65

76
/// List of allowed sources for packages.
@@ -14,16 +13,8 @@ const ALLOWED_SOURCES: &[&str] = &[
1413
/// Checks for external package sources. `root` is the path to the directory that contains the
1514
/// workspace `Cargo.toml`.
1615
pub fn check(root: &Path, bad: &mut bool) {
17-
let submodules = build_helper::util::parse_gitmodules(root);
18-
for &(workspace, _, _) in crate::deps::WORKSPACES {
19-
// Skip if it's a submodule, not in a CI environment, and not initialized.
20-
//
21-
// This prevents enforcing developers to fetch submodules for tidy.
22-
if submodules.contains(&workspace.into())
23-
&& !CiEnv::is_ci()
24-
// If the directory is empty, we can consider it as an uninitialized submodule.
25-
&& read_dir(root.join(workspace)).unwrap().next().is_none()
26-
{
16+
for &(workspace, _, _, submodules) in crate::deps::WORKSPACES {
17+
if crate::deps::has_missing_submodule(root, submodules) {
2718
continue;
2819
}
2920

0 commit comments

Comments
 (0)