|
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;
|
5 | 6 | use std::path::Path;
|
@@ -46,30 +47,37 @@ type ExceptionList = &'static [(&'static str, &'static str)];
|
46 | 47 | /// * Optionally a tuple of:
|
47 | 48 | /// * A list of crates for which dependencies need to be explicitly allowed.
|
48 | 49 | /// * The list of allowed dependencies.
|
| 50 | +/// * An indication of whether it is a submodule or not. |
49 | 51 | // 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)] = &[ |
51 | 53 | // 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), |
53 | 55 | // Outside of the alphabetical section because rustfmt formats it using multiple lines.
|
54 | 56 | (
|
55 | 57 | "compiler/rustc_codegen_cranelift",
|
56 | 58 | EXCEPTIONS_CRANELIFT,
|
57 | 59 | Some((&["rustc_codegen_cranelift"], PERMITTED_CRANELIFT_DEPENDENCIES)),
|
| 60 | + false, |
58 | 61 | ),
|
59 | 62 | // tidy-alphabetical-start
|
60 |
| - ("compiler/rustc_codegen_gcc", EXCEPTIONS_GCC, None), |
| 63 | + ("compiler/rustc_codegen_gcc", EXCEPTIONS_GCC, None, false), |
61 | 64 | //("library/backtrace", &[], None), // FIXME uncomment once rust-lang/backtrace#562 has been synced back to the rust repo
|
62 | 65 | //("library/portable-simd", &[], None), // FIXME uncomment once rust-lang/portable-simd#363 has been synced back to the rust repo
|
63 | 66 | //("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 | + ), |
66 | 74 | //("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), |
68 | 76 | //("src/tools/miri/test-cargo-miri", &[], None), // FIXME uncomment once all deps are vendored
|
69 | 77 | //("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), |
73 | 81 | // tidy-alphabetical-end
|
74 | 82 | ];
|
75 | 83 |
|
@@ -514,8 +522,15 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[
|
514 | 522 | pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
|
515 | 523 | let mut checked_runtime_licenses = false;
|
516 | 524 |
|
517 |
| - for &(workspace, exceptions, permitted_deps) in WORKSPACES { |
| 525 | + for &(workspace, exceptions, permitted_deps, is_submodule) in WORKSPACES { |
518 | 526 | 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 | + |
519 | 534 | tidy_error!(bad, "the `{workspace}` workspace doesn't have a Cargo.lock");
|
520 | 535 | continue;
|
521 | 536 | }
|
|
0 commit comments