Skip to content

Commit 91e1ef1

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

File tree

4 files changed

+46
-12
lines changed

4 files changed

+46
-12
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

+30-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
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;
6+
use std::fs::read_dir;
57
use std::path::Path;
68

79
/// These are licenses that are allowed for all crates, including the runtime,
@@ -46,30 +48,37 @@ type ExceptionList = &'static [(&'static str, &'static str)];
4648
/// * Optionally a tuple of:
4749
/// * A list of crates for which dependencies need to be explicitly allowed.
4850
/// * The list of allowed dependencies.
51+
/// * An indication of whether it is a submodule or not.
4952
// FIXME auto detect all cargo workspaces
50-
pub(crate) const WORKSPACES: &[(&str, ExceptionList, Option<(&[&str], &[&str])>)] = &[
53+
pub(crate) const WORKSPACES: &[(&str, ExceptionList, Option<(&[&str], &[&str])>, bool)] = &[
5154
// The root workspace has to be first for check_rustfix to work.
52-
(".", EXCEPTIONS, Some((&["rustc-main"], PERMITTED_RUSTC_DEPENDENCIES))),
55+
(".", EXCEPTIONS, Some((&["rustc-main"], PERMITTED_RUSTC_DEPENDENCIES)), false),
5356
// Outside of the alphabetical section because rustfmt formats it using multiple lines.
5457
(
5558
"compiler/rustc_codegen_cranelift",
5659
EXCEPTIONS_CRANELIFT,
5760
Some((&["rustc_codegen_cranelift"], PERMITTED_CRANELIFT_DEPENDENCIES)),
61+
false,
5862
),
5963
// tidy-alphabetical-start
60-
("compiler/rustc_codegen_gcc", EXCEPTIONS_GCC, None),
64+
("compiler/rustc_codegen_gcc", EXCEPTIONS_GCC, None, false),
6165
//("library/backtrace", &[], None), // FIXME uncomment once rust-lang/backtrace#562 has been synced back to the rust repo
6266
//("library/portable-simd", &[], None), // FIXME uncomment once rust-lang/portable-simd#363 has been synced back to the rust repo
6367
//("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),
68+
("src/bootstrap", EXCEPTIONS_BOOTSTRAP, None, false),
69+
(
70+
"src/ci/docker/host-x86_64/test-various/uefi_qemu_test",
71+
EXCEPTIONS_UEFI_QEMU_TEST,
72+
None,
73+
false,
74+
),
6675
//("src/etc/test-float-parse", &[], None), // FIXME uncomment once all deps are vendored
67-
("src/tools/cargo", EXCEPTIONS_CARGO, None),
76+
("src/tools/cargo", EXCEPTIONS_CARGO, None, false),
6877
//("src/tools/miri/test-cargo-miri", &[], None), // FIXME uncomment once all deps are vendored
6978
//("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),
79+
("src/tools/rust-analyzer", EXCEPTIONS_RUST_ANALYZER, None, false),
80+
("src/tools/rustc-perf", EXCEPTIONS_RUSTC_PERF, None, true),
81+
("src/tools/x", &[], None, false),
7382
// tidy-alphabetical-end
7483
];
7584

@@ -514,7 +523,18 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[
514523
pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
515524
let mut checked_runtime_licenses = false;
516525

517-
for &(workspace, exceptions, permitted_deps) in WORKSPACES {
526+
for &(workspace, exceptions, permitted_deps, is_submodule) in WORKSPACES {
527+
// Skip if it's a submodule, not in a CI environment, and not initialized.
528+
//
529+
// This prevents enforcing developers to fetch submodules for tidy.
530+
if is_submodule
531+
&& !CiEnv::is_ci()
532+
// If the directory is empty, we can consider it as an uninitialized submodule.
533+
&& read_dir(root.join(workspace)).unwrap().next().is_none()
534+
{
535+
continue;
536+
}
537+
518538
if !root.join(workspace).join("Cargo.lock").exists() {
519539
tidy_error!(bad, "the `{workspace}` workspace doesn't have a Cargo.lock");
520540
continue;

src/tools/tidy/src/extdeps.rs

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

67
/// List of allowed sources for packages.
@@ -13,7 +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 {
18+
// Skip if it's a submodule, not in a CI environment, and not initialized.
19+
//
20+
// This prevents enforcing developers to fetch submodules for tidy.
21+
if is_submodule
22+
&& !CiEnv::is_ci()
23+
// If the directory is empty, we can consider it as an uninitialized submodule.
24+
&& read_dir(root.join(workspace)).unwrap().next().is_none()
25+
{
26+
continue;
27+
}
28+
1729
// FIXME check other workspaces too
1830
// `Cargo.lock` of rust.
1931
let path = root.join(workspace).join("Cargo.lock");

0 commit comments

Comments
 (0)