Skip to content

Commit 8cebd4e

Browse files
committed
tidy: skip submodules if not present for non-CI environments
Signed-off-by: onur-ozkan <[email protected]>
1 parent dd50e18 commit 8cebd4e

File tree

4 files changed

+36
-11
lines changed

4 files changed

+36
-11
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -5697,6 +5697,7 @@ dependencies = [
56975697
name = "tidy"
56985698
version = "0.1.0"
56995699
dependencies = [
5700+
"build_helper",
57005701
"cargo_metadata 0.15.4",
57015702
"ignore",
57025703
"miropt-test-tools",

src/tools/tidy/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition = "2021"
55
autobins = false
66

77
[dependencies]
8+
build_helper = { path = "../build_helper" }
89
cargo_metadata = "0.15"
910
regex = "1"
1011
miropt-test-tools = { path = "../miropt-test-tools" }

src/tools/tidy/src/deps.rs

+25-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Checks the licenses of third-party dependencies.
22
3+
use build_helper::ci::CiEnv;
34
use cargo_metadata::{Metadata, Package, PackageId};
45
use std::collections::HashSet;
56
use std::path::Path;
@@ -46,30 +47,37 @@ type ExceptionList = &'static [(&'static str, &'static str)];
4647
/// * Optionally a tuple of:
4748
/// * A list of crates for which dependencies need to be explicitly allowed.
4849
/// * The list of allowed dependencies.
50+
/// * An indication of whether it is a submodule or not.
4951
// FIXME auto detect all cargo workspaces
50-
pub(crate) const WORKSPACES: &[(&str, ExceptionList, Option<(&[&str], &[&str])>)] = &[
52+
pub(crate) const WORKSPACES: &[(&str, ExceptionList, Option<(&[&str], &[&str])>, bool)] = &[
5153
// The root workspace has to be first for check_rustfix to work.
52-
(".", EXCEPTIONS, Some((&["rustc-main"], PERMITTED_RUSTC_DEPENDENCIES))),
54+
(".", EXCEPTIONS, Some((&["rustc-main"], PERMITTED_RUSTC_DEPENDENCIES)), false),
5355
// Outside of the alphabetical section because rustfmt formats it using multiple lines.
5456
(
5557
"compiler/rustc_codegen_cranelift",
5658
EXCEPTIONS_CRANELIFT,
5759
Some((&["rustc_codegen_cranelift"], PERMITTED_CRANELIFT_DEPENDENCIES)),
60+
false,
5861
),
5962
// tidy-alphabetical-start
60-
("compiler/rustc_codegen_gcc", EXCEPTIONS_GCC, None),
63+
("compiler/rustc_codegen_gcc", EXCEPTIONS_GCC, None, false),
6164
//("library/backtrace", &[], None), // FIXME uncomment once rust-lang/backtrace#562 has been synced back to the rust repo
6265
//("library/portable-simd", &[], None), // FIXME uncomment once rust-lang/portable-simd#363 has been synced back to the rust repo
6366
//("library/stdarch", EXCEPTIONS_STDARCH, None), // FIXME uncomment once rust-lang/stdarch#1462 has been synced back to the rust repo
64-
("src/bootstrap", EXCEPTIONS_BOOTSTRAP, None),
65-
("src/ci/docker/host-x86_64/test-various/uefi_qemu_test", EXCEPTIONS_UEFI_QEMU_TEST, None),
67+
("src/bootstrap", EXCEPTIONS_BOOTSTRAP, None, false),
68+
(
69+
"src/ci/docker/host-x86_64/test-various/uefi_qemu_test",
70+
EXCEPTIONS_UEFI_QEMU_TEST,
71+
None,
72+
false,
73+
),
6674
//("src/etc/test-float-parse", &[], None), // FIXME uncomment once all deps are vendored
67-
("src/tools/cargo", EXCEPTIONS_CARGO, None),
75+
("src/tools/cargo", EXCEPTIONS_CARGO, None, false),
6876
//("src/tools/miri/test-cargo-miri", &[], None), // FIXME uncomment once all deps are vendored
6977
//("src/tools/miri/test_dependencies", &[], None), // FIXME uncomment once all deps are vendored
70-
("src/tools/rust-analyzer", EXCEPTIONS_RUST_ANALYZER, None),
71-
("src/tools/rustc-perf", EXCEPTIONS_RUSTC_PERF, None),
72-
("src/tools/x", &[], None),
78+
("src/tools/rust-analyzer", EXCEPTIONS_RUST_ANALYZER, None, false),
79+
("src/tools/rustc-perf", EXCEPTIONS_RUSTC_PERF, None, true),
80+
("src/tools/x", &[], None, false),
7381
// tidy-alphabetical-end
7482
];
7583

@@ -514,8 +522,15 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[
514522
pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
515523
let mut checked_runtime_licenses = false;
516524

517-
for &(workspace, exceptions, permitted_deps) in WORKSPACES {
525+
for &(workspace, exceptions, permitted_deps, is_submodule) in WORKSPACES {
518526
if !root.join(workspace).join("Cargo.lock").exists() {
527+
// Skip if it's a submodule, not checked out, and not in a CI environment.
528+
//
529+
// This prevents enforcing developers to fetch submodules for tidy.
530+
if is_submodule && !root.join(workspace).join(".git").exists() && !CiEnv::is_ci() {
531+
continue;
532+
}
533+
519534
tidy_error!(bad, "the `{workspace}` workspace doesn't have a Cargo.lock");
520535
continue;
521536
}

src/tools/tidy/src/extdeps.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Check for external package sources. Allow only vendorable packages.
22
3+
use build_helper::ci::CiEnv;
34
use std::fs;
45
use std::path::Path;
56

@@ -13,11 +14,18 @@ const ALLOWED_SOURCES: &[&str] = &[
1314
/// Checks for external package sources. `root` is the path to the directory that contains the
1415
/// workspace `Cargo.toml`.
1516
pub fn check(root: &Path, bad: &mut bool) {
16-
for &(workspace, _, _) in crate::deps::WORKSPACES {
17+
for &(workspace, _, _, is_submodule) in crate::deps::WORKSPACES {
1718
// FIXME check other workspaces too
1819
// `Cargo.lock` of rust.
1920
let path = root.join(workspace).join("Cargo.lock");
2021

22+
// Skip if it's a submodule, not checked out, and not in a CI environment.
23+
//
24+
// This prevents enforcing developers to fetch submodules for tidy.
25+
if is_submodule && !root.join(workspace).join(".git").exists() && !CiEnv::is_ci() {
26+
continue;
27+
}
28+
2129
if !path.exists() {
2230
tidy_error!(bad, "the `{workspace}` workspace doesn't have a Cargo.lock");
2331
continue;

0 commit comments

Comments
 (0)