@@ -9,6 +9,8 @@ use build_helper::ci::CiEnv;
99use cargo_metadata:: semver:: Version ;
1010use cargo_metadata:: { Metadata , Package , PackageId } ;
1111
12+ use crate :: diagnostics:: { CheckId , DiagCtx , RunningCheck } ;
13+
1214#[ path = "../../../bootstrap/src/utils/proc_macro_deps.rs" ]
1315mod proc_macro_deps;
1416
@@ -661,18 +663,20 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[
661663///
662664/// `root` is path to the directory with the root `Cargo.toml` (for the workspace). `cargo` is path
663665/// to the cargo executable.
664- pub fn check ( root : & Path , cargo : & Path , bless : bool , bad : & mut bool ) {
666+ pub fn check ( root : & Path , cargo : & Path , bless : bool , diag_ctx : DiagCtx ) {
667+ let mut check = diag_ctx. start_check ( CheckId :: new ( "deps" ) . path ( root) ) ;
668+
665669 let mut checked_runtime_licenses = false ;
666670
667- check_proc_macro_dep_list ( root, cargo, bless, bad ) ;
671+ check_proc_macro_dep_list ( root, cargo, bless, & mut check ) ;
668672
669673 for & WorkspaceInfo { path, exceptions, crates_and_deps, submodules } in WORKSPACES {
670674 if has_missing_submodule ( root, submodules) {
671675 continue ;
672676 }
673677
674678 if !root. join ( path) . join ( "Cargo.lock" ) . exists ( ) {
675- tidy_error ! ( bad , "the `{path}` workspace doesn't have a Cargo.lock" ) ;
679+ check . error ( format ! ( "the `{path}` workspace doesn't have a Cargo.lock" ) ) ;
676680 continue ;
677681 }
678682
@@ -683,16 +687,23 @@ pub fn check(root: &Path, cargo: &Path, bless: bool, bad: &mut bool) {
683687 . other_options ( vec ! [ "--locked" . to_owned( ) ] ) ;
684688 let metadata = t ! ( cmd. exec( ) ) ;
685689
686- check_license_exceptions ( & metadata, path, exceptions, bad ) ;
690+ check_license_exceptions ( & metadata, path, exceptions, & mut check ) ;
687691 if let Some ( ( crates, permitted_deps, location) ) = crates_and_deps {
688692 let descr = crates. get ( 0 ) . unwrap_or ( & path) ;
689- check_permitted_dependencies ( & metadata, descr, permitted_deps, crates, location, bad) ;
693+ check_permitted_dependencies (
694+ & metadata,
695+ descr,
696+ permitted_deps,
697+ crates,
698+ location,
699+ & mut check,
700+ ) ;
690701 }
691702
692703 if path == "library" {
693- check_runtime_license_exceptions ( & metadata, bad ) ;
694- check_runtime_no_duplicate_dependencies ( & metadata, bad ) ;
695- check_runtime_no_proc_macros ( & metadata, bad ) ;
704+ check_runtime_license_exceptions ( & metadata, & mut check ) ;
705+ check_runtime_no_duplicate_dependencies ( & metadata, & mut check ) ;
706+ check_runtime_no_proc_macros ( & metadata, & mut check ) ;
696707 checked_runtime_licenses = true ;
697708 }
698709 }
@@ -703,7 +714,7 @@ pub fn check(root: &Path, cargo: &Path, bless: bool, bad: &mut bool) {
703714}
704715
705716/// Ensure the list of proc-macro crate transitive dependencies is up to date
706- fn check_proc_macro_dep_list ( root : & Path , cargo : & Path , bless : bool , bad : & mut bool ) {
717+ fn check_proc_macro_dep_list ( root : & Path , cargo : & Path , bless : bool , check : & mut RunningCheck ) {
707718 let mut cmd = cargo_metadata:: MetadataCommand :: new ( ) ;
708719 cmd. cargo_path ( cargo)
709720 . manifest_path ( root. join ( "Cargo.toml" ) )
@@ -750,22 +761,22 @@ pub static CRATES: &[&str] = &[
750761 )
751762 . unwrap ( ) ;
752763 } else {
753- let old_bad = * bad ;
764+ let mut error_found = false ;
754765
755766 for missing in proc_macro_deps. difference ( & expected) {
756- tidy_error ! (
757- bad ,
767+ error_found = true ;
768+ check . error ( format ! (
758769 "proc-macro crate dependency `{missing}` is not registered in `src/bootstrap/src/utils/proc_macro_deps.rs`" ,
759- ) ;
770+ ) ) ;
760771 }
761772 for extra in expected. difference ( & proc_macro_deps) {
762- tidy_error ! (
763- bad ,
773+ error_found = true ;
774+ check . error ( format ! (
764775 "`{extra}` is registered in `src/bootstrap/src/utils/proc_macro_deps.rs`, but is not a proc-macro crate dependency" ,
765- ) ;
776+ ) ) ;
766777 }
767- if * bad != old_bad {
768- eprintln ! ( "Run `./x.py test tidy --bless` to regenerate the list" ) ;
778+ if error_found {
779+ check . message ( "Run `./x.py test tidy --bless` to regenerate the list" ) ;
769780 }
770781 }
771782}
@@ -787,7 +798,7 @@ pub fn has_missing_submodule(root: &Path, submodules: &[&str]) -> bool {
787798///
788799/// Unlike for tools we don't allow exceptions to the `LICENSES` list for the runtime with the sole
789800/// exception of `fortanix-sgx-abi` which is only used on x86_64-fortanix-unknown-sgx.
790- fn check_runtime_license_exceptions ( metadata : & Metadata , bad : & mut bool ) {
801+ fn check_runtime_license_exceptions ( metadata : & Metadata , check : & mut RunningCheck ) {
791802 for pkg in & metadata. packages {
792803 if pkg. source . is_none ( ) {
793804 // No need to check local packages.
@@ -796,7 +807,8 @@ fn check_runtime_license_exceptions(metadata: &Metadata, bad: &mut bool) {
796807 let license = match & pkg. license {
797808 Some ( license) => license,
798809 None => {
799- tidy_error ! ( bad, "dependency `{}` does not define a license expression" , pkg. id) ;
810+ check
811+ . error ( format ! ( "dependency `{}` does not define a license expression" , pkg. id) ) ;
800812 continue ;
801813 }
802814 } ;
@@ -809,7 +821,7 @@ fn check_runtime_license_exceptions(metadata: &Metadata, bad: &mut bool) {
809821 continue ;
810822 }
811823
812- tidy_error ! ( bad , "invalid license `{}` in `{}`" , license, pkg. id) ;
824+ check . error ( format ! ( "invalid license `{}` in `{}`" , license, pkg. id) ) ;
813825 }
814826 }
815827}
@@ -821,37 +833,32 @@ fn check_license_exceptions(
821833 metadata : & Metadata ,
822834 workspace : & str ,
823835 exceptions : & [ ( & str , & str ) ] ,
824- bad : & mut bool ,
836+ check : & mut RunningCheck ,
825837) {
826838 // Validate the EXCEPTIONS list hasn't changed.
827839 for ( name, license) in exceptions {
828840 // Check that the package actually exists.
829841 if !metadata. packages . iter ( ) . any ( |p| * p. name == * name) {
830- tidy_error ! (
831- bad,
832- "could not find exception package `{}` in workspace `{workspace}`\n \
842+ check. error ( format ! (
843+ "could not find exception package `{name}` in workspace `{workspace}`\n \
833844 Remove from EXCEPTIONS list if it is no longer used.",
834- name
835- ) ;
845+ ) ) ;
836846 }
837847 // Check that the license hasn't changed.
838848 for pkg in metadata. packages . iter ( ) . filter ( |p| * p. name == * name) {
839849 match & pkg. license {
840850 None => {
841- tidy_error ! (
842- bad,
851+ check. error ( format ! (
843852 "dependency exception `{}` in workspace `{workspace}` does not declare a license expression" ,
844853 pkg. id
845- ) ;
854+ ) ) ;
846855 }
847856 Some ( pkg_license) => {
848857 if pkg_license. as_str ( ) != * license {
849- println ! (
850- "dependency exception `{name}` license in workspace `{workspace}` has changed"
851- ) ;
852- println ! ( " previously `{license}` now `{pkg_license}`" ) ;
853- println ! ( " update EXCEPTIONS for the new license" ) ;
854- * bad = true ;
858+ check. error ( format ! ( r#"dependency exception `{name}` license in workspace `{workspace}` has changed
859+ previously `{license}` now `{pkg_license}`
860+ update EXCEPTIONS for the new license
861+ "# ) ) ;
855862 }
856863 }
857864 }
@@ -872,26 +879,23 @@ fn check_license_exceptions(
872879 let license = match & pkg. license {
873880 Some ( license) => license,
874881 None => {
875- tidy_error ! (
876- bad,
882+ check. error ( format ! (
877883 "dependency `{}` in workspace `{workspace}` does not define a license expression" ,
878884 pkg. id
879- ) ;
885+ ) ) ;
880886 continue ;
881887 }
882888 } ;
883889 if !LICENSES . contains ( & license. as_str ( ) ) {
884- tidy_error ! (
885- bad,
890+ check. error ( format ! (
886891 "invalid license `{}` for package `{}` in workspace `{workspace}`" ,
887- license,
888- pkg. id
889- ) ;
892+ license, pkg. id
893+ ) ) ;
890894 }
891895 }
892896}
893897
894- fn check_runtime_no_duplicate_dependencies ( metadata : & Metadata , bad : & mut bool ) {
898+ fn check_runtime_no_duplicate_dependencies ( metadata : & Metadata , check : & mut RunningCheck ) {
895899 let mut seen_pkgs = HashSet :: new ( ) ;
896900 for pkg in & metadata. packages {
897901 if pkg. source . is_none ( ) {
@@ -902,25 +906,23 @@ fn check_runtime_no_duplicate_dependencies(metadata: &Metadata, bad: &mut bool)
902906 // depends on two version of (one for the `wasm32-wasip1` target and
903907 // another for the `wasm32-wasip2` target).
904908 if pkg. name . to_string ( ) != "wasi" && !seen_pkgs. insert ( & * pkg. name ) {
905- tidy_error ! (
906- bad,
909+ check. error ( format ! (
907910 "duplicate package `{}` is not allowed for the standard library" ,
908911 pkg. name
909- ) ;
912+ ) ) ;
910913 }
911914 }
912915}
913916
914- fn check_runtime_no_proc_macros ( metadata : & Metadata , bad : & mut bool ) {
917+ fn check_runtime_no_proc_macros ( metadata : & Metadata , check : & mut RunningCheck ) {
915918 for pkg in & metadata. packages {
916919 if pkg. targets . iter ( ) . any ( |target| target. is_proc_macro ( ) ) {
917- tidy_error ! (
918- bad,
920+ check. error ( format ! (
919921 "proc macro `{}` is not allowed as standard library dependency.\n \
920922 Using proc macros in the standard library would break cross-compilation \
921923 as proc-macros don't get shipped for the host tuple.",
922924 pkg. name
923- ) ;
925+ ) ) ;
924926 }
925927 }
926928}
@@ -935,7 +937,7 @@ fn check_permitted_dependencies(
935937 permitted_dependencies : & [ & ' static str ] ,
936938 restricted_dependency_crates : & [ & ' static str ] ,
937939 permitted_location : ListLocation ,
938- bad : & mut bool ,
940+ check : & mut RunningCheck ,
939941) {
940942 let mut has_permitted_dep_error = false ;
941943 let mut deps = HashSet :: new ( ) ;
@@ -957,11 +959,10 @@ fn check_permitted_dependencies(
957959 }
958960 }
959961 if !deps. iter ( ) . any ( |dep_id| compare ( pkg_from_id ( metadata, dep_id) , permitted) ) {
960- tidy_error ! (
961- bad,
962+ check. error ( format ! (
962963 "could not find allowed package `{permitted}`\n \
963964 Remove from PERMITTED_DEPENDENCIES list if it is no longer used.",
964- ) ;
965+ ) ) ;
965966 has_permitted_dep_error = true ;
966967 }
967968 }
@@ -988,7 +989,7 @@ fn check_permitted_dependencies(
988989 false
989990 } ;
990991 if !is_eq {
991- tidy_error ! ( bad , "Dependency for {descr} not explicitly permitted: {}" , dep. id) ;
992+ check . error ( format ! ( "Dependency for {descr} not explicitly permitted: {}" , dep. id) ) ;
992993 has_permitted_dep_error = true ;
993994 }
994995 }
0 commit comments