Skip to content

Commit

Permalink
tidy: skip submodules if not present for non-CI environments
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <[email protected]>
  • Loading branch information
onur-ozkan committed Jun 10, 2024
1 parent dd50e18 commit fb2a528
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5697,6 +5697,7 @@ dependencies = [
name = "tidy"
version = "0.1.0"
dependencies = [
"build_helper",
"cargo_metadata 0.15.4",
"ignore",
"miropt-test-tools",
Expand Down
1 change: 1 addition & 0 deletions src/tools/tidy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
35 changes: 25 additions & 10 deletions src/tools/tidy/src/deps.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
];

Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 9 additions & 1 deletion src/tools/tidy/src/extdeps.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
Expand Down

0 comments on commit fb2a528

Please sign in to comment.