@@ -9,6 +9,8 @@ use build_helper::ci::CiEnv;
9
9
use cargo_metadata:: semver:: Version ;
10
10
use cargo_metadata:: { Metadata , Package , PackageId } ;
11
11
12
+ use crate :: diagnostics:: { CheckId , DiagCtx , RunningCheck } ;
13
+
12
14
#[ path = "../../../bootstrap/src/utils/proc_macro_deps.rs" ]
13
15
mod proc_macro_deps;
14
16
@@ -661,18 +663,20 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[
661
663
///
662
664
/// `root` is path to the directory with the root `Cargo.toml` (for the workspace). `cargo` is path
663
665
/// 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
+
665
669
let mut checked_runtime_licenses = false ;
666
670
667
- check_proc_macro_dep_list ( root, cargo, bless, bad ) ;
671
+ check_proc_macro_dep_list ( root, cargo, bless, & mut check ) ;
668
672
669
673
for & WorkspaceInfo { path, exceptions, crates_and_deps, submodules } in WORKSPACES {
670
674
if has_missing_submodule ( root, submodules) {
671
675
continue ;
672
676
}
673
677
674
678
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" ) ) ;
676
680
continue ;
677
681
}
678
682
@@ -683,16 +687,23 @@ pub fn check(root: &Path, cargo: &Path, bless: bool, bad: &mut bool) {
683
687
. other_options ( vec ! [ "--locked" . to_owned( ) ] ) ;
684
688
let metadata = t ! ( cmd. exec( ) ) ;
685
689
686
- check_license_exceptions ( & metadata, path, exceptions, bad ) ;
690
+ check_license_exceptions ( & metadata, path, exceptions, & mut check ) ;
687
691
if let Some ( ( crates, permitted_deps, location) ) = crates_and_deps {
688
692
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
+ ) ;
690
701
}
691
702
692
703
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 ) ;
696
707
checked_runtime_licenses = true ;
697
708
}
698
709
}
@@ -703,7 +714,7 @@ pub fn check(root: &Path, cargo: &Path, bless: bool, bad: &mut bool) {
703
714
}
704
715
705
716
/// 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 ) {
707
718
let mut cmd = cargo_metadata:: MetadataCommand :: new ( ) ;
708
719
cmd. cargo_path ( cargo)
709
720
. manifest_path ( root. join ( "Cargo.toml" ) )
@@ -750,22 +761,22 @@ pub static CRATES: &[&str] = &[
750
761
)
751
762
. unwrap ( ) ;
752
763
} else {
753
- let old_bad = * bad ;
764
+ let mut error_found = false ;
754
765
755
766
for missing in proc_macro_deps. difference ( & expected) {
756
- tidy_error ! (
757
- bad ,
767
+ error_found = true ;
768
+ check . error ( format ! (
758
769
"proc-macro crate dependency `{missing}` is not registered in `src/bootstrap/src/utils/proc_macro_deps.rs`" ,
759
- ) ;
770
+ ) ) ;
760
771
}
761
772
for extra in expected. difference ( & proc_macro_deps) {
762
- tidy_error ! (
763
- bad ,
773
+ error_found = true ;
774
+ check . error ( format ! (
764
775
"`{extra}` is registered in `src/bootstrap/src/utils/proc_macro_deps.rs`, but is not a proc-macro crate dependency" ,
765
- ) ;
776
+ ) ) ;
766
777
}
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" ) ;
769
780
}
770
781
}
771
782
}
@@ -787,7 +798,7 @@ pub fn has_missing_submodule(root: &Path, submodules: &[&str]) -> bool {
787
798
///
788
799
/// Unlike for tools we don't allow exceptions to the `LICENSES` list for the runtime with the sole
789
800
/// 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 ) {
791
802
for pkg in & metadata. packages {
792
803
if pkg. source . is_none ( ) {
793
804
// No need to check local packages.
@@ -796,7 +807,8 @@ fn check_runtime_license_exceptions(metadata: &Metadata, bad: &mut bool) {
796
807
let license = match & pkg. license {
797
808
Some ( license) => license,
798
809
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) ) ;
800
812
continue ;
801
813
}
802
814
} ;
@@ -809,7 +821,7 @@ fn check_runtime_license_exceptions(metadata: &Metadata, bad: &mut bool) {
809
821
continue ;
810
822
}
811
823
812
- tidy_error ! ( bad , "invalid license `{}` in `{}`" , license, pkg. id) ;
824
+ check . error ( format ! ( "invalid license `{}` in `{}`" , license, pkg. id) ) ;
813
825
}
814
826
}
815
827
}
@@ -821,37 +833,32 @@ fn check_license_exceptions(
821
833
metadata : & Metadata ,
822
834
workspace : & str ,
823
835
exceptions : & [ ( & str , & str ) ] ,
824
- bad : & mut bool ,
836
+ check : & mut RunningCheck ,
825
837
) {
826
838
// Validate the EXCEPTIONS list hasn't changed.
827
839
for ( name, license) in exceptions {
828
840
// Check that the package actually exists.
829
841
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 \
833
844
Remove from EXCEPTIONS list if it is no longer used.",
834
- name
835
- ) ;
845
+ ) ) ;
836
846
}
837
847
// Check that the license hasn't changed.
838
848
for pkg in metadata. packages . iter ( ) . filter ( |p| * p. name == * name) {
839
849
match & pkg. license {
840
850
None => {
841
- tidy_error ! (
842
- bad,
851
+ check. error ( format ! (
843
852
"dependency exception `{}` in workspace `{workspace}` does not declare a license expression" ,
844
853
pkg. id
845
- ) ;
854
+ ) ) ;
846
855
}
847
856
Some ( pkg_license) => {
848
857
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
+ "# ) ) ;
855
862
}
856
863
}
857
864
}
@@ -872,26 +879,23 @@ fn check_license_exceptions(
872
879
let license = match & pkg. license {
873
880
Some ( license) => license,
874
881
None => {
875
- tidy_error ! (
876
- bad,
882
+ check. error ( format ! (
877
883
"dependency `{}` in workspace `{workspace}` does not define a license expression" ,
878
884
pkg. id
879
- ) ;
885
+ ) ) ;
880
886
continue ;
881
887
}
882
888
} ;
883
889
if !LICENSES . contains ( & license. as_str ( ) ) {
884
- tidy_error ! (
885
- bad,
890
+ check. error ( format ! (
886
891
"invalid license `{}` for package `{}` in workspace `{workspace}`" ,
887
- license,
888
- pkg. id
889
- ) ;
892
+ license, pkg. id
893
+ ) ) ;
890
894
}
891
895
}
892
896
}
893
897
894
- fn check_runtime_no_duplicate_dependencies ( metadata : & Metadata , bad : & mut bool ) {
898
+ fn check_runtime_no_duplicate_dependencies ( metadata : & Metadata , check : & mut RunningCheck ) {
895
899
let mut seen_pkgs = HashSet :: new ( ) ;
896
900
for pkg in & metadata. packages {
897
901
if pkg. source . is_none ( ) {
@@ -902,25 +906,23 @@ fn check_runtime_no_duplicate_dependencies(metadata: &Metadata, bad: &mut bool)
902
906
// depends on two version of (one for the `wasm32-wasip1` target and
903
907
// another for the `wasm32-wasip2` target).
904
908
if pkg. name . to_string ( ) != "wasi" && !seen_pkgs. insert ( & * pkg. name ) {
905
- tidy_error ! (
906
- bad,
909
+ check. error ( format ! (
907
910
"duplicate package `{}` is not allowed for the standard library" ,
908
911
pkg. name
909
- ) ;
912
+ ) ) ;
910
913
}
911
914
}
912
915
}
913
916
914
- fn check_runtime_no_proc_macros ( metadata : & Metadata , bad : & mut bool ) {
917
+ fn check_runtime_no_proc_macros ( metadata : & Metadata , check : & mut RunningCheck ) {
915
918
for pkg in & metadata. packages {
916
919
if pkg. targets . iter ( ) . any ( |target| target. is_proc_macro ( ) ) {
917
- tidy_error ! (
918
- bad,
920
+ check. error ( format ! (
919
921
"proc macro `{}` is not allowed as standard library dependency.\n \
920
922
Using proc macros in the standard library would break cross-compilation \
921
923
as proc-macros don't get shipped for the host tuple.",
922
924
pkg. name
923
- ) ;
925
+ ) ) ;
924
926
}
925
927
}
926
928
}
@@ -935,7 +937,7 @@ fn check_permitted_dependencies(
935
937
permitted_dependencies : & [ & ' static str ] ,
936
938
restricted_dependency_crates : & [ & ' static str ] ,
937
939
permitted_location : ListLocation ,
938
- bad : & mut bool ,
940
+ check : & mut RunningCheck ,
939
941
) {
940
942
let mut has_permitted_dep_error = false ;
941
943
let mut deps = HashSet :: new ( ) ;
@@ -957,11 +959,10 @@ fn check_permitted_dependencies(
957
959
}
958
960
}
959
961
if !deps. iter ( ) . any ( |dep_id| compare ( pkg_from_id ( metadata, dep_id) , permitted) ) {
960
- tidy_error ! (
961
- bad,
962
+ check. error ( format ! (
962
963
"could not find allowed package `{permitted}`\n \
963
964
Remove from PERMITTED_DEPENDENCIES list if it is no longer used.",
964
- ) ;
965
+ ) ) ;
965
966
has_permitted_dep_error = true ;
966
967
}
967
968
}
@@ -988,7 +989,7 @@ fn check_permitted_dependencies(
988
989
false
989
990
} ;
990
991
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) ) ;
992
993
has_permitted_dep_error = true ;
993
994
}
994
995
}
0 commit comments