|
1 | 1 | //! Checks the licenses of third-party dependencies.
|
2 | 2 |
|
| 3 | +use build_helper::ci::CiEnv; |
3 | 4 | use cargo_metadata::{Metadata, Package, PackageId};
|
4 | 5 | use std::collections::HashSet;
|
| 6 | +use std::fs::read_dir; |
5 | 7 | use std::path::Path;
|
6 | 8 |
|
7 | 9 | /// These are licenses that are allowed for all crates, including the runtime,
|
@@ -46,30 +48,37 @@ type ExceptionList = &'static [(&'static str, &'static str)];
|
46 | 48 | /// * Optionally a tuple of:
|
47 | 49 | /// * A list of crates for which dependencies need to be explicitly allowed.
|
48 | 50 | /// * The list of allowed dependencies.
|
| 51 | +/// * An indication of whether it is a submodule or not. |
49 | 52 | // 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)] = &[ |
51 | 54 | // 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), |
53 | 56 | // Outside of the alphabetical section because rustfmt formats it using multiple lines.
|
54 | 57 | (
|
55 | 58 | "compiler/rustc_codegen_cranelift",
|
56 | 59 | EXCEPTIONS_CRANELIFT,
|
57 | 60 | Some((&["rustc_codegen_cranelift"], PERMITTED_CRANELIFT_DEPENDENCIES)),
|
| 61 | + false, |
58 | 62 | ),
|
59 | 63 | // tidy-alphabetical-start
|
60 |
| - ("compiler/rustc_codegen_gcc", EXCEPTIONS_GCC, None), |
| 64 | + ("compiler/rustc_codegen_gcc", EXCEPTIONS_GCC, None, false), |
61 | 65 | //("library/backtrace", &[], None), // FIXME uncomment once rust-lang/backtrace#562 has been synced back to the rust repo
|
62 | 66 | //("library/portable-simd", &[], None), // FIXME uncomment once rust-lang/portable-simd#363 has been synced back to the rust repo
|
63 | 67 | //("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 | + ), |
66 | 75 | //("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), |
68 | 77 | //("src/tools/miri/test-cargo-miri", &[], None), // FIXME uncomment once all deps are vendored
|
69 | 78 | //("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), |
73 | 82 | // tidy-alphabetical-end
|
74 | 83 | ];
|
75 | 84 |
|
@@ -514,7 +523,18 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[
|
514 | 523 | pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
|
515 | 524 | let mut checked_runtime_licenses = false;
|
516 | 525 |
|
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 | + |
518 | 538 | if !root.join(workspace).join("Cargo.lock").exists() {
|
519 | 539 | tidy_error!(bad, "the `{workspace}` workspace doesn't have a Cargo.lock");
|
520 | 540 | continue;
|
|
0 commit comments