From fb2a52812dc752c666c1e7dbd874cff9da52adbf Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Mon, 10 Jun 2024 17:07:19 +0300 Subject: [PATCH] tidy: skip submodules if not present for non-CI environments Signed-off-by: onur-ozkan --- Cargo.lock | 1 + src/tools/tidy/Cargo.toml | 1 + src/tools/tidy/src/deps.rs | 35 +++++++++++++++++++++++++---------- src/tools/tidy/src/extdeps.rs | 10 +++++++++- 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 58d95f927bf95..a9fdf8926ee03 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5697,6 +5697,7 @@ dependencies = [ name = "tidy" version = "0.1.0" dependencies = [ + "build_helper", "cargo_metadata 0.15.4", "ignore", "miropt-test-tools", diff --git a/src/tools/tidy/Cargo.toml b/src/tools/tidy/Cargo.toml index 63963b0bd1ced..c5204a9fee728 100644 --- a/src/tools/tidy/Cargo.toml +++ b/src/tools/tidy/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" autobins = false [dependencies] +build_helper = { path = "../build_helper" } cargo_metadata = "0.15" regex = "1" miropt-test-tools = { path = "../miropt-test-tools" } diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index 2dd3d17f9e3e7..dde237697ff16 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -1,5 +1,6 @@ //! Checks the licenses of third-party dependencies. +use build_helper::ci::CiEnv; use cargo_metadata::{Metadata, Package, PackageId}; use std::collections::HashSet; use std::path::Path; @@ -46,30 +47,37 @@ 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. +/// * An indication of whether it is a submodule or not. // FIXME auto detect all cargo workspaces -pub(crate) const WORKSPACES: &[(&str, ExceptionList, Option<(&[&str], &[&str])>)] = &[ +pub(crate) const WORKSPACES: &[(&str, ExceptionList, Option<(&[&str], &[&str])>, bool)] = &[ // 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)), false), // 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)), + false, ), // tidy-alphabetical-start - ("compiler/rustc_codegen_gcc", EXCEPTIONS_GCC, None), + ("compiler/rustc_codegen_gcc", EXCEPTIONS_GCC, None, false), //("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/bootstrap", EXCEPTIONS_BOOTSTRAP, None, false), + ( + "src/ci/docker/host-x86_64/test-various/uefi_qemu_test", + EXCEPTIONS_UEFI_QEMU_TEST, + None, + false, + ), //("src/etc/test-float-parse", &[], None), // FIXME uncomment once all deps are vendored - ("src/tools/cargo", EXCEPTIONS_CARGO, None), + ("src/tools/cargo", EXCEPTIONS_CARGO, None, false), //("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/rustc-perf", EXCEPTIONS_RUSTC_PERF, None), - ("src/tools/x", &[], None), + ("src/tools/rust-analyzer", EXCEPTIONS_RUST_ANALYZER, None, false), + ("src/tools/rustc-perf", EXCEPTIONS_RUSTC_PERF, None, true), + ("src/tools/x", &[], None, false), // tidy-alphabetical-end ]; @@ -514,8 +522,15 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[ pub fn check(root: &Path, cargo: &Path, bad: &mut bool) { let mut checked_runtime_licenses = false; - for &(workspace, exceptions, permitted_deps) in WORKSPACES { + for &(workspace, exceptions, permitted_deps, is_submodule) in WORKSPACES { if !root.join(workspace).join("Cargo.lock").exists() { + // Skip if it's a submodule, not initialized, and not in a CI environment. + // + // This prevents enforcing developers to fetch submodules for tidy. + if is_submodule && !root.join(workspace).join(".git").exists() && !CiEnv::is_ci() { + continue; + } + tidy_error!(bad, "the `{workspace}` workspace doesn't have a Cargo.lock"); continue; } diff --git a/src/tools/tidy/src/extdeps.rs b/src/tools/tidy/src/extdeps.rs index 2118de5f20411..c1eab232b3ca8 100644 --- a/src/tools/tidy/src/extdeps.rs +++ b/src/tools/tidy/src/extdeps.rs @@ -1,5 +1,6 @@ //! Check for external package sources. Allow only vendorable packages. +use build_helper::ci::CiEnv; use std::fs; use std::path::Path; @@ -13,11 +14,18 @@ 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) { - for &(workspace, _, _) in crate::deps::WORKSPACES { + for &(workspace, _, _, is_submodule) in crate::deps::WORKSPACES { // FIXME check other workspaces too // `Cargo.lock` of rust. let path = root.join(workspace).join("Cargo.lock"); + // Skip if it's a submodule, not initialized, and not in a CI environment. + // + // This prevents enforcing developers to fetch submodules for tidy. + if is_submodule && !root.join(workspace).join(".git").exists() && !CiEnv::is_ci() { + continue; + } + if !path.exists() { tidy_error!(bad, "the `{workspace}` workspace doesn't have a Cargo.lock"); continue;