@@ -48,39 +48,74 @@ const LICENSES: &[&str] = &[
4848
4949type ExceptionList = & ' static [ ( & ' static str , & ' static str ) ] ;
5050
51+ pub ( crate ) struct WorkspaceInfo < ' a > {
52+ /// Path to the directory containing the workspace root Cargo.toml file.
53+ pub ( crate ) path : & ' a str ,
54+ /// The list of license exceptions.
55+ pub ( crate ) exceptions : ExceptionList ,
56+ /// Optionally:
57+ /// * A list of crates for which dependencies need to be explicitly allowed.
58+ /// * The list of allowed dependencies.
59+ pub ( crate ) crates_and_deps : Option < ( & ' a [ & ' a str ] , & ' a [ & ' a str ] ) > ,
60+ /// Submodules required for the workspace
61+ pub ( crate ) submodules : & ' a [ & ' a str ] ,
62+ }
63+
64+ impl < ' a > WorkspaceInfo < ' a > {
65+ const fn new (
66+ path : & ' a str ,
67+ exceptions : ExceptionList ,
68+ crates_and_deps : Option < ( & ' a [ & str ] , & ' a [ & str ] ) > ,
69+ submodules : & ' a [ & str ] ,
70+ ) -> Self {
71+ Self { path, exceptions, crates_and_deps, submodules }
72+ }
73+ }
74+
5175/// The workspaces to check for licensing and optionally permitted dependencies.
52- ///
53- /// Each entry consists of a tuple with the following elements:
54- ///
55- /// * The path to the workspace root Cargo.toml file.
56- /// * The list of license exceptions.
57- /// * Optionally a tuple of:
58- /// * A list of crates for which dependencies need to be explicitly allowed.
59- /// * The list of allowed dependencies.
60- /// * Submodules required for the workspace.
6176// FIXME auto detect all cargo workspaces
62- pub ( crate ) const WORKSPACES : & [ ( & str , ExceptionList , Option < ( & [ & str ] , & [ & str ] ) > , & [ & str ] ) ] = & [
77+ pub ( crate ) const WORKSPACES : & [ WorkspaceInfo < ' static > ] = & [
6378 // The root workspace has to be first for check_rustfix to work.
64- ( "." , EXCEPTIONS , Some ( ( & [ "rustc-main" ] , PERMITTED_RUSTC_DEPENDENCIES ) ) , & [ ] ) ,
65- ( "library" , EXCEPTIONS_STDLIB , Some ( ( & [ "sysroot" ] , PERMITTED_STDLIB_DEPENDENCIES ) ) , & [ ] ) ,
79+ WorkspaceInfo :: new ( "." , EXCEPTIONS , Some ( ( & [ "rustc-main" ] , PERMITTED_RUSTC_DEPENDENCIES ) ) , & [ ] ) ,
80+ WorkspaceInfo :: new (
81+ "library" ,
82+ EXCEPTIONS_STDLIB ,
83+ Some ( ( & [ "sysroot" ] , PERMITTED_STDLIB_DEPENDENCIES ) ) ,
84+ & [ ] ,
85+ ) ,
6686 // Outside of the alphabetical section because rustfmt formats it using multiple lines.
67- (
87+ WorkspaceInfo :: new (
6888 "compiler/rustc_codegen_cranelift" ,
6989 EXCEPTIONS_CRANELIFT ,
7090 Some ( ( & [ "rustc_codegen_cranelift" ] , PERMITTED_CRANELIFT_DEPENDENCIES ) ) ,
7191 & [ ] ,
7292 ) ,
7393 // tidy-alphabetical-start
74- ( "compiler/rustc_codegen_gcc" , EXCEPTIONS_GCC , None , & [ ] ) ,
75- ( "src/bootstrap" , EXCEPTIONS_BOOTSTRAP , None , & [ ] ) ,
76- ( "src/tools/cargo" , EXCEPTIONS_CARGO , None , & [ "src/tools/cargo" ] ) ,
77- //("src/tools/miri/test-cargo-miri", &[], None), // FIXME uncomment once all deps are vendored
78- //("src/tools/miri/test_dependencies", &[], None), // FIXME uncomment once all deps are vendored
79- ( "src/tools/rust-analyzer" , EXCEPTIONS_RUST_ANALYZER , None , & [ ] ) ,
80- ( "src/tools/rustbook" , EXCEPTIONS_RUSTBOOK , None , & [ "src/doc/book" , "src/doc/reference" ] ) ,
81- ( "src/tools/rustc-perf" , EXCEPTIONS_RUSTC_PERF , None , & [ "src/tools/rustc-perf" ] ) ,
82- ( "src/tools/test-float-parse" , EXCEPTIONS , None , & [ ] ) ,
83- ( "tests/run-make-cargo/uefi-qemu/uefi_qemu_test" , EXCEPTIONS_UEFI_QEMU_TEST , None , & [ ] ) ,
94+ WorkspaceInfo :: new ( "compiler/rustc_codegen_gcc" , EXCEPTIONS_GCC , None , & [ ] ) ,
95+ WorkspaceInfo :: new ( "src/bootstrap" , EXCEPTIONS_BOOTSTRAP , None , & [ ] ) ,
96+ WorkspaceInfo :: new ( "src/tools/cargo" , EXCEPTIONS_CARGO , None , & [ "src/tools/cargo" ] ) ,
97+ //WorkspaceInfo::new("src/tools/miri/test-cargo-miri", &[], None), // FIXME uncomment once all deps are vendored
98+ //WorkspaceInfo::new("src/tools/miri/test_dependencies", &[], None), // FIXME uncomment once all deps are vendored
99+ WorkspaceInfo :: new ( "src/tools/rust-analyzer" , EXCEPTIONS_RUST_ANALYZER , None , & [ ] ) ,
100+ WorkspaceInfo :: new (
101+ "src/tools/rustbook" ,
102+ EXCEPTIONS_RUSTBOOK ,
103+ None ,
104+ & [ "src/doc/book" , "src/doc/reference" ] ,
105+ ) ,
106+ WorkspaceInfo :: new (
107+ "src/tools/rustc-perf" ,
108+ EXCEPTIONS_RUSTC_PERF ,
109+ None ,
110+ & [ "src/tools/rustc-perf" ] ,
111+ ) ,
112+ WorkspaceInfo :: new ( "src/tools/test-float-parse" , EXCEPTIONS , None , & [ ] ) ,
113+ WorkspaceInfo :: new (
114+ "tests/run-make-cargo/uefi-qemu/uefi_qemu_test" ,
115+ EXCEPTIONS_UEFI_QEMU_TEST ,
116+ None ,
117+ & [ ] ,
118+ ) ,
84119 // tidy-alphabetical-end
85120] ;
86121
@@ -567,29 +602,29 @@ pub fn check(root: &Path, cargo: &Path, bless: bool, bad: &mut bool) {
567602
568603 check_proc_macro_dep_list ( root, cargo, bless, bad) ;
569604
570- for & ( workspace , exceptions, permitted_deps , submodules) in WORKSPACES {
605+ for & WorkspaceInfo { path , exceptions, crates_and_deps , submodules } in WORKSPACES {
571606 if has_missing_submodule ( root, submodules) {
572607 continue ;
573608 }
574609
575- if !root. join ( workspace ) . join ( "Cargo.lock" ) . exists ( ) {
576- tidy_error ! ( bad, "the `{workspace }` workspace doesn't have a Cargo.lock" ) ;
610+ if !root. join ( path ) . join ( "Cargo.lock" ) . exists ( ) {
611+ tidy_error ! ( bad, "the `{path }` workspace doesn't have a Cargo.lock" ) ;
577612 continue ;
578613 }
579614
580615 let mut cmd = cargo_metadata:: MetadataCommand :: new ( ) ;
581616 cmd. cargo_path ( cargo)
582- . manifest_path ( root. join ( workspace ) . join ( "Cargo.toml" ) )
617+ . manifest_path ( root. join ( path ) . join ( "Cargo.toml" ) )
583618 . features ( cargo_metadata:: CargoOpt :: AllFeatures )
584619 . other_options ( vec ! [ "--locked" . to_owned( ) ] ) ;
585620 let metadata = t ! ( cmd. exec( ) ) ;
586621
587- check_license_exceptions ( & metadata, workspace , exceptions, bad) ;
588- if let Some ( ( crates, permitted_deps) ) = permitted_deps {
589- check_permitted_dependencies ( & metadata, workspace , permitted_deps, crates, bad) ;
622+ check_license_exceptions ( & metadata, path , exceptions, bad) ;
623+ if let Some ( ( crates, permitted_deps) ) = crates_and_deps {
624+ check_permitted_dependencies ( & metadata, path , permitted_deps, crates, bad) ;
590625 }
591626
592- if workspace == "library" {
627+ if path == "library" {
593628 check_runtime_license_exceptions ( & metadata, bad) ;
594629 check_runtime_no_duplicate_dependencies ( & metadata, bad) ;
595630 check_runtime_no_proc_macros ( & metadata, bad) ;
0 commit comments