Skip to content

Commit

Permalink
Auto merge of rust-lang#128123 - ehuss:tidy-rustbook-submodule, r=Mar…
Browse files Browse the repository at this point in the history
…k-Simulacrum

Fix tidy check if book submodule is not checked out

This fixes tidy in a checkout without submodules. rust-lang#127786 added a new cargo workspace, and the corresponding checks in tidy. There is code in tidy to skip those checks if the submodule is checked out, but that code assumed the root of the workspace was also the root of the submodule. With `rustbook`, the root is `src/tools/rustbook`, but the submodules it needs are in the `src/doc` directory.

The solution here is to explicitly list which submodules are needed instead of assuming the root is also the submodule.
  • Loading branch information
bors committed Jul 24, 2024
2 parents f751af4 + e8ef886 commit 42103d6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 33 deletions.
47 changes: 26 additions & 21 deletions src/tools/tidy/src/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,33 @@ type ExceptionList = &'static [(&'static str, &'static str)];
/// * Optionally a tuple of:
/// * A list of crates for which dependencies need to be explicitly allowed.
/// * The list of allowed dependencies.
/// * Submodules required for the workspace.
// FIXME auto detect all cargo workspaces
pub(crate) const WORKSPACES: &[(&str, ExceptionList, Option<(&[&str], &[&str])>)] = &[
pub(crate) const WORKSPACES: &[(&str, ExceptionList, Option<(&[&str], &[&str])>, &[&str])] = &[
// The root workspace has to be first for check_rustfix to work.
(".", EXCEPTIONS, Some((&["rustc-main"], PERMITTED_RUSTC_DEPENDENCIES))),
(".", EXCEPTIONS, Some((&["rustc-main"], PERMITTED_RUSTC_DEPENDENCIES)), &[]),
// Outside of the alphabetical section because rustfmt formats it using multiple lines.
(
"compiler/rustc_codegen_cranelift",
EXCEPTIONS_CRANELIFT,
Some((&["rustc_codegen_cranelift"], PERMITTED_CRANELIFT_DEPENDENCIES)),
&[],
),
// tidy-alphabetical-start
("compiler/rustc_codegen_gcc", EXCEPTIONS_GCC, None),
("compiler/rustc_codegen_gcc", EXCEPTIONS_GCC, None, &[]),
//("library/backtrace", &[], None), // FIXME uncomment once rust-lang/backtrace#562 has been synced back to the rust repo
//("library/portable-simd", &[], None), // FIXME uncomment once rust-lang/portable-simd#363 has been synced back to the rust repo
//("library/stdarch", EXCEPTIONS_STDARCH, None), // FIXME uncomment once rust-lang/stdarch#1462 has been synced back to the rust repo
("src/bootstrap", EXCEPTIONS_BOOTSTRAP, None),
("src/ci/docker/host-x86_64/test-various/uefi_qemu_test", EXCEPTIONS_UEFI_QEMU_TEST, None),
("src/etc/test-float-parse", EXCEPTIONS, None),
("src/tools/cargo", EXCEPTIONS_CARGO, None),
("src/bootstrap", EXCEPTIONS_BOOTSTRAP, None, &[]),
("src/ci/docker/host-x86_64/test-various/uefi_qemu_test", EXCEPTIONS_UEFI_QEMU_TEST, None, &[]),
("src/etc/test-float-parse", EXCEPTIONS, None, &[]),
("src/tools/cargo", EXCEPTIONS_CARGO, None, &["src/tools/cargo"]),
//("src/tools/miri/test-cargo-miri", &[], None), // FIXME uncomment once all deps are vendored
//("src/tools/miri/test_dependencies", &[], None), // FIXME uncomment once all deps are vendored
("src/tools/rust-analyzer", EXCEPTIONS_RUST_ANALYZER, None),
("src/tools/rustbook", EXCEPTIONS_RUSTBOOK, None),
("src/tools/rustc-perf", EXCEPTIONS_RUSTC_PERF, None),
("src/tools/x", &[], None),
("src/tools/rust-analyzer", EXCEPTIONS_RUST_ANALYZER, None, &[]),
("src/tools/rustbook", EXCEPTIONS_RUSTBOOK, None, &["src/doc/book"]),
("src/tools/rustc-perf", EXCEPTIONS_RUSTC_PERF, None, &["src/tools/rustc-perf"]),
("src/tools/x", &[], None, &[]),
// tidy-alphabetical-end
];

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

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

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

/// Used to skip a check if a submodule is not checked out, and not in a CI environment.
///
/// This helps prevent enforcing developers to fetch submodules for tidy.
pub fn has_missing_submodule(root: &Path, submodules: &[&str]) -> bool {
!CiEnv::is_ci()
&& submodules.iter().any(|submodule| {
// If the directory is empty, we can consider it as an uninitialized submodule.
read_dir(root.join(submodule)).unwrap().next().is_none()
})
}

/// Check that all licenses of runtime dependencies are in the valid list in `LICENSES`.
///
/// Unlike for tools we don't allow exceptions to the `LICENSES` list for the runtime with the sole
Expand Down
15 changes: 3 additions & 12 deletions src/tools/tidy/src/extdeps.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Check for external package sources. Allow only vendorable packages.

use build_helper::ci::CiEnv;
use std::fs::{self, read_dir};
use std::fs;
use std::path::Path;

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

Expand Down

0 comments on commit 42103d6

Please sign in to comment.