Skip to content

Commit d1a877a

Browse files
committed
Improve tidy error on dependency license exceptions
1 parent 0b807fc commit d1a877a

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

src/tools/tidy/src/deps.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ pub fn check(root: &Path, cargo: &Path, bless: bool, bad: &mut bool) {
599599
.other_options(vec!["--locked".to_owned()]);
600600
let metadata = t!(cmd.exec());
601601

602-
check_license_exceptions(&metadata, exceptions, bad);
602+
check_license_exceptions(&metadata, workspace, exceptions, bad);
603603
if let Some((crates, permitted_deps)) = permitted_deps {
604604
check_permitted_dependencies(&metadata, workspace, permitted_deps, crates, bad);
605605
}
@@ -730,14 +730,19 @@ fn check_runtime_license_exceptions(metadata: &Metadata, bad: &mut bool) {
730730
/// Check that all licenses of tool dependencies are in the valid list in `LICENSES`.
731731
///
732732
/// Packages listed in `exceptions` are allowed for tools.
733-
fn check_license_exceptions(metadata: &Metadata, exceptions: &[(&str, &str)], bad: &mut bool) {
733+
fn check_license_exceptions(
734+
metadata: &Metadata,
735+
workspace: &str,
736+
exceptions: &[(&str, &str)],
737+
bad: &mut bool,
738+
) {
734739
// Validate the EXCEPTIONS list hasn't changed.
735740
for (name, license) in exceptions {
736741
// Check that the package actually exists.
737742
if !metadata.packages.iter().any(|p| *p.name == *name) {
738743
tidy_error!(
739744
bad,
740-
"could not find exception package `{}`\n\
745+
"could not find exception package `{}` in workspace `{workspace}`\n\
741746
Remove from EXCEPTIONS list if it is no longer used.",
742747
name
743748
);
@@ -753,13 +758,15 @@ fn check_license_exceptions(metadata: &Metadata, exceptions: &[(&str, &str)], ba
753758
}
754759
tidy_error!(
755760
bad,
756-
"dependency exception `{}` does not declare a license expression",
761+
"dependency exception `{}` in workspace `{workspace}` does not declare a license expression",
757762
pkg.id
758763
);
759764
}
760765
Some(pkg_license) => {
761766
if pkg_license.as_str() != *license {
762-
println!("dependency exception `{name}` license has changed");
767+
println!(
768+
"dependency exception `{name}` license in workspace `{workspace}` has changed"
769+
);
763770
println!(" previously `{license}` now `{pkg_license}`");
764771
println!(" update EXCEPTIONS for the new license");
765772
*bad = true;
@@ -783,12 +790,21 @@ fn check_license_exceptions(metadata: &Metadata, exceptions: &[(&str, &str)], ba
783790
let license = match &pkg.license {
784791
Some(license) => license,
785792
None => {
786-
tidy_error!(bad, "dependency `{}` does not define a license expression", pkg.id);
793+
tidy_error!(
794+
bad,
795+
"dependency `{}` in workspace `{workspace}` does not define a license expression",
796+
pkg.id
797+
);
787798
continue;
788799
}
789800
};
790801
if !LICENSES.contains(&license.as_str()) {
791-
tidy_error!(bad, "invalid license `{}` in `{}`", license, pkg.id);
802+
tidy_error!(
803+
bad,
804+
"invalid license `{}` for package `{}` in workspace `{workspace}`",
805+
license,
806+
pkg.id
807+
);
792808
}
793809
}
794810
}

0 commit comments

Comments
 (0)