@@ -48,40 +48,116 @@ const LICENSES: &[&str] = &[
4848
4949type ExceptionList = & ' static [ ( & ' static str , & ' static str ) ] ;
5050
51+ #[ derive( Clone , Copy ) ]
52+ pub ( crate ) struct WorkspaceInfo < ' a > {
53+ /// Path to the directory containing the workspace root Cargo.toml file.
54+ pub ( crate ) path : & ' a str ,
55+ /// The list of license exceptions.
56+ pub ( crate ) exceptions : ExceptionList ,
57+ /// Optionally:
58+ /// * A list of crates for which dependencies need to be explicitly allowed.
59+ /// * The list of allowed dependencies.
60+ /// * The source code location of the allowed dependencies list
61+ crates_and_deps : Option < ( & ' a [ & ' a str ] , & ' a [ & ' a str ] , ListLocation ) > ,
62+ /// Submodules required for the workspace
63+ pub ( crate ) submodules : & ' a [ & ' a str ] ,
64+ }
65+
5166/// 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.
6167// FIXME auto detect all cargo workspaces
62- pub ( crate ) const WORKSPACES : & [ ( & str , ExceptionList , Option < ( & [ & str ] , & [ & str ] ) > , & [ & str ] ) ] = & [
68+ pub ( crate ) const WORKSPACES : & [ WorkspaceInfo < ' static > ] = & [
6369 // 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 ) ) , & [ ] ) ,
66- // Outside of the alphabetical section because rustfmt formats it using multiple lines.
67- (
68- "compiler/rustc_codegen_cranelift" ,
69- EXCEPTIONS_CRANELIFT ,
70- Some ( ( & [ "rustc_codegen_cranelift" ] , PERMITTED_CRANELIFT_DEPENDENCIES ) ) ,
71- & [ ] ,
72- ) ,
73- // 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 , & [ ] ) ,
84- // tidy-alphabetical-end
70+ WorkspaceInfo {
71+ path : "." ,
72+ exceptions : EXCEPTIONS ,
73+ crates_and_deps : Some ( (
74+ & [ "rustc-main" ] ,
75+ PERMITTED_RUSTC_DEPENDENCIES ,
76+ PERMITTED_RUSTC_DEPS_LOCATION ,
77+ ) ) ,
78+ submodules : & [ ] ,
79+ } ,
80+ WorkspaceInfo {
81+ path : "library" ,
82+ exceptions : EXCEPTIONS_STDLIB ,
83+ crates_and_deps : Some ( (
84+ & [ "sysroot" ] ,
85+ PERMITTED_STDLIB_DEPENDENCIES ,
86+ PERMITTED_STDLIB_DEPS_LOCATION ,
87+ ) ) ,
88+ submodules : & [ ] ,
89+ } ,
90+ {
91+ WorkspaceInfo {
92+ path : "compiler/rustc_codegen_cranelift" ,
93+ exceptions : EXCEPTIONS_CRANELIFT ,
94+ crates_and_deps : Some ( (
95+ & [ "rustc_codegen_cranelift" ] ,
96+ PERMITTED_CRANELIFT_DEPENDENCIES ,
97+ PERMITTED_CRANELIFT_DEPS_LOCATION ,
98+ ) ) ,
99+ submodules : & [ ] ,
100+ }
101+ } ,
102+ WorkspaceInfo {
103+ path : "compiler/rustc_codegen_gcc" ,
104+ exceptions : EXCEPTIONS_GCC ,
105+ crates_and_deps : None ,
106+ submodules : & [ ] ,
107+ } ,
108+ WorkspaceInfo {
109+ path : "src/bootstrap" ,
110+ exceptions : EXCEPTIONS_BOOTSTRAP ,
111+ crates_and_deps : None ,
112+ submodules : & [ ] ,
113+ } ,
114+ WorkspaceInfo {
115+ path : "src/tools/cargo" ,
116+ exceptions : EXCEPTIONS_CARGO ,
117+ crates_and_deps : None ,
118+ submodules : & [ "src/tools/cargo" ] ,
119+ } ,
120+ // FIXME uncomment once all deps are vendored
121+ // WorkspaceInfo {
122+ // path: "src/tools/miri/test-cargo-miri",
123+ // crates_and_deps: None
124+ // submodules: &[],
125+ // },
126+ // WorkspaceInfo {
127+ // path: "src/tools/miri/test_dependencies",
128+ // crates_and_deps: None,
129+ // submodules: &[],
130+ // }
131+ WorkspaceInfo {
132+ path : "src/tools/rust-analyzer" ,
133+ exceptions : EXCEPTIONS_RUST_ANALYZER ,
134+ crates_and_deps : None ,
135+ submodules : & [ ] ,
136+ } ,
137+ WorkspaceInfo {
138+ path : "src/tools/rustbook" ,
139+ exceptions : EXCEPTIONS_RUSTBOOK ,
140+ crates_and_deps : None ,
141+ submodules : & [ "src/doc/book" , "src/doc/reference" ] ,
142+ } ,
143+ WorkspaceInfo {
144+ path : "src/tools/rustc-perf" ,
145+ exceptions : EXCEPTIONS_RUSTC_PERF ,
146+ crates_and_deps : None ,
147+ submodules : & [ "src/tools/rustc-perf" ] ,
148+ } ,
149+ WorkspaceInfo {
150+ path : "src/tools/test-float-parse" ,
151+ exceptions : EXCEPTIONS ,
152+ crates_and_deps : None ,
153+ submodules : & [ ] ,
154+ } ,
155+ WorkspaceInfo {
156+ path : "tests/run-make-cargo/uefi-qemu/uefi_qemu_test" ,
157+ exceptions : EXCEPTIONS_UEFI_QEMU_TEST ,
158+ crates_and_deps : None ,
159+ submodules : & [ ] ,
160+ } ,
85161] ;
86162
87163/// These are exceptions to Rust's permissive licensing policy, and
@@ -226,7 +302,20 @@ const EXCEPTIONS_UEFI_QEMU_TEST: ExceptionList = &[
226302 ( "r-efi" , "MIT OR Apache-2.0 OR LGPL-2.1-or-later" ) , // LGPL is not acceptable, but we use it under MIT OR Apache-2.0
227303] ;
228304
229- const PERMITTED_DEPS_LOCATION : & str = concat ! ( file!( ) , ":" , line!( ) ) ;
305+ #[ derive( Clone , Copy ) ]
306+ struct ListLocation {
307+ path : & ' static str ,
308+ line : u32 ,
309+ }
310+
311+ /// Creates a [`ListLocation`] for the current location (with an additional offset to the actual list start);
312+ macro_rules! location {
313+ ( + $offset: literal) => {
314+ ListLocation { path: file!( ) , line: line!( ) + $offset }
315+ } ;
316+ }
317+
318+ const PERMITTED_RUSTC_DEPS_LOCATION : ListLocation = location ! ( +6 ) ;
230319
231320/// Crates rustc is allowed to depend on. Avoid adding to the list if possible.
232321///
@@ -458,6 +547,8 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
458547 // tidy-alphabetical-end
459548] ;
460549
550+ const PERMITTED_STDLIB_DEPS_LOCATION : ListLocation = location ! ( +2 ) ;
551+
461552const PERMITTED_STDLIB_DEPENDENCIES : & [ & str ] = & [
462553 // tidy-alphabetical-start
463554 "addr2line" ,
@@ -499,6 +590,8 @@ const PERMITTED_STDLIB_DEPENDENCIES: &[&str] = &[
499590 // tidy-alphabetical-end
500591] ;
501592
593+ const PERMITTED_CRANELIFT_DEPS_LOCATION : ListLocation = location ! ( +2 ) ;
594+
502595const PERMITTED_CRANELIFT_DEPENDENCIES : & [ & str ] = & [
503596 // tidy-alphabetical-start
504597 "allocator-api2" ,
@@ -573,29 +666,30 @@ pub fn check(root: &Path, cargo: &Path, bless: bool, bad: &mut bool) {
573666
574667 check_proc_macro_dep_list ( root, cargo, bless, bad) ;
575668
576- for & ( workspace , exceptions, permitted_deps , submodules) in WORKSPACES {
669+ for & WorkspaceInfo { path , exceptions, crates_and_deps , submodules } in WORKSPACES {
577670 if has_missing_submodule ( root, submodules) {
578671 continue ;
579672 }
580673
581- if !root. join ( workspace ) . join ( "Cargo.lock" ) . exists ( ) {
582- tidy_error ! ( bad, "the `{workspace }` workspace doesn't have a Cargo.lock" ) ;
674+ if !root. join ( path ) . join ( "Cargo.lock" ) . exists ( ) {
675+ tidy_error ! ( bad, "the `{path }` workspace doesn't have a Cargo.lock" ) ;
583676 continue ;
584677 }
585678
586679 let mut cmd = cargo_metadata:: MetadataCommand :: new ( ) ;
587680 cmd. cargo_path ( cargo)
588- . manifest_path ( root. join ( workspace ) . join ( "Cargo.toml" ) )
681+ . manifest_path ( root. join ( path ) . join ( "Cargo.toml" ) )
589682 . features ( cargo_metadata:: CargoOpt :: AllFeatures )
590683 . other_options ( vec ! [ "--locked" . to_owned( ) ] ) ;
591684 let metadata = t ! ( cmd. exec( ) ) ;
592685
593- check_license_exceptions ( & metadata, workspace, exceptions, bad) ;
594- if let Some ( ( crates, permitted_deps) ) = permitted_deps {
595- check_permitted_dependencies ( & metadata, workspace, permitted_deps, crates, bad) ;
686+ check_license_exceptions ( & metadata, path, exceptions, bad) ;
687+ if let Some ( ( crates, permitted_deps, location) ) = crates_and_deps {
688+ let descr = crates. get ( 0 ) . unwrap_or ( & path) ;
689+ check_permitted_dependencies ( & metadata, descr, permitted_deps, crates, location, bad) ;
596690 }
597691
598- if workspace == "library" {
692+ if path == "library" {
599693 check_runtime_license_exceptions ( & metadata, bad) ;
600694 check_runtime_no_duplicate_dependencies ( & metadata, bad) ;
601695 check_runtime_no_proc_macros ( & metadata, bad) ;
@@ -840,6 +934,7 @@ fn check_permitted_dependencies(
840934 descr : & str ,
841935 permitted_dependencies : & [ & ' static str ] ,
842936 restricted_dependency_crates : & [ & ' static str ] ,
937+ permitted_location : ListLocation ,
843938 bad : & mut bool ,
844939) {
845940 let mut has_permitted_dep_error = false ;
@@ -900,7 +995,7 @@ fn check_permitted_dependencies(
900995 }
901996
902997 if has_permitted_dep_error {
903- eprintln ! ( "Go to `{PERMITTED_DEPS_LOCATION} ` for the list." ) ;
998+ eprintln ! ( "Go to `{}:{} ` for the list." , permitted_location . path , permitted_location . line ) ;
904999 }
9051000}
9061001
0 commit comments