@@ -48,39 +48,74 @@ const LICENSES: &[&str] = &[
48
48
49
49
type ExceptionList = & ' static [ ( & ' static str , & ' static str ) ] ;
50
50
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
+
51
75
/// 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.
61
76
// FIXME auto detect all cargo workspaces
62
- pub ( crate ) const WORKSPACES : & [ ( & str , ExceptionList , Option < ( & [ & str ] , & [ & str ] ) > , & [ & str ] ) ] = & [
77
+ pub ( crate ) const WORKSPACES : & [ WorkspaceInfo < ' static > ] = & [
63
78
// 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
+ ) ,
66
86
// Outside of the alphabetical section because rustfmt formats it using multiple lines.
67
- (
87
+ WorkspaceInfo :: new (
68
88
"compiler/rustc_codegen_cranelift" ,
69
89
EXCEPTIONS_CRANELIFT ,
70
90
Some ( ( & [ "rustc_codegen_cranelift" ] , PERMITTED_CRANELIFT_DEPENDENCIES ) ) ,
71
91
& [ ] ,
72
92
) ,
73
93
// 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
+ ) ,
84
119
// tidy-alphabetical-end
85
120
] ;
86
121
@@ -567,29 +602,29 @@ pub fn check(root: &Path, cargo: &Path, bless: bool, bad: &mut bool) {
567
602
568
603
check_proc_macro_dep_list ( root, cargo, bless, bad) ;
569
604
570
- for & ( workspace , exceptions, permitted_deps , submodules) in WORKSPACES {
605
+ for & WorkspaceInfo { path , exceptions, crates_and_deps , submodules } in WORKSPACES {
571
606
if has_missing_submodule ( root, submodules) {
572
607
continue ;
573
608
}
574
609
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" ) ;
577
612
continue ;
578
613
}
579
614
580
615
let mut cmd = cargo_metadata:: MetadataCommand :: new ( ) ;
581
616
cmd. cargo_path ( cargo)
582
- . manifest_path ( root. join ( workspace ) . join ( "Cargo.toml" ) )
617
+ . manifest_path ( root. join ( path ) . join ( "Cargo.toml" ) )
583
618
. features ( cargo_metadata:: CargoOpt :: AllFeatures )
584
619
. other_options ( vec ! [ "--locked" . to_owned( ) ] ) ;
585
620
let metadata = t ! ( cmd. exec( ) ) ;
586
621
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) ;
590
625
}
591
626
592
- if workspace == "library" {
627
+ if path == "library" {
593
628
check_runtime_license_exceptions ( & metadata, bad) ;
594
629
check_runtime_no_duplicate_dependencies ( & metadata, bad) ;
595
630
check_runtime_no_proc_macros ( & metadata, bad) ;
0 commit comments