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 <work@onurozkan.dev>
  • Loading branch information
onur-ozkan committed Jun 10, 2024
1 parent dd50e18 commit 91e1ef1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 12 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
40 changes: 30 additions & 10 deletions src/tools/tidy/src/deps.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! Checks the licenses of third-party dependencies.

use build_helper::ci::CiEnv;
use cargo_metadata::{Metadata, Package, PackageId};
use std::collections::HashSet;
use std::fs::read_dir;
use std::path::Path;

/// These are licenses that are allowed for all crates, including the runtime,
Expand Down Expand Up @@ -46,30 +48,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,7 +523,18 @@ 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 {
// Skip if it's a submodule, not in a CI environment, and not initialized.
//
// This prevents enforcing developers to fetch submodules for tidy.
if is_submodule
&& !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()
{
continue;
}

if !root.join(workspace).join("Cargo.lock").exists() {
tidy_error!(bad, "the `{workspace}` workspace doesn't have a Cargo.lock");
continue;
Expand Down
16 changes: 14 additions & 2 deletions src/tools/tidy/src/extdeps.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Check for external package sources. Allow only vendorable packages.

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

/// List of allowed sources for packages.
Expand All @@ -13,7 +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 {
// Skip if it's a submodule, not in a CI environment, and not initialized.
//
// This prevents enforcing developers to fetch submodules for tidy.
if is_submodule
&& !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()
{
continue;
}

// FIXME check other workspaces too
// `Cargo.lock` of rust.
let path = root.join(workspace).join("Cargo.lock");
Expand Down

0 comments on commit 91e1ef1

Please sign in to comment.